| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace addons\Mch\client\controllers;
- use addons\Mch\common\models\MchUser;
- use common\enums\StatusEnum;
- use common\models\common\MallSetting;
- use common\models\order\OrderDetail;
- use common\models\user\User;
- use common\models\user\UserLevel;
- class UserController extends BaseController
- {
- /**
- * 门店会员
- * @Author bing
- * @DateTime 2022-04-26 18:07:46
- * @return void
- * @copyright: Copyright (c) 2022 广东七件事集团
- */
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- $where = [
- ['mall_id' => $this->mall_id],
- ['mch_id' => $this->mch_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- $get = \Yii::$app->request->get();
- $user_where = [];
- if (!empty($get['nickname_or_mobile'])) {
- $user_where[] = [
- 'OR',
- ['like', 'mobile', $get['nickname_or_mobile'] . '%', false],
- ['like', 'nickname', $get['nickname_or_mobile'] . '%', false]
- ];
- }
- if (!empty($get['level'])) {
- $user_where[] = ['level'=>$get['level']];
- }
- if (!empty($get['user_id'])) {
- $user_where[] = ['id'=>$get['user_id']];
- }
- if(!empty($user_where)){
- $user_list = User::lists(['where' =>$user_where, 'select' => 'id']);
- $user_id_arr = array_column($user_list, 'id');
- $where[] = ['user_id' => $user_id_arr];
- }
- $params = [
- 'where' => $where,
- 'with' => ['user'],
- 'order' => 'id desc'
- ];
- $list = MchUser::listPage($params);
- if ($list === false) return $this->error(MchUser::getStaticError());
- $levels = UserLevel::getListIndexByLevelColumn($this->mall_id);
- $user_level_arr = UserLevel::lists(['where'=>[['mall_id'=>$this->mall_id],['status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]],'select'=>'level,name','index'=>'level']);
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$item) {
- $item['level_name'] = empty($user_level_arr[$item['user']['level']]) ? MallSetting::getDefaultLevelName($this->mall_id) : $user_level_arr[$item['user']['level']]['name'];// 会员等级名称
- }
- }
- $list['levels'] = $levels;
- return $this->success('ok', $list);
- }
- return $this->render($this->action->id);
- }
- public function actionDetail(){
- if (\Yii::$app->request->isAjax) {
- $get =\Yii::$app->request->get();
- $where = [
- ['mall_id' => $this->mall_id],
- ['user_id' => $get['id']],
- ['mch_id' => $this->mch_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- $detail = MchUser::getOne($where,true,['user']);
- $detail['ke_dan_jia'] = 0;
- if(!empty($detail['pay_nums'])){
- $detail['ke_dan_jia'] = bcdiv($detail['pay_money'],$detail['pay_nums'],2);
- }
- $where = [
- ['mall_id' => $this->mall_id],
- ['user_id' => $get['id']],
- ['mch_id' => $this->mch_id],
- ['!=','order_status',0],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ];
- $order_detail_list = OrderDetail::listPage(['where'=>$where,'select'=>'sum(num) num,sum(goods_price) as goods_price,goods_id,goods_name','group'=>'goods_id']);
- return $this->success('ok', ['detail'=>$detail,'order_detail_list'=>$order_detail_list]);
- }
- return $this->render($this->action->id);
- }
- }
|