PointsController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\admin\controller\client;
  3. use app\admin\service\member\MemberService;
  4. use app\controller\Curd;
  5. use app\model\ClientFavorite;
  6. use app\model\ClientPoints;
  7. use app\model\MemberRole;
  8. use support\Request;
  9. use support\Response;
  10. class PointsController extends Curd
  11. {
  12. public function __construct()
  13. {
  14. $this->model = new ClientPoints();
  15. }
  16. public function select(Request $request): Response
  17. {
  18. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  19. $order = $request->get('order', 'desc');
  20. $field = $field ?? 'client_points_addtimes';
  21. if (!empty($request->get('member_mobile'))) {
  22. $where['member.member_mobile'] = ['like', $request->get('member_mobile')];
  23. }
  24. if (!empty($request->get('order_id'))) {
  25. $where['order.order_id'] = ['like', $request->get('order_id')];
  26. }
  27. $query = $this->doSelect($where, $field, $order);
  28. return $this->doFormat($query, $format, $limit);
  29. }
  30. protected function doSelect(array $where, string $field = null, string $order = 'desc')
  31. {
  32. $model = $this->model->leftJoin('member', 'member.member_id', '=', 'client_points.join_client_points_member_id')
  33. ->leftJoin('member_info', 'member_info.join_info_member_id', '=', 'client_points.join_client_points_member_id')
  34. ->leftJoin('member_cert', 'member_cert.join_cert_member_id', '=', 'client_points.join_client_points_member_id')
  35. ->leftJoin('order', 'order.order_id', '=', 'client_points.join_client_points_order_id')
  36. ->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.*');
  37. foreach ($where as $column => $value) {
  38. if (is_array($value)) {
  39. if ($value[0] === 'like' || $value[0] === 'not like') {
  40. $model = $model->where($column, $value[0], "%$value[1]%");
  41. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  42. $model = $model->where($column, $value[0], $value[1]);
  43. } elseif ($value[0] == 'in' && !empty($value[1])) {
  44. $valArr = $value[1];
  45. if (is_string($value[1])) {
  46. $valArr = explode(",", trim($value[1]));
  47. }
  48. $model = $model->whereIn($column, $valArr);
  49. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  50. $valArr = $value[1];
  51. if (is_string($value[1])) {
  52. $valArr = explode(",", trim($value[1]));
  53. }
  54. $model = $model->whereNotIn($column, $valArr);
  55. } elseif ($value[0] == 'null') {
  56. $model = $model->whereNull($column);
  57. } elseif ($value[0] == 'not null') {
  58. $model = $model->whereNotNull($column);
  59. } elseif ($value[0] !== '' || $value[1] !== '') {
  60. $model = $model->whereBetween($column, $value);
  61. }
  62. } else {
  63. $model = $model->where($column, $value);
  64. }
  65. }
  66. if ($field) {
  67. $model = $model->orderBy($field, $order);
  68. }
  69. return $model;
  70. }
  71. /**
  72. * @Desc 积分详情
  73. * @Author Gorden
  74. * @Date 2024/9/19 18:16
  75. *
  76. * @param Request $request
  77. * @return Response
  78. */
  79. public function info(Request $request): Response
  80. {
  81. $pointsId = $request->get('points_id');
  82. if (!$pointsId) {
  83. return json_fail('参数异常');
  84. }
  85. $points = ClientPoints::with([
  86. 'orders',
  87. 'goods',
  88. 'member' => function ($query) {
  89. $query->select('member_id','join_member_role_id', 'member_mobile', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer');
  90. },
  91. 'memberInfo' => function ($query) {
  92. $query->select('join_info_member_id', 'member_info_nickname','member_info_headimg');
  93. },
  94. 'memberCert' => function ($query) {
  95. $query->select('join_cert_member_id', 'member_cert_name');
  96. },
  97. ])->where('client_points_id', $pointsId)
  98. ->first();
  99. $mobile = !empty($points->member) && !empty($points->member->member_mobile) ? $points->member->member_mobile : '';
  100. $nickname = !empty($points->memberInfo) && !empty($points->memberInfo->member_info_nickname) ? $points->memberInfo->member_info_nickname : '';
  101. $certname = !empty($points->memberCert) && !empty($points->memberCert->member_cert_name) ? $points->memberCert->member_cert_name : '';
  102. $points->member_name = MemberService::getMemberName($mobile, $certname, $nickname);
  103. $points->member_info_headimg = MemberService::getAvatarUrl(!empty($points->memberInfo) ? $points->memberInfo->member_info_headimg : '');
  104. $points->role_name = !empty($points->member) && !empty($points->member_name->join_member_role_id) ? MemberRole::where('member_role_id',$points->member_name->join_member_role_id)->value('member_role_name') : '';
  105. return json_success("success", $points);
  106. }
  107. }