| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- <?php
- namespace addons\BusinessCard\backend\controllers;
- use addons\BusinessCard\common\enums\CardEnums;
- use addons\BusinessCard\common\models\BusinessCard;
- use addons\BusinessCard\common\models\BusinessCardPosition;
- use addons\BusinessCard\common\models\BusinessCardTag;
- use addons\BusinessCard\common\models\BusinessCardUser;
- use addons\BusinessCard\common\models\BusinessCardUserTag;
- use common\models\common\PlatformSetting;
- use common\models\user\User;
- use common\models\goods\Goods;
- use common\enums\StatusEnum;
- use Exception;
- use Yii;
- class CardController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 名片列表
- *
- * @author hpei
- * @param string keyword
- * @return array|mixed
- */
- public function actionIndex() {
- if (Yii::$app->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();
- }
- }
|