| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087 |
- <?php
- namespace addons\BusinessCard\api\modules\v1\controllers;
- use addons\BusinessCard\common\enums\CardEnums;
- use addons\BusinessCard\common\logic\Statistics;
- use addons\BusinessCard\common\logic\WechatNotice;
- use addons\BusinessCard\common\models\BusinessCard;
- use addons\BusinessCard\common\models\BusinessCardCustomerLog;
- use addons\BusinessCard\common\models\BusinessCardGoodsStatistics;
- use addons\BusinessCard\common\models\BusinessCardPosition;
- use addons\BusinessCard\common\models\BusinessCardStatistics;
- use addons\BusinessCard\common\models\BusinessCardTag;
- use addons\BusinessCard\common\models\BusinessCardUser;
- use addons\BusinessCard\common\models\BusinessCardUserTag;
- use addons\BusinessCard\common\services\TagService;
- use api\controllers\OnAuthController;
- use common\enums\RabbitMqEnum;
- use common\enums\StatusEnum;
- use common\models\common\PosterCode;
- use common\models\user\User;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * 名片控制器
- */
- class CardController extends OnAuthController
- {
- public $modelClass = '';
- public $card = '';
- protected $authOptional = ['card-list', 'config', 'card-info-by-share'];
- /**
- * 提示创建名片
- */
- public function beforeAction($action) {
- parent::beforeAction($action);
- $white_list = [
- 'browsing-history',
- 'to-create-card',
- 'create-card',
- 'card-list',
- 'card-info',
- 'valid-card-token',
- 'like',
- 'config',
- 'is-created',
- 'card-info-by-share'
- ];
- if (in_array($action->id, $white_list)) return $action;
- $card = BusinessCard::getOne([['=', 'user_id', $this->user_id], ['=', 'status', StatusEnum::ENABLED]], true);
- $setting = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- if (empty($card)) {
- Yii::$app->controller->asJson(['code' => 3, 'msg' => '请先创建名片', 'data' => ['is_card_token' => $setting['is_card_token'] ?? 0, 'add_command_show_title' => $setting['add_command_show_title'] ?? '添加命令']])->send();
- return;
- }
- $this->card = $card;
- return $action;
-
- }
- /**
- * 进入创建名片
- *
- * @author hpei
- * @return array
- */
- public function actionToCreateCard() {
- if (Yii::$app->request->isGet) {
- $data = [];
- $setting = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- $data['images'] = !empty($setting['images']) ? json_decode($setting['images']) : [];
- $data['address'] = $setting['address'] ?? '';
- $data['company'] = $setting['company'] ?? '';
- $data['video_url'] = $setting['video_url'] ?? '';
- $data['video_cover_pic'] = $setting['video_cover_pic'] ?? '';
- $data['share_pic'] = $setting['share_pic'] ?? '';
- $data['lng'] = $setting['lng'] ?? '';
- $data['lat'] = $setting['lat'] ?? '';
- $data['department'] = BusinessCardPosition::departmentPosition($this->mall_id);
- $data['department_show_label'] = $setting['department_show_label'] ?? '部门';
- $data['company_show_label'] = $setting['company_show_label'] ?? '公司';
- $data['is_allow_edit_card_info'] = $setting['is_allow_edit_card_info'] ?? 0;
- $data['is_show_update_division'] = $setting['is_show_update_division'] ?? 0;
- $data['default_department_id'] = BusinessCardPosition::find()
- ->where(['mall_id' => $this->mall_id, 'is_default_position' => StatusEnum::ENABLED])
- ->andWhere(['>', 'parent_id', 0])
- ->select('id')
- ->scalar();
- $data['is_show_networking'] = $setting['is_show_networking'] ?? 0;
- $data['collect_wechat'] = !empty($setting['collect_wechat']) ? $setting['collect_wechat'] : 0;
- $data['collect_info'] = !empty($setting['collect_info']) ? $setting['collect_info']: 0;
- $data['is_required'] = $setting['is_required'] ?? 2;
- $data['supply_resources'] = [];
- $data['need_resources'] = [];
- $data['education'] = [];
- $data['industry'] = [];
- $data['identity_tags'] = [];
- $data['zodiac'] = CardEnums::getZodiac();
- $data['sign'] = $setting['sign'] ?? '';
- //获取商城标签数据
- $tag_info = BusinessCardTag::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ],
- 'select' => 'id as tid,name,type',
- 'order' => 'id asc',
- ]);
- if (!empty($tag_info)) {
- foreach ($tag_info as $key => $value) {
- switch ($value['type']) {
- case 1:
- $data['supply_resources'][] = $value;
- break;
- case 2:
- $data['need_resources'][] = $value;
- break;
- case 3:
- $data['education'][] = $value;
- break;
- case 4:
- $data['industry'][] = $value;
- break;
- case 5:
- $data['identity_tags'][] = $value;
- break;
- }
- }
- }
- if (BusinessCard::find()->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])->count()) {
- return $this->error('已存在卡片', $data);
- }
- return $this->success('操作成功', $data);
- }
- }
-
- /**
- * 创建名片&编辑名片
- * @author hpei
- * @param string $avatar_url 头像
- * @param int $mobile 电话
- * @param string $nickname 昵称
- * @param int $department_id 部门ID
- * @param int $position_id 职位ID
- * @param string $phone 座机
- * @param string $email 邮箱
- * @param string $company 公司
- * @param string $address 地址
- * @param string $sign 签名
- * @param string $video 视频
- * @param array $tags 标签
- * @param array $images 图文
- * @return array|mixed
- */
- public function actionCreateCard() {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['mobile', 'nickname', 'department_id'], 'required'],
- [['avatar_url', 'phone', 'email', 'company', 'address', 'sign', 'video', 'tags', 'images', 'id', 'card_token',
- 'video_cover_pic', 'share_pic', 'lng', 'lat', 'wechat', 'phone_key_text', 'position_id', 'zodiac',
- 'wechat_code', 'province_id', 'city_id', 'supply_resources', 'need_resources', 'education', 'industry', 'identity_tags', 'delete_tag'], 'safe'],
- [['avatar_url', 'phone', 'email', 'company', 'address', 'sign', 'video', 'tags', 'images', 'video_cover_pic', 'active_city'], 'default', 'value' => ''],
- [['id', 'sex', 'marry_status', 'education_id'], 'default', 'value' => 0]
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- try {
- // 判断当前用户是否有申请过卡片 - 非编辑状态下才需要判断
- if (empty($params['id'])) {
- $card = BusinessCard::getOne([
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]
- ]);
- if (!empty($card)) return $this->error('不能多次创建');
- }
- // 判断密令 - 编辑的时候不需要密令
- if (empty($params['id'])) {
- $card_token = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic.card_token');
- $is_card_token = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic.is_card_token');
- if (!empty($card_token) && (string)$params['card_token'] != $card_token && !empty($is_card_token)) throw new \Exception("名片密令错误");
- } else {
- /**
- * @var $cardUser BusinessCardUser
- */
- $cardUser = BusinessCardUser::getOne([
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => StatusEnum::ENABLED]
- ]);
- $isAllowEditCardInfo = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic.is_allow_edit_card_info');
- if (empty($isAllowEditCardInfo) && $cardUser->role_type == 3) { // 如果是员工 那么不能修改 图文信息
- unset($params['images'], $params['video_cover_pic'], $params['video'], $params['share_pic']);
- }
- }
- // 是否已经没有了职位,只有角色?
- $res1 = BusinessCardPosition::checkPosition(['mall_id' => $this->mall_id, 'id' => $params['department_id'], 'isParent' => true]);
- // $res2 = BusinessCardPosition::checkPosition(['mall_id' => $this->mall_id, 'id' => $params['position_id'], 'isParent' => false]);
- // || $res2 === false
- if ($res1 === false) {
- return $this->error('部门不存在');
- }
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- //修改管理判断是否传了职位id过来没有传默认一个
- if (empty($params['position_id'])) {
- // 默认一个职位
- $params['position_id'] = BusinessCardPosition::find()->where(['mall_id' => $params['mall_id']])
- ->andWhere(['parent_id' => $params['department_id']])
- ->andWhere(['status' => StatusEnum::ENABLED])
- ->orderBy('id asc')->select('id')->scalar() ?? 0;
- // 判断部门下是否存在职位不存在提醒
- if (empty($params['position_id'])) {
- $department_name = BusinessCardPosition::find()->where(['id' => $params['department_id']])
- ->select('name')->scalar();
- return $this->error("请在部门 {$department_name} 下面添加至少一个职位");
- }
- }
- $setting = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- if ($setting['is_show_networking'] == 1) {
- //开启收集微信二维码按钮,微信二维码必填
- if ($setting['collect_wechat'] == 1) {
- if (empty($params['wechat_code'])) return $this->error('请上传微信二维码');
- }
- if ($setting['collect_info'] == 1) {
- //开启了必填按钮,则需要校验数据是否为空
- if ($setting['is_required'] == 1) {
- if (empty($params['sex'])) return $this->error('请选择性别');
- if (empty($params['marry_status'])) return $this->error('请选择婚姻状态');
- if (empty($params['active_city'])) return $this->error('请选择活跃城市');
- if (empty($params['industry'])) return $this->error('请选择从事行业');
- if (empty($params['identity_tags'])) return $this->error('请选择身份标签');
- if (count($params['identity_tags']) > 1) return $this->error('最多只能选择1个身份标签');
- if (count($params['industry']) > 3) return $this->error('最多只能选择3个行业');
- }
- }
- }
- if (is_array($params['images'])) $params['images'] = implode(',', $params['images']);
- if (is_array($params['tags'])) $params['tags'] = implode(',', $params['tags']);
- if($params['id'] == 'undefined') $params['id'] = '';
- $res1 = BusinessCard::setData($params);
- if (!$res1) return $this->error(BusinessCard::getStaticError());
- $params['cid'] = $params['id'];
- if (empty($params['id'])) $params['cid'] = $res1->id;
- //添加用户标签
- $res3 = (new TagService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->setUserTag($params);
- if(!$params['id']){
- $res2 = BusinessCardStatistics::setData(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'card_num' => 1]);
- }
- return $this->success('操作成功', $res1->id);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- /**
- * 名片预览
- * @param int $card_id
- * @param string $type show:预览 edit:编辑
- * @return array
- * @throws \Exception
- * @author hpei
- */
- public function actionCardInfo() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['scene','card_id','share_id','type'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $type = Yii::$app->request->get('type', 'show');
- $card_id = $params['card_id'] ?? null;
- $share_id = $params['share_id'] ?? null;
- // 检查提交的参数
- if(!empty($params['scene'])){
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $where[] = ['=', 'code', $params['scene']];
- $qrode = PosterCode::getOne($where,true);
- if($qrode){
- $card_id = $qrode['item_id'];
- $share_id = $qrode['user_id'];
- }
- }
- $setting = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- if (!empty($card_id)) { // 如果 没有拿到分享人的 那么就拿 card_id的
- $where = [['=', 'id', $card_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where);
- }
- if(!empty($share_id) && empty($card_info)){ // 先拿分享人的
- $where = [['=', 'user_id', $share_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where);
- }
- if (empty($card_info)){ // 如果没有 那就拿当前用户的
- $where = [['=', 'user_id', $this->user_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $is_how_parent_card = boolval($setting['is_show_parent_card']); // 只有查看自己的名片的时候才需要
- $card_info = BusinessCard::getCardInfo($where);
- }
- // V3需求,如果自己没有名片则取出上级名片
- $is_parent_card = StatusEnum::DISABLED;
- if (empty($card_info) && !empty($is_how_parent_card) && $params['type'] != 'edit') { // 如果还没有 就拿上级的
- // 取之前的浏览过的名片
- $history_card_id = BusinessCardCustomerLog::find()->where(['mall_id' => $this->mall_id])
- ->andWhere(['user_id' => $this->user_id])
- ->andWhere(['log_type' => CardEnums::LOG_TYPE_CARD])
- ->andWhere(['status' => StatusEnum::ENABLED])
- ->orderBy('id desc')
- ->select('item_id')->scalar();
- if (!empty($history_card_id)) {
- $where = [['=', 'id', $history_card_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where);
- }
- if (empty($card_info)) {
- // 取出上级的名片
- $parent_id = User::find()->where(['id' => $this->user_id])->select('parent_id')->scalar();
- if (!empty($parent_id)) {
- $where = [['=', 'user_id', $parent_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where);
- }
- }
- if (!empty($card_info)) {
- $is_parent_card = StatusEnum::ENABLED;
- $params['type'] = 'show';
- $card_id = $card_info['id'];
- }
- }
- $add_command_show_title = $setting['add_command_show_title'] ?? '添加命令';
- //var_dump($card_info);
- if (empty($card_info)&&$share_id) {
- Yii::$app->controller->asJson(['code' => 3, 'msg' => '名片不存在,请先创建名片', 'data' => ['is_card_token' => $setting['is_card_token'] ?? 0, 'add_command_show_title' => $add_command_show_title]])->send();
- return;
- }else if(empty($card_info)&&!$card_id&&$params['type']!='edit'){
- Yii::$app->controller->asJson(['code' => 4, 'msg' => '请先创建名片', 'data' => ['is_card_token' => $setting['is_card_token'] ?? 0, 'add_command_show_title' => $add_command_show_title]])->send();
- return;
- }
- if (in_array($type, ['show', 'edit'])) {
- $card_info['goods_list'] = empty($setting) ? [] : json_decode($setting['goods_list'], true);
- $card_info['logo'] = empty($setting) ? '' : $setting['logo'];
- $card_info['style'] = $setting['style'] ?? '';
- $card_info['video_url'] = !empty($card_info['video']) ? $card_info['video'] : ($setting['video_url'] ?? '');;
- $card_info['video_cover_pic'] = !empty($card_info['video_cover_pic']) ? $card_info['video_cover_pic'] : ($setting['video_cover_pic'] ?? '');
- $card_info['share_title'] = $setting['share_title'] ?? '';
- $card_info['share_desc'] = $setting['share_desc'] ?? '';
- $card_info['share_pic'] = !empty($card_info['share_pic']) ? $card_info['share_pic'] : ($setting['share_pic'] ?? '');
- $card_info['list_card_show'] = !empty($setting['list_card_show']) ? Json::decode($setting['list_card_show']) : [];
- // $card_info['like_num'] = $card_info['like_num'];//靠谱数
- // $card_info['browse_num'] = $card_info['browse_num'];//浏览数
- $card_info['lately_browse'] = BusinessCardCustomerLog::latelyBrowse($card_id);//最近浏览
- $card_user = BusinessCardUser::getOne([['=', 'user_id', $this->user_id]]);
- $card_info['user_role'] = empty($card_user) ? 0 : $card_user->role_type;
- $where = [['=', 'status', StatusEnum::ENABLED], ['=', 'user_id', $this->user_id], ['=', 'log_type', CardEnums::LOG_TYPE_LIKE], ['=', 'item_id', $card_info['id']]];
- $card_info['is_like'] = BusinessCardCustomerLog::count(['where' => $where]) > 0;
- $card_info['is_show_alert'] = !empty($setting['is_show_alert']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_enable_save_phone'] = !empty($setting['is_enable_save_phone']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_hidden_popularity'] = !empty($setting['is_hidden_popularity']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_show_mall_nav'] = !empty($setting['is_show_mall_nav']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_show_update_division'] = !empty($setting['is_show_update_division']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_parent_card'] = $is_parent_card;
- $card_info['parent_id'] = $parent_id ?? 0;
- $card_info['collect_wechat'] = !empty($setting['collect_wechat']) ? $setting['collect_wechat'] : 0;
- $card_info['collect_info'] = !empty($setting['collect_info']) ? $setting['collect_info'] : 0;
- $card_info['sign'] = !empty($card_info['sign']) ? $card_info['sign'] : $setting['sign'];
- if ($type == 'show') {
- if ($card_info['user_id'] != $this->user_id) {
- Statistics::handler(['item_id' => $card_id, 'user_id' => $this->user_id,
- 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_CARD]);
- if ($this->user_id) {
- WechatNotice::handler(['to_user_id' => $card_info['user_id'], 'user_id' => $this->user_id,
- 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_CARD]);
- }
- }
- if ($share_id) Statistics::handler(['item_id' => $card_id, 'user_id' => $share_id,
- 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_SHARE]);
- if (empty($is_parent_card)) { // 如果为非上级名片,那么就需要绑定关系
- //绑定关系
- $pid = Yii::$app->request->get('pid', 0);
- $data = ['parent_id' => $pid, 'user_id' => $this->user_id, 'mall_id' => $this->mall_id,'card_id' =>$card_id];
- if ($pid != 0 && $pid == $card_info['user_id']){
- Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE,
- $data, Statistics::class, 'band_parent_handle');
- }
- }
- // if ($card_info['browse_num'] > 0) {
- // 需要返回流量数据
- $card_info['browse_list'] = BusinessCardCustomerLog::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['item_id' => $card_info['id']],
- ['log_type' => CardEnums::LOG_TYPE_CARD],
- ['status' => StatusEnum::ENABLED],
- ],
- 'limit' => 5,
- 'group' => 'user_id',
- 'with' => ['user'],
- 'order' => 'id desc',
- 'select'=> 'id, user_id, created_at'
- ]);
- // }
- $card_info['config'] = [
- 'company_name_show_label' => $setting['company_name_show_label'] ?? '公司名称',
- 'company_address_show_label' => $setting['company_address_show_label'] ?? '公司地址',
- 'add_command_show_title' => $add_command_show_title,
- 'is_card_token' => $setting['is_card_token'] ?? 0,
- ];
- }
- $card_info['supply_resources'] = []; //提供的人脉
- $card_info['need_resources'] = [];//需要的人脉
- $card_info['education'] = [];//学历
- $card_info['industry'] = [];//从事的行业
- $card_info['identity_tags'] = [];//身份标签
- //获取用户标签
- $tag_info = BusinessCardUserTag::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['user_id' => $card_info['user_id']],
- ['cid' => $card_info['id']],
- ['status' => StatusEnum::ENABLED],
- ],
- 'with' => ['tag'],
- ]);
- if (!empty($tag_info)) {
- foreach ($tag_info as $key => $value) {
- switch ($value['tag']['type']) {
- case 1:
- $value['name'] = $value['tag']['name'];
- unset($value['tag']);
- $card_info['supply_resources'][] = $value;
- break;
- case 2:
- $value['name'] = $value['tag']['name'];
- unset($value['tag']);
- $card_info['need_resources'][] = $value;
- break;
- case 3:
- $value['name'] = $value['tag']['name'];
- unset($value['tag']);
- $card_info['education'][] = $value;
- break;
- case 4:
- $value['name'] = $value['tag']['name'];
- unset($value['tag']);
- $card_info['industry'][] = $value;
- break;
- case 5:
- $value['name'] = $value['tag']['name'];
- unset($value['tag']);
- $card_info['identity_tags'][] = $value;
- break;
- }
- }
- }
- }
-
- // 不需要浏览名片列表
- // if ($card_info['user_id'] != $this->user_id) Statistics::handler(['item_id' => $card_id,'card_user_id' => $card_info['user_id'],
- // 'user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_INDEX]);
- return $this->success('操作成功', $card_info);
- }
- }
- /**
- * 名片预览
- * @param int $card_id
- * @param string $type show:预览 edit:编辑
- * @return array
- * @throws \Exception
- * @author hpei
- */
- public function actionCardInfoByShare() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['scene','card_id','share_id','type'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $type = Yii::$app->request->get('type', 'show');
- $card_id = $params['card_id'] ?? null;
- $share_id = $params['share_id'] ?? null;
- // 检查提交的参数
- if(!empty($params['scene'])){
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $where[] = ['=', 'code', $params['scene']];
- $qrode = PosterCode::getOne($where,true);
- if($qrode){
- $card_id = $qrode['item_id'];
- $share_id = $qrode['user_id'];
- }
- }
- $setting = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- if (!empty($card_id)) { // 如果 没有拿到分享人的 那么就拿 card_id的
- $where = [['=', 'id', $card_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where);
- }
- if(!empty($share_id) && empty($card_info)){ // 先拿分享人的
- $where = [['=', 'user_id', $share_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where);
- }
- if (empty($card_info)){
- return $this->error('数据不存在');
- }
- $add_command_show_title = $setting['add_command_show_title'] ?? '添加命令';
- if (in_array($type, ['show'])) {
- $card_info['goods_list'] = empty($setting) ? [] : json_decode($setting['goods_list'], true);
- $card_info['logo'] = empty($setting) ? '' : $setting['logo'];
- $card_info['style'] = $setting['style'] ?? '';
- $card_info['video_url'] = !empty($card_info['video']) ? $card_info['video'] : ($setting['video_url'] ?? '');;
- $card_info['video_cover_pic'] = !empty($card_info['video_cover_pic']) ? $card_info['video_cover_pic'] : ($setting['video_cover_pic'] ?? '');
- $card_info['share_title'] = $setting['share_title'] ?? '';
- $card_info['share_desc'] = $setting['share_desc'] ?? '';
- $card_info['share_pic'] = !empty($card_info['share_pic']) ? $card_info['share_pic'] : ($setting['share_pic'] ?? '');
- $card_info['list_card_show'] = !empty($setting['list_card_show']) ? Json::decode($setting['list_card_show']) : [];
- // $card_info['like_num'] = $card_info['like_num'];//靠谱数
- // $card_info['browse_num'] = $card_info['browse_num'];//浏览数
- $card_info['lately_browse'] = BusinessCardCustomerLog::latelyBrowse($card_id);//最近浏览
- $card_info['user_role'] = 0;
- $card_info['is_like'] = false;
- $card_info['is_show_alert'] = !empty($setting['is_show_alert']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_enable_save_phone'] = !empty($setting['is_enable_save_phone']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_hidden_popularity'] = !empty($setting['is_hidden_popularity']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_show_mall_nav'] = !empty($setting['is_show_mall_nav']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_show_update_division'] = !empty($setting['is_show_update_division']) ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- $card_info['is_parent_card'] = 1;
- $card_info['parent_id'] = $share_id;
- if (empty($card_info['sign'])) $card_info['sign'] = $setting['sign'];
- if ($share_id) Statistics::handler(['item_id' => $card_id, 'user_id' => $share_id,
- 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_SHARE]);
- // 需要返回流量数据
- $card_info['browse_list'] = BusinessCardCustomerLog::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['item_id' => $card_info['id']],
- ['log_type' => CardEnums::LOG_TYPE_CARD],
- ['status' => StatusEnum::ENABLED],
- ],
- 'limit' => 5,
- 'group' => 'user_id',
- 'with' => ['user'],
- 'order' => 'id desc',
- 'select'=> 'id, user_id, created_at'
- ]);
- // }
- $card_info['config'] = [
- 'company_name_show_label' => $setting['company_name_show_label'] ?? '公司名称',
- 'company_address_show_label' => $setting['company_address_show_label'] ?? '公司地址',
- 'add_command_show_title' => $add_command_show_title,
- ];
- }
- return $this->success('操作成功', $card_info);
- }
- }
- /**
- * 海报接口
- *
- * @author hpei
- * @param string keyword
- * @return array|mixed
- */
- public function actionPoster() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- $carduser = BusinessCard::getOne([['id'=>$params['id'],'status' =>StatusEnum::ENABLED]],true);
- $data['content'] = $res['content'];
- $list['name'] = $carduser['nickname'];
- $list['id'] = $carduser['id'];
- $list['head'] = $carduser['avatar_url'];
- $list['list'][] = $data;
- $list['qrcode_id'] = CardEnums::SHARE_TYPE;
- return $this->success('操作成功',$list);
- }
- }
- /**
- * 名片列表
- * @author hpei
- * @param string $keyword
- * @return array
- */
- public function actionCardList() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['<>','status', StatusEnum::DELETE];
- if (isset($params['department_id']) && !empty($params['department_id'])) {
- }
- //添加判断条件,管理层可以看自己部门的信息,非管理层只可以看自己推荐人的信息
- $carduser = BusinessCardUser::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status' =>StatusEnum::ENABLED]]);
- $card = BusinessCard::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status' =>StatusEnum::ENABLED]]);
- if($carduser['role_type'] == CardEnums::ROLE_TYPE_STAFF || !$carduser['role_type'] && $card){
- $where[] = ['parent_id' => $this->user_id];
- }else if($carduser['role_type'] == CardEnums::ROLE_TYPE_LEADER){
- if($carduser['department_id']){
- //分组搜索
- if (isset($params['department_id']) && !empty($params['department_id']) && $params['department_id'] !=-1) {
- $where[] = ['position_id' => $params['department_id']];
- }
- $where[] = ['department_id' => $carduser['department_id']];
- $position_params['where'][] = ['=', 'parent_id',$carduser['department_id']];
- }
- }else{
- //分组搜索
- if (isset($params['department_id']) && !empty($params['department_id']) && $params['department_id'] !=-1) {
- $where[] = ['department_id' => $params['department_id']];
- }
- $position_params['where'][] = ['=', 'parent_id', '0'];
- }
- $position_params['where'][] = ['=', 'mall_id', $this->mall_id];
- $position_params['where'][] = ['=', 'status' , StatusEnum::ENABLED];
- $position_params['order'] = 'sort desc';
- $position_data = BusinessCardPosition::lists($position_params,true);
- $position_data_all[0]['id'] = -1;
- $position_data_all[0]['name'] = "全部";
- $list = BusinessCard::getCardList($where,'share_num desc');
- $list['is_create'] = (bool)BusinessCard::count(['where' => [['=', 'user_id', $this->user_id], ['=', 'status', StatusEnum::ENABLED]]]);
- $list['detail_data']['user_role'] = empty($carduser) ? 0 : $carduser['role_type'];
- $list['position'] = array_merge($position_data_all,$position_data);
- return $this->success('操作成功', $list);
- }
- }
- /**
- * boss的优秀列表
- * @author ltm
- * @param string $keyword
- * @return array
- */
- public function actionBossGoods() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $carduser = BusinessCardUser::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status' =>StatusEnum::ENABLED]]);
- if($carduser['role_type'] == CardEnums::ROLE_TYPE_BOSS){//老板
- //分组搜索
- if (isset($params['department_id']) && !empty($params['department_id']) && $params['department_id'] !=-1) {
- $user_ids = BusinessCardUser::find()->select("user_id")->where(['mall_id' => $this->mall_id])
- ->andWhere(['=', 'department_id', $params['department_id']])->asArray()->column();
- $where[] = ['in', 'user_id', $user_ids];
- }
- $position_params['where'][] = ['=', 'parent_id', '0'];
- }else{
- if($carduser['role_type'] == CardEnums::ROLE_TYPE_STAFF || !$carduser['role_type']){
- $where[] = ['parent_id' => $this->user_id];
- }else if($carduser['role_type'] == CardEnums::ROLE_TYPE_LEADER){
- //分组搜索
- if (isset($params['department_id']) && !empty($params['department_id']) && $params['department_id'] !=-1) {
- $user_ids = BusinessCardUser::find()->select("user_id")->where(['mall_id' => $this->mall_id])
- ->andWhere(['=', 'department_id', $carduser['department_id']])
- ->andWhere(['=', 'position_id', $params['department_id']])
- ->asArray()->column();
- }else{
- $user_ids = BusinessCardUser::find()->select("user_id")->where(['mall_id' => $this->mall_id])
- ->andWhere(['=', 'department_id', $carduser['department_id']])->asArray()->column();
- }
- $where[] = ['in', 'user_id', $user_ids];
- $position_params['where'][] = ['=', 'parent_id',$carduser['department_id']];
- }
- }
- //员工和主管看到得信息
- $with = ['goods'];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $order = 'total_views desc';
- $goodsparams = array('where' => $where,'with' => $with,'group'=>'goods_id','order'=>$order);
- $goodsparams['select'] = 'goods_id,max(total_views) as total_views,count(user_id) as total_visitors';
- $list = BusinessCardGoodsStatistics::listPage($goodsparams,false,true);
- $position_params['where'][] = ['=', 'mall_id', $this->mall_id];
- $position_params['where'][] = ['=', 'status' , StatusEnum::ENABLED];
- $position_params['order'] = 'sort desc';
- $position_data = BusinessCardPosition::lists($position_params,true);
- $position_data_all[0]['id'] = -1;
- $position_data_all[0]['name'] = "全部";
- $list['detail_data']['user_role'] = empty($carduser) ? 0 : $carduser['role_type'];
- $list['position'] = array_merge($position_data_all,$position_data);
- return $this->success('操作成功', $list);
- }
- }
- /**
- * 雷达优秀列表
- * @author ltm
- * @param string $keyword
- * @return array
- */
- public function actionSell() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $params['where'][] = ['mall_id' =>$this->mall_id];
- $params['where'][] = ['status' =>StatusEnum::ENABLED];
- //添加判断条件,管理层可以看自己部门的信息,非管理层只可以看自己推荐人的信息
- $carduser = BusinessCardUser::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status' =>StatusEnum::ENABLED]]);
- if($carduser['role_type'] == CardEnums::ROLE_TYPE_STAFF || !$carduser['role_type']){ // 员工
- $params['where'][] = ['parent_id' => $this->user_id];
- }else if($carduser['role_type'] == CardEnums::ROLE_TYPE_LEADER){ // 主管
- if($carduser['department_id']){
- //分组搜索
- if (isset($params['department_id']) && !empty($params['department_id']) && $params['department_id'] !=-1) {
- $params['where'][] = ['position_id' => $params['department_id']];
- }
- $params['where'][] = ['department_id' => $carduser['department_id']];
- $position_params['where'][] = ['=', 'parent_id',$carduser['department_id']];
- }else{
- return $this->error('请联系管理先设置部门再查看');
- }
- }else{ // 老板
- //分组搜索
- if (isset($params['department_id']) && !empty($params['department_id']) && $params['department_id'] !=-1) {
- $params['where'][] = ['department_id' => $params['department_id']];
- }
- $position_params['where'][] = ['=', 'parent_id', '0'];
- }
- $params['order'] = 'share_num desc';
- $params['limit'] = $params['limit'] ?? 5;
- $params['with'] = ['user', 'card' => function($query) {
- $query->where(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]])->select('user_id, browse_num');
- }];
- $list = BusinessCardUser::listPage($params);
- //分组搜索
- $position_params['where'][] = ['=', 'mall_id', $this->mall_id];
- $position_params['where'][] = ['=', 'status' , StatusEnum::ENABLED];
- $position_params['order'] = 'sort desc';
- $position_data = BusinessCardPosition::lists($position_params);
- $position_data_all[0]['id'] = -1;
- $position_data_all[0]['name'] = "全部";
- $list['detail_data']['user_role'] = empty($carduser) ? 0 : $carduser['role_type'];
- $list['position'] = array_merge($position_data_all,$position_data);
- return $this->success('操作成功', $list);
- }
- }
- /**
- * 获取部门列表
- * @author ltm
- * @param string $keyword
- * @return array
- */
- public function actionPosition() {
- if (Yii::$app->request->isGet) {
- //分组搜索
- $carduser = BusinessCardUser::getOne([['mall_id' => $this->mall_id,'user_id' => $this->user_id,'status' =>StatusEnum::ENABLED]]);
- $position_params['where'][] = ['=', 'mall_id', $this->mall_id];
- $position_params['where'][] = ['=', 'status' , StatusEnum::ENABLED];
- $position_params['order'] = 'sort desc';
- $position_data = BusinessCardPosition::lists($position_params,true);
- $position_data_all[0]['id'] = -1;
- $position_data_all[0]['name'] = "全部";
- $list['detail_data']['user_role'] = empty($carduser) ? 0 : $carduser['role_type'];
- $list['position'] = array_merge($position_data_all,$position_data);
- return $this->success('操作成功', $list);
- }
- }
- /**
- * 商品列表
- * @author ltm
- * @param string $keyword
- * @return array
- */
- public function actionGoods() {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $where[] = ['parent_id' => $this->user_id];
- //员工和主管看到得信息
- $with = ['goods'];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $order = 'total_views desc';
- $goodsparams = array('where' => $where,'with' => $with,'group'=>'goods_id','order'=>$order);
- $goodsparams['select'] = 'goods_id,max(total_views) as total_views,count(user_id) as total_visitors';
- $list = BusinessCardGoodsStatistics::listPage($goodsparams,false,true);
- $position_params['where'][] = ['=', 'mall_id', $this->mall_id];
- $position_params['where'][] = ['=', 'status' , StatusEnum::ENABLED];
- $position_params['order'] = 'sort desc';
- $position_data = BusinessCardPosition::lists($position_params,true);
- $position_data_all[0]['id'] = -1;
- $position_data_all[0]['name'] = "全部";
- $list['detail_data']['user_role'] = empty($carduser) ? 0 : $carduser['role_type'];
- $list['position'] = array_merge($position_data_all,$position_data);
- return $this->success('操作成功', $list);
- }
- }
- /**
- * 点赞&取消点赞
- * @author hpei
- * @param int $card_id
- * @return mixed
- */
- public function actionLike() {
- if (Yii::$app->request->isPost) {
- $card_id = Yii::$app->request->post('card_id', 0);
- $where = [['=', 'id', $card_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $card_info = BusinessCard::getCardInfo($where, false);
- if (empty($card_info)) return $this->error('卡片不存在');
- Statistics::handler(['item_id' => $card_id,'card_user_id' =>$card_info['user_id'], 'user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_LIKE]);
- //$res = Statistics::async_handle(['item_id' => $card_id,'card_user_id' =>$card_info['user_id'], 'user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'log_type' => CardEnums::LOG_TYPE_LIKE]);
- //var_dump($res);
- return $this->success('操作成功');
- }
- }
- /**
- * 浏览记录
- * @return mixed
- */
- public function actionBrowsingHistory()
- {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['keyword'], 'string'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['<>','status', StatusEnum::DELETE];
- $position_params['where'][] = ['=', 'mall_id', $this->mall_id];
- $position_params['where'][] = ['=', 'status' , StatusEnum::ENABLED];
- $position_params['order'] = 'sort desc';
- $position_data = BusinessCardPosition::lists($position_params,true);
- $position_data_all[0]['id'] = -1;
- $position_data_all[0]['name'] = "全部";
- $cWhere = [
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => StatusEnum::ENABLED],
- ['log_type' => CardEnums::LOG_TYPE_CARD],
- ];
- if (!empty($params['keyword'])) {
- $cWhere[] = ['or', ['like', 'nickname', $params['keyword']],
- ['like', 'mobile', $params['keyword']],
- ['like', 'email', $params['keyword']]];
- }
- // 获取浏览过的数据
- $card_ids = BusinessCardCustomerLog::listPage([
- 'where' => $cWhere,
- 'order' => 'id desc',
- 'select'=> 'item_id',
- 'limit' => 10
- ]);
- $list = [];
- if (!empty($card_ids['list'])) {
- $where[] = ["id" => array_column($card_ids['list'], "item_id")];
- $list = BusinessCard::getCardList($where,'share_num desc');
- }
- $list['is_create'] = (bool)BusinessCard::count(['where' => [['=', 'user_id', $this->user_id], ['=', 'status', StatusEnum::ENABLED]]]);
- $list['detail_data']['user_role'] = empty($carduser) ? 0 : $carduser['role_type'];
- $list['position'] = array_merge($position_data_all,$position_data);
- return $this->success('操作成功', $list);
- }
- }
- /**
- * 我的页面数据
- * @return mixed|null
- */
- public function actionInfo()
- {
- $ret['card'] = BusinessCard::getCardInfo([
- // 'where' => [
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => StatusEnum::ENABLED],
- // ],
- // 'select'=> 'id, nickname, avatar_url, address, company, tags, images, department_id, position_id',
- ]);
- if (empty($ret['card'])) return $this->error('请先创建名片', [], 4);
- $today_browse_num = BusinessCardCustomerLog::find()
- ->where(['mall_id' => $this->mall_id])
- ->andWhere(['item_id' => $ret['card']['id']])
- ->andWhere(['log_type' => CardEnums::LOG_TYPE_CARD])
- ->andWhere(['>=', 'created_at', strtotime(date('Y-m-d'))])
- ->count();
- $share_num = BusinessCardCustomerLog::find()
- ->where(['mall_id' => $this->mall_id])
- ->where(['user_id' => $this->user_id])
- ->andWhere(['log_type' => CardEnums::LOG_TYPE_SHARE])
- ->count();
- // 数据
- $ret['data'] = [
- 'today_browse_num' => $today_browse_num,
- 'browse_num' => $ret['card']['browse_num'] + $today_browse_num, // 今天的量
- 'share_num' => $ret['card']['share_num'] + $share_num, // 被分享+本人分享
- ];
- return $this->success("获取成功", $ret);
- }
- /**
- * 最近访客记录
- * @return mixed|null
- */
- public function actionRecentVisitors()
- {
- $get = \Yii::$app->request->get();
- $id = BusinessCard::find()
- ->where(['mall_id' => $this->mall_id])
- ->andWhere(['status' => StatusEnum::ENABLED])
- ->andWhere(['user_id' => $this->user_id])
- ->select('id')
- ->scalar();
- $keyword = $get['keyword'];
- if (empty($id)) return $this->error('请先创建名片', [], 4);
-
- $where = [
- 'alias' => 'bc',
- 'join' =>[['LEFT JOIN', User::tableName() . ' u', "u.id = bc.user_id"]],
- 'where' => [
- ['bc.mall_id' => $this->mall_id],
- ['bc.log_type' => CardEnums::LOG_TYPE_CARD],
- ['bc.item_id' => $id],
- ['<>', 'bc.user_id', $this->user_id],
- ],
- 'order' => 'bc.id desc',
- 'select'=> 'bc.id, bc.log_type, bc.created_at, bc.user_id, u.avatar_url, u.mobile, u.nickname, u.username',
- // 'with' => ['user'],
- 'limit' => $get['limit'] ?? 10,
- 'group' => 'bc.user_id',
- // 'joinWith' =>['user' => function ($query) {
- // $query->from(['u' => User::tableName()]);
- // }]
- ];
- if (!empty($keyword)) {
- $where['where'][] = ['or',['like', 'u.nickname', $keyword], ['like', 'u.id', $keyword], ['like', 'u.mobile', $keyword]];
- }
- // print_r($where);exit;
- $ret = BusinessCardCustomerLog::listPage($where);
- if (!empty($ret['list'])) {
- foreach ($ret['list'] as &$item) {
- $item['created_at'] = date("Y/m/d", $item['created_at']);
- }
- }
- return $this->success('获取成功', $ret);
- }
- /**
- * 校验卡片密钥
- * @return mixed|void|null
- * @throws \Exception
- */
- public function actionValidCardToken()
- {
- $params = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['card_token'], 'string'],
- [['card_token'], 'required'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $card_token = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic.card_token');
- if (!empty($card_token) && (string)$params['card_token'] != $card_token) return $this->error('名片密令错误');
- return $this->success('校验通过');
- }
- public function actionConfig()
- {
- $config = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- return $this->success('success', [
- 'is_not_forced_login' => $config['is_not_forced_login'] ?? 0,
- 'is_show_create_btn' => $config['is_show_create_btn'] ?? 0,
- ]);
- }
- public function actionIsCreated()
- {
- $where = [['=', 'user_id', $this->user_id], ['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]];
- $find = BusinessCard::find();
- BusinessCard::paramPack(compact('where'), $find);
- return $this->success('success', [
- 'is_exists' => $find->exists()
- ]);
- }
- //获取人脉配置数据
- public function actionGetNetworkingConfig()
- {
- $request = Yii::$app->request;
- try {
- if ($request->isGet) {
- $params = $request->get();
- $info = (new TagService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->getNetWorkingConfig($params);
- return $this->success('获取成功', $info);
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- //获取名片列表数据
- public function actionGetNetworkingList()
- {
- $request = Yii::$app->request;
- try {
- if ($request->isPost) {
- $post = $request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['name'], 'string'],
- [['level_status', 'distance', 'sex', 'marry_status', 'page', 'limit'], 'integer'],
- [['latitude', 'longitude'], 'number'],
- [['industry', 'identity_tags', 'zodiac'], 'safe'],
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $info = (new TagService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->getNetworkingList($post);
- return $this->success('获取成功', $info);
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- public function actionDelUserTag()
- {
- $request = Yii::$app->request;
- try {
- if ($request->isPost) {
- $post = $request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['id'], 'integer']
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $res = (new TagService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->delUserTag($post);
- return $this->success('操作成功');
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
|