| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace addons\BusinessCard\backend\controllers;
- use addons\BusinessCard\common\enums\CardEnums;
- use addons\BusinessCard\common\models\BusinessCardTag;
- use addons\BusinessCard\common\logic\Statistics;
- use addons\BusinessCard\common\services\TagService;
- use common\enums\RabbitMqEnum;
- use common\enums\StatusEnum;
- use common\models\user\UserLevel;
- use Exception;
- use Yii;
- class SettingController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 基础配置
- *
- * @author hpi
- * @return array|mixed
- */
- public function actionIndex() {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [[ 'share_title', 'share_desc', 'networking_name', 'expert_name', 'square_name', 'networking_notice', 'sign'], 'safe'],
- [['goods_list','address', 'company', 'images', 'logo', 'card_token',
- 'style', 'list_card_show', 'video_url', 'video_cover_pic', 'share_pic', 'is_card_token', 'company_name_show_label',
- 'company_address_show_label', 'department_show_label', 'company_show_label', 'first_img', 'second_img', 'level', 'identity_tags', 'industry',
- 'education' , 'need_resources', 'supply_resources', 'add_command_show_title'], 'safe'],
- [['wechat_notice_6', 'wechat_notice_15', 'wechat_notice_18', 'wechat_notice_limit_6', 'lng', 'lat'], 'safe'],
- [['is_show_alert', 'is_enable_save_phone', 'is_hidden_popularity', 'is_show_mall_nav', 'is_show_parent_card', 'is_show_update_division',
- 'is_allow_edit_card_info', 'is_not_forced_login', 'is_show_create_btn', 'is_show_networking', 'collect_wechat', 'collect_info', 'is_required'], 'integer']
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- //处理标签数据
-
- try {
- $data = ['basic' => [
- 'video_url'=> $params['video_url'],
- 'video_cover_pic'=> $params['video_cover_pic'],
- 'logo' => $params['logo'],
- 'card_token' => $params['card_token'],
- 'is_card_token' => $params['is_card_token'],
- 'list_card_show' => !empty($params['list_card_show']) ? json_encode($params['list_card_show'], JSON_UNESCAPED_UNICODE)
- : json_encode([]),
- 'style' => empty($params['style']) ? 0 : $params['style'],
- 'address' => $params['address'],
- 'company' => $params['company'],
- 'share_desc' => $params['share_desc'],
- 'images' => !empty($params['images']) ?
- json_encode($params['images'], JSON_UNESCAPED_UNICODE) : json_encode([]),
- 'share_title' => $params['share_title'],
- 'goods_list' => !empty($params['goods_list']) ?
- json_encode($params['goods_list'], JSON_UNESCAPED_UNICODE) : json_encode([]),
- 'wechat_notice_6' => $params['wechat_notice_6'] ?? '',
- 'wechat_notice_15' => $params['wechat_notice_15'] ?? '',
- 'wechat_notice_18' => $params['wechat_notice_18'] ?? '',
- 'wechat_notice_limit_6' => $params['wechat_notice_limit_6'] ?? 0,
- 'share_pic' => $params['share_pic'] ?? '',
- 'lat' => $params['lat'] ?? '',
- 'lng' => $params['lng'] ?? '',
- 'is_show_alert' => $params['is_show_alert'] ?? 0,
- 'is_enable_save_phone' => $params['is_enable_save_phone'] ?? 0,
- 'is_hidden_popularity' => $params['is_hidden_popularity'] ?? 0,
- 'is_show_mall_nav' => $params['is_show_mall_nav'] ?? 0,
- 'is_show_parent_card' => $params['is_show_parent_card'] ?? 0,
- 'is_show_update_division' => $params['is_show_update_division'] ?? 0,
- 'company_name_show_label' => $params['company_name_show_label'] ?? '',
- 'company_address_show_label' => $params['company_address_show_label'] ?? '',
- 'department_show_label' => $params['department_show_label'] ?? '',
- 'company_show_label' => $params['company_show_label'] ?? '',
- 'add_command_show_title' => $params['add_command_show_title'] ?? '',
- 'is_allow_edit_card_info' => $params['is_allow_edit_card_info'] ?? 0,
- 'is_not_forced_login' => $params['is_not_forced_login'] ?? 0,
- 'is_show_create_btn' => $params['is_show_create_btn'] ?? 0,
- 'is_show_networking' => $params['is_show_networking'] ?? 0,
- 'collect_wechat' => $params['collect_wechat'] ?? 0,
- 'collect_info' => $params['collect_info'] ?? 0,
- 'is_required' => $params['is_required'] ?? 2,
- 'networking_name' => $params['networking_name'] ?? '',
- 'expert_name' => $params['expert_name'] ?? '',
- 'square_name' => $params['square_name'] ?? '',
- 'networking_notice' => $params['networking_notice'] ?? '',
- 'first_img' => !empty($params['first_img']) ?
- json_encode($params['first_img'], JSON_UNESCAPED_UNICODE) : json_encode([]),
- 'second_img' => !empty($params['second_img']) ?
- json_encode($params['second_img'], JSON_UNESCAPED_UNICODE) : json_encode([]),
- 'level' => !empty($params['level']) ?
- json_encode($params['level'], JSON_UNESCAPED_UNICODE) : json_encode([]),
- 'sign' => $params['sign'] ?? '',
- ]];
- $res = Yii::$app->services->setting->addons->set($this->mall_id, CardEnums::ADDONS_NAME, $data);
- // 每次修改更新员工图文
- if (empty($data['basic']['is_allow_edit_card_info'])) {
- Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE,
- ['mall_id' => $this->mall_id], Statistics::class, 'updateCardInfo');
- }
- $tag_res = (new TagService(['mall_id' => $this->mall_id]))->setTagData($params);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success('操作成功', $data);
- } else {
- $res = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- $res['images'] = !empty($res['images']) ? json_decode($res['images'], true) : [];
- $res['goods_list'] = !empty($res['goods_list']) ? json_decode($res['goods_list'], true) : [];
- $res['list_card_show'] = !empty($res['list_card_show']) ? json_decode($res['list_card_show'], true) : [];
- $res['is_not_forced_login'] = $res['is_not_forced_login'] ?? 0;
- $res['is_show_create_btn'] = $res['is_show_create_btn'] ?? 0;
- $res['is_show_networking'] = $res['is_show_networking'] ?? 0;
- $res['collect_wechat'] = $res['collect_wechat'] ?? 0;
- $res['collect_info'] = $res['collect_info'] ?? 0;
- $res['is_required'] = $res['is_required'] ?? 2;
- $res['first_img'] = !empty($res['first_img']) ? json_decode($res['first_img'], true) : [];
- $res['second_img'] = !empty($res['second_img']) ? json_decode($res['second_img'], true) : [];
- $res['level'] = !empty($res['level']) ? json_decode($res['level'], true) : [];
- $res['identity_tags'] = [];
- $res['industry'] = [];
- $res['education'] = [];
- $res['need_resources'] = [];
- $res['supply_resources'] = [];
- //获取标签数据
- $tag_data = BusinessCardTag::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]
- ],
- 'order' => 'id asc',
- ]);
- if (!empty($tag_data)) {
- foreach ($tag_data as $key => $value) {
- switch ($value['type']) {
- case 1:
- $res['supply_resources'][] = $value;
- break;
- case 2:
- $res['need_resources'][] = $value;
- break;
- case 3:
- $res['education'][] = $value;
- break;
- case 4:
- $res['industry'][] = $value;
- break;
- case 5:
- $res['identity_tags'][] = $value;
- break;
- }
- }
- }
-
- $levels = UserLevel::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]
- ],
- 'select' => 'id,name,level'
- ]);
- $res['levels'] = $levels;
- return $this->success('操作成功', $res);
- }
- }
- return $this->render('index');
- }
- /**
- * 标签设置
- *
- * @author hpei
- * @return array|mixed
- */
- public function actionTag() {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $tagList = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic.tag');
- if (!empty($tagList)) $tagList = json_decode($tagList, true);
- return $this->success('操作成功', $tagList);
- } else {
- $tags = Yii::$app->request->post('tags', '');
- if (empty($tags)) return $this->error('标签不能为空');
- try {
- $data = ['basic' => ['tag' => json_encode($tags, JSON_UNESCAPED_UNICODE)]];
- Yii::$app->services->setting->addons->set($this->mall_id, CardEnums::ADDONS_NAME, $data);
- return $this->success('操作成功');
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- return $this->render('tag');
- }
- /**
- * 海报设置
- *
- * @author hpei
- * @return array|mixed
- */
- public function actionPoster() {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $res = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
- $data['content'] = json_decode($res['content']);
- return $this->success('操作成功',$data);
- } else {
- $params = Yii::$app->request->post();
- try {
- $data['content'] = json_encode($params['content']);
- $config = Yii::$app->services->setting->addons->set($this->mall_id, CardEnums::ADDONS_NAME, ['basic' => $data]);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- return $this->success('操作成功');
- }
- }
- return $this->render('poster');
- }
- public function actionDelTag()
- {
- $request = Yii::$app->request;
- try {
- if ($request->isAjax && $request->isPost) {
- $post = $request->post();
- $res = Yii::$app->services->validate->validate($post, [
- [['id', 'type'], 'integer'],
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $res = (new TagService(['mall_id' => $this->mall_id]))->del_tag($post);
- return $this->success('操作成功');
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
|