UserController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace addons\Happiness\client\controllers;
  3. use addons\Store\common\models\StoreOrderDetail;
  4. use addons\Store\common\models\StoreUser;
  5. use addons\Happiness\common\models\HappinessOrder;
  6. use addons\Happiness\common\models\HappinessStoreUser;
  7. use common\enums\StatusEnum;
  8. use common\models\common\MallSetting;
  9. use common\models\order\OrderDetail;
  10. use common\models\user\User;
  11. use common\models\user\UserLevel;
  12. class UserController extends BaseController
  13. {
  14. /**
  15. * 门店会员
  16. * @Author bing
  17. * @DateTime 2022-04-26 18:07:46
  18. * @return void
  19. * @copyright: Copyright (c) 2022 广东七件事集团
  20. */
  21. public function actionIndex()
  22. {
  23. if (\Yii::$app->request->isAjax) {
  24. $where = [
  25. ['mall_id' => $this->mall_id],
  26. ['store_id' => $this->store_id],
  27. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  28. ];
  29. $get = \Yii::$app->request->get();
  30. $user_where = [];
  31. if (!empty($get['nickname_or_mobile'])) {
  32. $user_where[] = [
  33. 'OR',
  34. ['like', 'mobile', $get['nickname_or_mobile'] . '%', false],
  35. ['like', 'nickname', $get['nickname_or_mobile'] . '%', false]
  36. ];
  37. }
  38. if (!empty($get['level'])) {
  39. $user_where[] = ['level'=>$get['level']];
  40. }
  41. if (!empty($get['user_id'])) {
  42. $user_where[] = ['id'=>$get['user_id']];
  43. }
  44. if(!empty($user_where)){
  45. $user_list = User::lists(['where' =>$user_where, 'select' => 'id']);
  46. $user_id_arr = array_column($user_list, 'id');
  47. $where[] = ['user_id' => $user_id_arr];
  48. }
  49. $params = [
  50. 'where' => $where,
  51. 'with' => ['user'],
  52. 'order' => 'id desc'
  53. ];
  54. $list = HappinessStoreUser::listPage($params);
  55. if ($list === false) return $this->error(HappinessStoreUser::getStaticError());
  56. $levels = UserLevel::getListIndexByLevelColumn($this->mall_id);
  57. $user_level_arr = UserLevel::lists(['where'=>[['mall_id'=>$this->mall_id],['status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]],'select'=>'level,name','index'=>'level']);
  58. if (!empty($list['list'])) {
  59. foreach ($list['list'] as &$item) {
  60. $item['level_name'] = empty($user_level_arr[$item['user']['level']]) ? MallSetting::getDefaultLevelName($this->mall_id) : $user_level_arr[$item['user']['level']]['name'];// 会员等级名称
  61. }
  62. }
  63. $list['levels'] = $levels;
  64. return $this->success('ok', $list);
  65. }
  66. return $this->render($this->action->id);
  67. }
  68. public function actionDetail(){
  69. if (\Yii::$app->request->isAjax) {
  70. $get =\Yii::$app->request->get();
  71. $where = [
  72. ['mall_id' => $this->mall_id],
  73. ['user_id' => $get['id']],
  74. ['store_id' => $this->store_id],
  75. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  76. ];
  77. $detail = HappinessStoreUser::getOne($where,true,['user']);
  78. $detail['ke_dan_jia'] = 0;
  79. if(!empty($detail['pay_nums'])){
  80. $detail['ke_dan_jia'] = bcdiv($detail['pay_money'],$detail['pay_nums'],2);
  81. }
  82. //获取主订单数据
  83. $order = HappinessOrder::lists([
  84. 'where' => [
  85. ['mall_id' => $this->mall_id],
  86. ['user_id' => $get['id']],
  87. ['store_id' => $this->store_id],
  88. ]
  89. ]);
  90. $order_ids = array_column($order, 'order_id');
  91. $order_detail_list = ['list' => []];
  92. if (!empty($order_ids)) {
  93. $where = [
  94. ['mall_id' => $this->mall_id],
  95. ['user_id' => $get['id']],
  96. ['order_id' => $order_ids],
  97. ['!=','order_status',0],
  98. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  99. ];
  100. $order_detail_list = OrderDetail::listPage(['where'=>$where,'select'=>'sum(num) num,sum(goods_price) as goods_price,goods_id,goods_name','group'=>'goods_id']);
  101. }
  102. return $this->success('ok', ['detail'=>$detail,'order_detail_list'=>$order_detail_list]);
  103. }
  104. return $this->render($this->action->id);
  105. }
  106. }