request->isAjax && Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where = [['=', 'mall_id', $this->mall_id], ['<>', 'status' , StatusEnum::DELETE]]; if (isset($get['keyword']) && !empty($get['keyword'])) { $where[] = ['or', ['=', 'user_id', $get['keyword']], ['=', 'mobile', $get['keyword']], ['like', 'nickname', $get['keyword']]]; } $params = [ 'limit' => 10, 'where' => $where, 'select' => ['id', 'user_id', 'nickname', 'mobile', 'avatar_url','share_num', 'position_id', 'like_num', 'browse_num'], 'order' => 'created_at desc', 'with' => ['user', 'cardUser'] ]; $list = BusinessCard::listPage($params); $Platform_config = PlatformSetting::getConfByGroup( 'system', true); $list['web_url'] = $Platform_config['h5_url']['value']; $list['mall_sign'] = $this->mall['mall_sign']; if (!empty($list['list'])) { foreach ($list['list'] as &$item) { $item['qrcode'] = ''; $item['h5_url'] = "{$list['web_url']}/plugins2/BusinessCard/index?sign={$list['mall_sign']}&card_id={$item['id']}"; } } $list['sum'] = Yii::$app->db->createCommand(BusinessCard::find() ->where(['mall_id' => $this->mall_id]) ->andWhere(['status' => StatusEnum::ENABLED]) ->select(["COALESCE(SUM(share_num), 0) as share", "COALESCE(SUM(browse_num), 0) as view", "COALESCE(SUM(like_num), 0) as like"]) ->createCommand()->getRawSql())->queryAll()[0] ?? [0, 0, 0]; $list['roles'] = CardEnums::getRoleTypeMap(); return $this->success('操作成功', $list); } return $this->render('index'); } /** * 客户管理 * * @author hpei * @param string keyword * @return array|mixed */ public function actionCardCustomer() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $where = [['=', 'mall_id', $this->mall_id], ['<>','status', StatusEnum::DELETE]]; $get = Yii::$app->request->get(); if (isset($get['keyword']) && !empty($get['keyword'])) { $userWhere = [ ['=', 'mall_id', $this->mall_id], ['<>','status', StatusEnum::DELETE], ['=', 'mobile', $get['keyword']], ['or', ['=', 'id', $get['keyword']], ['=', 'mobile', $get['keyword']], ['like', 'nickname', $get['keyword']]] ]; } if (isset($get['nickname']) && !empty($get['nickname'])) { $userWhere = [ ['=', 'mall_id', $this->mall_id], ['<>','status', StatusEnum::DELETE], ['like', 'nickname', $get['nickname']] ]; } if (isset($userWhere)) { $user_select = 'id,mobile,nickname,avatar_url'; $userParams = ['where' => $userWhere, 'select' => $user_select]; $userList = User::lists($userParams); if (!empty($userList)) $where[] = ['in', 'user_id', array_column($userList, 'id')]; } $with = ['parent' => function($query){ $query->select('id,mobile,nickname,avatar_url'); },'user' => function($query){ $query->select('id,mobile,nickname,avatar_url'); } ]; $params = ['limit' => 10, 'where' => $where, 'select' => ['user_id', 'parent_id', 'tags'], 'with' =>$with,'order' => 'id desc']; $list = BusinessCardUser::listPage($params); return $this->success('操作成功', $list); } return $this->render('card-customer'); } /** * 查找会员 * @Author: lun * @DateTime: 2023/3/10 0010 9:26 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|string|void */ public function actionSelectUser() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['mobile' => $get['keyword']]; $where[] = ['status' => StatusEnum::ENABLED]; $user_select = 'id,mobile,nickname,avatar_url'; $userParams = ['where' => $where, 'select' => $user_select]; $list = User::listPage($userParams); return $this->success('操作成功', $list); } } /** * 线索列表 * * @author hpei * @param int customer_type * @param string keyword * @return array|mixed */ public function actionClueList() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $get = Yii::$app->request->get(); $where = [['=', 'mall_id', $this->mall_id], ['=', 'is_clue', 1], ['<>','status', StatusEnum::DELETE]]; if (isset($get['keyword']) && !empty($get['keyword'])) { $userWhere = [ ['=', 'mall_id', $this->mall_id], ['<>','status', StatusEnum::DELETE], ['or', ['=', 'id', $get['keyword']], ['in', 'mobile', $get['keyword']], ['like', 'nickname', $get['keyword']]] ]; $userParams = ['where' => $userWhere]; $userList = User::lists($userParams); if (!empty($userList)) $where[] = ['in', 'user_id', array_column($userList, 'id')]; } if (isset($get['customer_type']) && !empty($get['customer_type']) &&$get['customer_type']>0) $where[] = ['=', 'customer_type', $get['customer_type']]; $with = ['parent' => function($query){ $query->select('id,mobile,nickname,avatar_url'); },'user' => function($query){ $query->select('id,mobile,nickname,avatar_url'); } ]; $params = ['limit' => 10, 'where' => $where, 'select' => ['user_id', 'parent_id', 'customer_type', 'created_at'],'with' =>$with,'order' => 'id desc']; $list = BusinessCardUser::listPage($params); $customerType = CardEnums::getCustomerTypeMap(); $list['customerType'] = $customerType; if (!empty($list['list'])) { foreach ($list['list'] as &$val) { if (empty($val['buying_point'])) { $val['goods_name'] = ''; } else { //找出browse_num最大值对应的goods_id $buyingPoint = array_column($val['buying_point'], null, 'browse_num'); $maxBrowse = max(array_keys($buyingPoint)); $goods_id = $buyingPoint[$maxBrowse]['item_id']; $goodsInfo = Goods::getOne([['id' => $goods_id]], true, [], false, 'goods_name'); $val['goods_name'] = empty($goodsInfo) ? '' : $goodsInfo['goods_name']; } unset($val['buying_point']); } } return $this->success('操作成功', $list); } return $this->render('clue-list'); } /** * 查看卡片 * * @param int card_id * @author hpei * @return array|mixed */ public function actionCardInfo() { if (Yii::$app->request->isAjax && Yii::$app->request->isGet) { $id = Yii::$app->request->get('id', 0); $info = BusinessCard::getOne([['=', 'id', $id], ['<>','status', StatusEnum::DELETE]], true); if (empty($info)) return $this->error('卡片不存在或者已删除'); $department_id = $info['department_id']; $position_id = $info['position_id']; $params = [ 'where' => [['in', 'id', [$department_id, $position_id]], ['<>', 'status', StatusEnum::DELETE], ['=', 'mall_id', $this->mall_id]], 'select' => ['name', 'id'], 'index' => 'id' ]; $position = BusinessCardPosition::lists($params); $info['department_name'] = isset($position[$department_id]) ? $position[$department_id]['name'] : ''; $info['position_name'] = isset($position[$position_id]) ? $position[$position_id]['name'] : ''; $info['tags'] = $info['tags'] ? explode(',', $info['tags']) : ''; $info['url'] = $info['url'] ? explode(',', $info['url']) : ''; $info['images'] = explode(',',$info['images']); $zodiacMap = CardEnums::getZodiac(); if (!empty($info['zodiac'])) { $info['zodiac'] = $zodiacMap[$info['zodiac']]; } $info['supply_resources'] = []; //提供的人脉 $info['need_resources'] = [];//需要的人脉 $info['education'] = [];//学历 $info['industry'] = [];//从事的行业 $info['identity_tags'] = [];//身份标签 //获取商城标签数据 $tag_info = BusinessCardUserTag::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['user_id' => $info['user_id']], ['cid' => $info['id']], ['status' => StatusEnum::ENABLED], ], 'with' => ['tag'], ]); $tag = BusinessCardTag::lists([ 'where' => [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ], 'index' => 'id', ]); if (!empty($info['education_id'])) { $info['education'][] = $tag[$info['education_id']]; } if (!empty($tag_info)) { foreach ($tag_info as $key => $value) { switch ($value['tag']['type']) { case 1: $info['supply_resources'][] = $value['tag']; break; case 2: $info['need_resources'][] = $value['tag']; break; case 3: $info['education'][] = $value['tag']; break; case 4: $info['industry'][] = $value['tag']; break; case 5: $info['identity_tags'][] = $value['tag']; break; } } } $setting = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic'); $info['sign'] = !empty($info['sign']) ? $info['sign'] : $setting['sign']; return $this->success('操作成功', $info); } $id = Yii::$app->request->get('id', ''); if (!$id) throw new Exception('卡片不存在或者已删除'); return $this->render('card-info', ['id' => $id]); } /** * 删除卡片 * * @author hpei * @return string */ public function actionDelete() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { $id = Yii::$app->request->post('id', 0); $t = Yii::$app->db->beginTransaction(); try { $card = BusinessCard::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $id]); if (empty($card)) throw new Exception('名片不存在'); $card->status = StatusEnum::DELETE; if (!$card->save()) throw new Exception($card->getErrorMessage()); // 所属部门需要删除 $user = BusinessCardUser::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'user_id' => $card->user_id]); if (!empty($user)) { $user->status = StatusEnum::DELETE; if (!$user->save()) throw new Exception($user->getErrorMessage()); } $t->commit(); } catch (\Exception $e) { $t->rollBack(); return $this->error($e->getMessage()); } } return $this->success('操作成功'); } /** * 获取全部职位 * * @author hpei * @return array */ public function actionGetPosition() { $position = BusinessCardPosition::getPosition($this->mall_id, ['name', 'id'], 'id'); return $this->success('操作成功', $position); } public function actionTest(){ $res = Statistics::goodsStatistics(); } }