UserController.php 3.8 KB

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