PointsController.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\controller\client;
  3. use app\controller\Curd;
  4. use app\model\ClientFavorite;
  5. use app\model\ClientPoints;
  6. use support\Request;
  7. use support\Response;
  8. class PointsController extends Curd
  9. {
  10. public function __construct()
  11. {
  12. $this->model = new ClientPoints();
  13. }
  14. public function select(Request $request): Response
  15. {
  16. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  17. $order = $request->get('order', 'desc');
  18. $field = $field ?? 'client_points_addtimes';
  19. if (!empty($request->get('member_mobile'))) {
  20. $where['member.member_mobile'] = ['like', $request->get('member_mobile')];
  21. }
  22. if (!empty($request->get('order_id'))) {
  23. $where['order.order_id'] = ['like', $request->get('order_id')];
  24. }
  25. $query = $this->doSelect($where, $field, $order);
  26. return $this->doFormat($query, $format, $limit);
  27. }
  28. protected function doSelect(array $where, string $field = null, string $order = 'desc')
  29. {
  30. $model = $this->model->leftJoin('member', 'member.member_id', '=', 'client_points.join_client_points_member_id')
  31. ->leftJoin('member_info', 'member_info.join_info_member_id', '=', 'client_points.join_client_points_member_id')
  32. ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'client_points.join_client_points_member_id')
  33. ->leftJoin('order', 'order.order_id', '=', 'client_points.join_client_points_order_id')
  34. ->select('member.member_id', 'member.member_mobile','member_info.member_info_nickname','member_cert.member_cert_name', 'order.order_id', 'order.order_name', 'client_points.*');
  35. foreach ($where as $column => $value) {
  36. if (is_array($value)) {
  37. if ($value[0] === 'like' || $value[0] === 'not like') {
  38. $model = $model->where($column, $value[0], "%$value[1]%");
  39. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  40. $model = $model->where($column, $value[0], $value[1]);
  41. } elseif ($value[0] == 'in' && !empty($value[1])) {
  42. $valArr = $value[1];
  43. if (is_string($value[1])) {
  44. $valArr = explode(",", trim($value[1]));
  45. }
  46. $model = $model->whereIn($column, $valArr);
  47. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  48. $valArr = $value[1];
  49. if (is_string($value[1])) {
  50. $valArr = explode(",", trim($value[1]));
  51. }
  52. $model = $model->whereNotIn($column, $valArr);
  53. } elseif ($value[0] == 'null') {
  54. $model = $model->whereNull($column);
  55. } elseif ($value[0] == 'not null') {
  56. $model = $model->whereNotNull($column);
  57. } elseif ($value[0] !== '' || $value[1] !== '') {
  58. $model = $model->whereBetween($column, $value);
  59. }
  60. } else {
  61. $model = $model->where($column, $value);
  62. }
  63. }
  64. if ($field) {
  65. $model = $model->orderBy($field, $order);
  66. }
  67. return $model;
  68. }
  69. /**
  70. * @Desc 积分详情
  71. * @Author Gorden
  72. * @Date 2024/9/19 18:16
  73. *
  74. * @param Request $request
  75. * @return Response
  76. */
  77. public function info(Request $request): Response
  78. {
  79. $pointsId = $request->get('points_id');
  80. if (!$pointsId){
  81. return json_fail('参数异常');
  82. }
  83. }
  84. }