CommissionListController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\admin\controller\finance;
  3. use app\admin\service\goods\GoodsSkuService;
  4. use app\admin\service\member\MemberService;
  5. use app\controller\Curd;
  6. use app\model\Member;
  7. use app\model\MemberAccountList;
  8. use app\model\Order;
  9. use app\model\OrderSheet;
  10. use support\Request;
  11. use support\Response;
  12. class CommissionListController extends Curd
  13. {
  14. public function __construct()
  15. {
  16. $this->model = new MemberAccountList();
  17. }
  18. public function select(Request $request): Response
  19. {
  20. [$where, $format, $limit, $field, $order] = $this->selectInput($request);
  21. $order = $request->get('order', 'desc');
  22. $field = $field ?? 'member_account_list_addtimes';
  23. $query = $this->doSelect($where, $field, $order);
  24. return $this->doFormat($query, $format, $limit);
  25. }
  26. protected function doSelect(array $where, string $field = null, string $order = 'desc')
  27. {
  28. $model = $this->model->with([
  29. 'member' => function ($query) {
  30. $query->select('member_id', 'member_mobile', 'member_is_owner', 'member_is_vip', 'member_is_partner', 'member_is_referrer');
  31. },
  32. 'memberInfo' => function ($query) {
  33. $query->select('join_info_member_id', 'member_info_nickname', 'member_info_headimg');
  34. },
  35. 'memberCert' => function ($query) {
  36. $query->select('join_cert_member_id', 'member_cert_name');
  37. }
  38. ]);
  39. foreach ($where as $column => $value) {
  40. if (is_array($value)) {
  41. if ($value[0] === 'like' || $value[0] === 'not like') {
  42. $model = $model->where($column, $value[0], "%$value[1]%");
  43. } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
  44. $model = $model->where($column, $value[0], $value[1]);
  45. } elseif ($value[0] == 'in' && !empty($value[1])) {
  46. $valArr = $value[1];
  47. if (is_string($value[1])) {
  48. $valArr = explode(",", trim($value[1]));
  49. }
  50. $model = $model->whereIn($column, $valArr);
  51. } elseif ($value[0] == 'not in' && !empty($value[1])) {
  52. $valArr = $value[1];
  53. if (is_string($value[1])) {
  54. $valArr = explode(",", trim($value[1]));
  55. }
  56. $model = $model->whereNotIn($column, $valArr);
  57. } elseif ($value[0] == 'null') {
  58. $model = $model->whereNull($column);
  59. } elseif ($value[0] == 'not null') {
  60. $model = $model->whereNotNull($column);
  61. } elseif ($value[0] !== '' || $value[1] !== '') {
  62. $model = $model->whereBetween($column, $value);
  63. }
  64. } else {
  65. $model = $model->where($column, $value);
  66. }
  67. }
  68. if ($field) {
  69. $model = $model->orderBy($field, $order);
  70. }
  71. return $model;
  72. }
  73. public function afterQuery($items)
  74. {
  75. foreach ($items as &$item) {
  76. $item['member_mobile'] = isset($item['member']) ? $item['member']['member_mobile'] : '';
  77. $item['member_info_nickname'] = isset($item['memberInfo']) && !empty($item['memberInfo']['member_info_nickname']) ? $item['memberInfo']['member_info_nickname'] : '';
  78. $item['member_cert_name'] = isset($item['memberCert']) && !empty($item['memberCert']['member_cert_name']) ? $item['memberCert']['member_cert_name'] : '';
  79. $item['member_name'] = MemberService::getMemberName($item['member_mobile'], $item['member_cert_name'], $item['member_info_nickname']);
  80. $item['member_info_headimg'] = isset($item['memberInfo']) && !empty($item['memberInfo']['member_info_headimg']) ? $item['memberInfo']['member_info_headimg'] : "";
  81. $item['member_is_owner'] = isset($item['member']) ? $item['member']['member_is_owner'] : '';
  82. $item['member_is_vip'] = isset($item['member']) ? $item['member']['member_is_vip'] : '';
  83. $item['member_is_partner'] = isset($item['member']) ? $item['member']['member_is_partner'] : '';
  84. $item['member_is_referrer'] = isset($item['member']) ? $item['member']['member_is_referrer'] : '';
  85. unset($item['member'], $item['memberInfo'], $item['memberCert']);
  86. }
  87. return $items;
  88. }
  89. /**
  90. * @Desc 记录详情
  91. * @Author Gorden
  92. * @Date 2024/9/28 17:15
  93. *
  94. * @param Request $request
  95. * @return Response
  96. */
  97. public function info(Request $request): Response
  98. {
  99. $id = $request->get('member_account_list_id');
  100. if (!$id) {
  101. return json_fail("参数异常");
  102. }
  103. $info = MemberAccountList::where('member_account_list_id', $id)->first();
  104. $infoMember = Member::with([
  105. 'role' => function ($query) {
  106. $query->select('member_role_id', 'member_role_name');
  107. }
  108. ])->where('member_id', $info->join_member_account_list_member_id)
  109. ->first();
  110. $info->member_role_name = !empty($infoMember->role) ? $infoMember->role->member_role_name : '';
  111. if (!empty($info->member_account_list_json)) {
  112. $accountListJson = json_decode($info->member_account_list_json, true);
  113. // 下单人
  114. if (isset($accountListJson['master_member_id'])) {
  115. $member = Member::with([
  116. 'info' => function ($query) {
  117. $query->select('join_info_member_id', 'member_info_nickname');
  118. },
  119. 'cert' => function ($query) {
  120. $query->select('join_cert_member_id', 'member_cert_name');
  121. },
  122. 'role' => function ($query) {
  123. $query->select('member_role_id', 'member_role_name');
  124. }
  125. ])->where('member_id', $accountListJson['master_member_id'])
  126. ->first();
  127. $info->master_nickname = isset($member->info) && !empty($member->info->member_info_nickname) ? $member->info->member_info_nickname : MemberService::getMemberNickname($member->member_mobile ?? '');
  128. $info->master_certname = isset($member->cert) && !empty($member->cert->member_cert_name) ? $member->cert->member_cert_name : '';
  129. $info->master_mobile = isset($member) && !empty($member->member_mobile) ? $member->member_mobile : '';
  130. $info->master_member_name = MemberService::getMemberName($info->master_mobile, $info->master_certname, $info->master_nickname);
  131. $info->master_role_name = !empty($member->role) ? $member->role->member_role_name : '';
  132. $info->join_member_role_id = $member->join_member_role_id ?? '';
  133. $info->member_is_owner = $member->member_is_owner ?? '';
  134. $info->member_is_vip = $member->member_is_vip ?? '';
  135. $info->member_is_partner = $member->member_is_partner ?? '';
  136. $info->member_is_referrer = $member->member_is_referrer ?? '';
  137. }
  138. // 订单
  139. if (isset($accountListJson['order_id'])) {
  140. $info->order = Order::where('order_id', $accountListJson['order_id'])
  141. ->select('order_id','order_groupby','order_amount_total','order_amount_pay','order_addtimes')
  142. ->first();
  143. $sheets = OrderSheet::with([
  144. 'goods'=>function($query){
  145. $query->select('goods_id','goods_name','goods_sales_price','goods_cover');
  146. },
  147. 'sku' => function($query){
  148. $query->select('goods_sku_id','goods_sku_specs_json');
  149. }
  150. ])->where('join_sheet_order_id',$accountListJson['order_id'])
  151. ->select('join_sheet_order_id','join_sheet_goods_id','join_sheet_goods_sku_id','order_sheet_num','order_sheet_price','order_sheet_amount','order_sheet_addtimes')
  152. ->get()
  153. ->toArray();
  154. foreach ($sheets as &$sheet){
  155. if (!empty($sheet['goods']) && !empty($sheet['goods']['goods_cover'])){
  156. $sheet['goods']['goods_cover'] = getenv('STORAGE_DOMAIN').$sheet['goods']['goods_cover'];
  157. }
  158. if (!empty($sheet['sku'])){
  159. $sheet['sku']['sku_title'] = GoodsSkuService::getSkuTitle($sheet['sku']['goods_sku_specs_json']);
  160. }
  161. }
  162. $info->sheet = $sheets;
  163. }
  164. }
  165. return json_success('success', $info);
  166. }
  167. }