SettingController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. namespace addons\BusinessCard\backend\controllers;
  3. use addons\BusinessCard\common\enums\CardEnums;
  4. use addons\BusinessCard\common\models\BusinessCardTag;
  5. use addons\BusinessCard\common\logic\Statistics;
  6. use addons\BusinessCard\common\services\TagService;
  7. use common\enums\RabbitMqEnum;
  8. use common\enums\StatusEnum;
  9. use common\models\user\UserLevel;
  10. use Exception;
  11. use Yii;
  12. class SettingController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. /**
  16. * 基础配置
  17. *
  18. * @author hpi
  19. * @return array|mixed
  20. */
  21. public function actionIndex() {
  22. if (Yii::$app->request->isAjax) {
  23. if (Yii::$app->request->isPost) {
  24. $params = Yii::$app->request->post();
  25. $res = Yii::$app->services->validate->validate($params, [
  26. [[ 'share_title', 'share_desc', 'networking_name', 'expert_name', 'square_name', 'networking_notice', 'sign'], 'safe'],
  27. [['goods_list','address', 'company', 'images', 'logo', 'card_token',
  28. 'style', 'list_card_show', 'video_url', 'video_cover_pic', 'share_pic', 'is_card_token', 'company_name_show_label',
  29. 'company_address_show_label', 'department_show_label', 'company_show_label', 'first_img', 'second_img', 'level', 'identity_tags', 'industry',
  30. 'education' , 'need_resources', 'supply_resources', 'add_command_show_title'], 'safe'],
  31. [['wechat_notice_6', 'wechat_notice_15', 'wechat_notice_18', 'wechat_notice_limit_6', 'lng', 'lat'], 'safe'],
  32. [['is_show_alert', 'is_enable_save_phone', 'is_hidden_popularity', 'is_show_mall_nav', 'is_show_parent_card', 'is_show_update_division',
  33. 'is_allow_edit_card_info', 'is_not_forced_login', 'is_show_create_btn', 'is_show_networking', 'collect_wechat', 'collect_info', 'is_required'], 'integer']
  34. ]);
  35. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  36. //处理标签数据
  37. try {
  38. $data = ['basic' => [
  39. 'video_url'=> $params['video_url'],
  40. 'video_cover_pic'=> $params['video_cover_pic'],
  41. 'logo' => $params['logo'],
  42. 'card_token' => $params['card_token'],
  43. 'is_card_token' => $params['is_card_token'],
  44. 'list_card_show' => !empty($params['list_card_show']) ? json_encode($params['list_card_show'], JSON_UNESCAPED_UNICODE)
  45. : json_encode([]),
  46. 'style' => empty($params['style']) ? 0 : $params['style'],
  47. 'address' => $params['address'],
  48. 'company' => $params['company'],
  49. 'share_desc' => $params['share_desc'],
  50. 'images' => !empty($params['images']) ?
  51. json_encode($params['images'], JSON_UNESCAPED_UNICODE) : json_encode([]),
  52. 'share_title' => $params['share_title'],
  53. 'goods_list' => !empty($params['goods_list']) ?
  54. json_encode($params['goods_list'], JSON_UNESCAPED_UNICODE) : json_encode([]),
  55. 'wechat_notice_6' => $params['wechat_notice_6'] ?? '',
  56. 'wechat_notice_15' => $params['wechat_notice_15'] ?? '',
  57. 'wechat_notice_18' => $params['wechat_notice_18'] ?? '',
  58. 'wechat_notice_limit_6' => $params['wechat_notice_limit_6'] ?? 0,
  59. 'share_pic' => $params['share_pic'] ?? '',
  60. 'lat' => $params['lat'] ?? '',
  61. 'lng' => $params['lng'] ?? '',
  62. 'is_show_alert' => $params['is_show_alert'] ?? 0,
  63. 'is_enable_save_phone' => $params['is_enable_save_phone'] ?? 0,
  64. 'is_hidden_popularity' => $params['is_hidden_popularity'] ?? 0,
  65. 'is_show_mall_nav' => $params['is_show_mall_nav'] ?? 0,
  66. 'is_show_parent_card' => $params['is_show_parent_card'] ?? 0,
  67. 'is_show_update_division' => $params['is_show_update_division'] ?? 0,
  68. 'company_name_show_label' => $params['company_name_show_label'] ?? '',
  69. 'company_address_show_label' => $params['company_address_show_label'] ?? '',
  70. 'department_show_label' => $params['department_show_label'] ?? '',
  71. 'company_show_label' => $params['company_show_label'] ?? '',
  72. 'add_command_show_title' => $params['add_command_show_title'] ?? '',
  73. 'is_allow_edit_card_info' => $params['is_allow_edit_card_info'] ?? 0,
  74. 'is_not_forced_login' => $params['is_not_forced_login'] ?? 0,
  75. 'is_show_create_btn' => $params['is_show_create_btn'] ?? 0,
  76. 'is_show_networking' => $params['is_show_networking'] ?? 0,
  77. 'collect_wechat' => $params['collect_wechat'] ?? 0,
  78. 'collect_info' => $params['collect_info'] ?? 0,
  79. 'is_required' => $params['is_required'] ?? 2,
  80. 'networking_name' => $params['networking_name'] ?? '',
  81. 'expert_name' => $params['expert_name'] ?? '',
  82. 'square_name' => $params['square_name'] ?? '',
  83. 'networking_notice' => $params['networking_notice'] ?? '',
  84. 'first_img' => !empty($params['first_img']) ?
  85. json_encode($params['first_img'], JSON_UNESCAPED_UNICODE) : json_encode([]),
  86. 'second_img' => !empty($params['second_img']) ?
  87. json_encode($params['second_img'], JSON_UNESCAPED_UNICODE) : json_encode([]),
  88. 'level' => !empty($params['level']) ?
  89. json_encode($params['level'], JSON_UNESCAPED_UNICODE) : json_encode([]),
  90. 'sign' => $params['sign'] ?? '',
  91. ]];
  92. $res = Yii::$app->services->setting->addons->set($this->mall_id, CardEnums::ADDONS_NAME, $data);
  93. // 每次修改更新员工图文
  94. if (empty($data['basic']['is_allow_edit_card_info'])) {
  95. Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE,
  96. ['mall_id' => $this->mall_id], Statistics::class, 'updateCardInfo');
  97. }
  98. $tag_res = (new TagService(['mall_id' => $this->mall_id]))->setTagData($params);
  99. } catch (\Exception $e) {
  100. return $this->error($e->getMessage());
  101. }
  102. return $this->success('操作成功', $data);
  103. } else {
  104. $res = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
  105. $res['images'] = !empty($res['images']) ? json_decode($res['images'], true) : [];
  106. $res['goods_list'] = !empty($res['goods_list']) ? json_decode($res['goods_list'], true) : [];
  107. $res['list_card_show'] = !empty($res['list_card_show']) ? json_decode($res['list_card_show'], true) : [];
  108. $res['is_not_forced_login'] = $res['is_not_forced_login'] ?? 0;
  109. $res['is_show_create_btn'] = $res['is_show_create_btn'] ?? 0;
  110. $res['is_show_networking'] = $res['is_show_networking'] ?? 0;
  111. $res['collect_wechat'] = $res['collect_wechat'] ?? 0;
  112. $res['collect_info'] = $res['collect_info'] ?? 0;
  113. $res['is_required'] = $res['is_required'] ?? 2;
  114. $res['first_img'] = !empty($res['first_img']) ? json_decode($res['first_img'], true) : [];
  115. $res['second_img'] = !empty($res['second_img']) ? json_decode($res['second_img'], true) : [];
  116. $res['level'] = !empty($res['level']) ? json_decode($res['level'], true) : [];
  117. $res['identity_tags'] = [];
  118. $res['industry'] = [];
  119. $res['education'] = [];
  120. $res['need_resources'] = [];
  121. $res['supply_resources'] = [];
  122. //获取标签数据
  123. $tag_data = BusinessCardTag::lists([
  124. 'where' => [
  125. ['mall_id' => $this->mall_id],
  126. ['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]]
  127. ],
  128. 'order' => 'id asc',
  129. ]);
  130. if (!empty($tag_data)) {
  131. foreach ($tag_data as $key => $value) {
  132. switch ($value['type']) {
  133. case 1:
  134. $res['supply_resources'][] = $value;
  135. break;
  136. case 2:
  137. $res['need_resources'][] = $value;
  138. break;
  139. case 3:
  140. $res['education'][] = $value;
  141. break;
  142. case 4:
  143. $res['industry'][] = $value;
  144. break;
  145. case 5:
  146. $res['identity_tags'][] = $value;
  147. break;
  148. }
  149. }
  150. }
  151. $levels = UserLevel::lists([
  152. 'where' => [
  153. ['mall_id' => $this->mall_id],
  154. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]
  155. ],
  156. 'select' => 'id,name,level'
  157. ]);
  158. $res['levels'] = $levels;
  159. return $this->success('操作成功', $res);
  160. }
  161. }
  162. return $this->render('index');
  163. }
  164. /**
  165. * 标签设置
  166. *
  167. * @author hpei
  168. * @return array|mixed
  169. */
  170. public function actionTag() {
  171. if (Yii::$app->request->isAjax) {
  172. if (Yii::$app->request->isGet) {
  173. $tagList = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic.tag');
  174. if (!empty($tagList)) $tagList = json_decode($tagList, true);
  175. return $this->success('操作成功', $tagList);
  176. } else {
  177. $tags = Yii::$app->request->post('tags', '');
  178. if (empty($tags)) return $this->error('标签不能为空');
  179. try {
  180. $data = ['basic' => ['tag' => json_encode($tags, JSON_UNESCAPED_UNICODE)]];
  181. Yii::$app->services->setting->addons->set($this->mall_id, CardEnums::ADDONS_NAME, $data);
  182. return $this->success('操作成功');
  183. } catch (\Exception $e) {
  184. return $this->error($e->getMessage());
  185. }
  186. }
  187. }
  188. return $this->render('tag');
  189. }
  190. /**
  191. * 海报设置
  192. *
  193. * @author hpei
  194. * @return array|mixed
  195. */
  196. public function actionPoster() {
  197. if (Yii::$app->request->isAjax) {
  198. if (Yii::$app->request->isGet) {
  199. $res = Yii::$app->services->setting->addons->get($this->mall_id, CardEnums::ADDONS_NAME, 'basic');
  200. $data['content'] = json_decode($res['content']);
  201. return $this->success('操作成功',$data);
  202. } else {
  203. $params = Yii::$app->request->post();
  204. try {
  205. $data['content'] = json_encode($params['content']);
  206. $config = Yii::$app->services->setting->addons->set($this->mall_id, CardEnums::ADDONS_NAME, ['basic' => $data]);
  207. } catch (\Exception $e) {
  208. return $this->error($e->getMessage());
  209. }
  210. return $this->success('操作成功');
  211. }
  212. }
  213. return $this->render('poster');
  214. }
  215. public function actionDelTag()
  216. {
  217. $request = Yii::$app->request;
  218. try {
  219. if ($request->isAjax && $request->isPost) {
  220. $post = $request->post();
  221. $res = Yii::$app->services->validate->validate($post, [
  222. [['id', 'type'], 'integer'],
  223. ]);
  224. if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
  225. $res = (new TagService(['mall_id' => $this->mall_id]))->del_tag($post);
  226. return $this->success('操作成功');
  227. }
  228. } catch (\Exception $e) {
  229. return $this->error($e->getMessage());
  230. }
  231. }
  232. }