123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 客户模块设置
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\crm\controller;
  8. use app\admin\controller\ApiCommon;
  9. use app\admin\model\Message;
  10. use think\Hook;
  11. use think\Request;
  12. use think\Db;
  13. class Setting extends ApiCommon
  14. {
  15. /**
  16. * 用于判断权限
  17. * @permission 无限制
  18. * @allow 登录用户可访问
  19. * @other 其他根据系统设置
  20. **/
  21. public function _initialize()
  22. {
  23. $action = [
  24. 'permission' => [''],
  25. 'allow' => [
  26. 'config', 'configdata', 'team', 'teamsave', 'contractday', 'recordlist', 'recordedit', 'customerconfiglist',
  27. 'customerconfigsave', 'customerconfigupdate', 'customerconfigdelete', 'numberSequenceAdd', 'quitteam',
  28. 'setvisitday', 'getvisitday', 'setnumber', 'customerconfigdel', 'numbersequencelist',
  29. ]
  30. ];
  31. Hook::listen('check_auth', $action);
  32. $request = Request::instance();
  33. $a = strtolower($request->action());
  34. if (!in_array($a, $action['permission'])) {
  35. parent::_initialize();
  36. }
  37. }
  38. /**
  39. * 客户相关配置
  40. *
  41. * @return \think\response\Json
  42. */
  43. public function config()
  44. {
  45. //权限判断
  46. if (!checkPerByAction('admin', 'crm', 'pool')) {
  47. header('Content-Type:application/json; charset=utf-8');
  48. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  49. }
  50. $configModel = model('ConfigData');
  51. $param = $this->param;
  52. if ((int)$param['follow_day'] > (int)$param['deal_day']) {
  53. return resultArray(['error' => '成交设置时长不能大于跟进设置时长']);
  54. }
  55. $res = $configModel->createData($param);
  56. if ($res) {
  57. return resultArray(['data' => '设置成功']);
  58. } else {
  59. return resultArray(['error' => $configModel->getError()]);
  60. }
  61. }
  62. /**
  63. * 客户相关配置(详情)
  64. *
  65. * @return \think\response\Json
  66. */
  67. public function configData()
  68. {
  69. $configModel = model('ConfigData');
  70. $data = $configModel->getData();
  71. return resultArray(['data' => $data]);
  72. }
  73. /**
  74. * 相关团队列表
  75. *
  76. * @return \think\response\Json
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. * @throws \think\exception\DbException
  80. */
  81. public function team()
  82. {
  83. $param = $this->param;
  84. $userModel = new \app\admin\model\User();
  85. if (!$param['types'] || !$param['types_id']) {
  86. return resultArray(['error' => '参数错误']);
  87. }
  88. switch ($param['types']) {
  89. case 'crm_leads' :
  90. $dataModel = new \app\crm\model\Leads();
  91. break;
  92. case 'crm_customer' :
  93. $dataModel = new \app\crm\model\Customer();
  94. break;
  95. case 'crm_contacts' :
  96. $dataModel = new \app\crm\model\Contacts();
  97. break;
  98. case 'crm_business' :
  99. $dataModel = new \app\crm\model\Business();
  100. break;
  101. case 'crm_contract' :
  102. $dataModel = new \app\crm\model\Contract();
  103. break;
  104. case 'crm_receivables' :
  105. $dataModel = new \app\crm\model\Receivables();
  106. break;
  107. }
  108. $resData = $dataModel->getDataById($param['types_id']);
  109. $ro_user_ids = $resData['ro_user_id'] ? array_filter(explode(',', $resData['ro_user_id'])) : []; //只读权限
  110. $rw_user_ids = $resData['rw_user_id'] ? array_filter(explode(',', $resData['rw_user_id'])) : []; //读写权限
  111. $ro_user_arr = [];
  112. $rw_user_arr = [];
  113. $owner_user_arr = ['1' => ['user_id' => $resData['owner_user_id'], 'type' => 0, 'group_name' => '负责人', 'authority' => '负责人权限']]; //负责人
  114. //转换为二维数组
  115. foreach ($ro_user_ids as $k => $v) {
  116. $ro_user_arr[$k]['user_id'] = $v;
  117. $ro_user_arr[$k]['type'] = 1;
  118. $ro_user_arr[$k]['group_name'] = '普通成员';
  119. $ro_user_arr[$k]['authority'] = '只读';
  120. }
  121. foreach ($rw_user_ids as $k => $v) {
  122. $rw_user_arr[$k]['user_id'] = $v;
  123. $rw_user_arr[$k]['type'] = 2;
  124. $rw_user_arr[$k]['group_name'] = '普通成员';
  125. $rw_user_arr[$k]['authority'] = '读写';
  126. }
  127. $user_list = array_merge($owner_user_arr, $rw_user_arr, $ro_user_arr);
  128. $new_user_list = [];
  129. $types_data = ['crm_leads' => 6, 'crm_customer' => 1, 'crm_contacts' => 2, 'crm_business' => 3, 'crm_contract' => 4, 'crm_receivables' => 5];
  130. foreach ($user_list as $k => $v) {
  131. if ($v['user_id']) {
  132. $userInfo = [];
  133. $userInfo = $userModel->getUserById($v['user_id']) ?: [];
  134. $userInfo['group_name'] = $v['group_name'];
  135. $userInfo['authority'] = $v['authority'];
  136. $userInfo['type'] = $v['type'];
  137. $userInfo['target_time'] = db('crm_team')->where(['team_user_id' => ['in', $v], 'target_id' => $param['types_id'], 'types' => $types_data[$param['types']]])->value('target_time') ? date('Y-m-d', db('crm_team')->where(['team_user_id' => ['in', $v], 'target_id' => $param['types_id'], 'types' => $types_data[$param['types']]])->value('target_time')) : '无限';
  138. $new_user_list[] = $userInfo;
  139. }
  140. }
  141. return resultArray(['data' => $new_user_list]);
  142. }
  143. /**
  144. * 退出团队
  145. *
  146. * @return \think\response\Json
  147. * @throws \think\Exception
  148. * @throws \think\db\exception\DataNotFoundException
  149. * @throws \think\db\exception\ModelNotFoundException
  150. * @throws \think\exception\DbException
  151. * @throws \think\exception\PDOException
  152. */
  153. public function quitTeam()
  154. {
  155. if (empty($this->param['types']) || empty($this->param['types_id'])) return resultArray(['error' => '参数错误']);
  156. if (!in_array($this->param['types'], ['crm_customer', 'crm_contacts', 'crm_business', 'crm_contract'])) {
  157. return resultArray(['error' => '参数错误']);
  158. }
  159. $userId = $this->userInfo['id'];
  160. $primaryKey = ['crm_customer' => 'customer_id', 'crm_contacts' => 'contacts_id', 'crm_business' => 'business_id', 'crm_contract' => 'contract_id'];
  161. $data = Db::name($this->param['types'])->field([$primaryKey[$this->param['types']], 'ro_user_id', 'rw_user_id', 'owner_user_id,name'])
  162. ->where($primaryKey[$this->param['types']], $this->param['types_id'])->find();
  163. if ($data['owner_user_id'] == $userId) return resultArray(['error' => '负责人不能退出团队!']);
  164. $data[$primaryKey[$this->param['types']]] = $this->param['types_id'];
  165. $data['ro_user_id'] = str_replace(',' . $userId, '', $data['ro_user_id']);
  166. $data['rw_user_id'] = str_replace(',' . $userId, '', $data['rw_user_id']);
  167. if (!Db::name($this->param['types'])->update($data)) {
  168. return resultArray(['error' => '操作失败!']);
  169. }
  170. $type = '';
  171. switch ($this->param['types']) {
  172. case 'crm_customer':
  173. $type = Message::CUSTOMER_PASS;
  174. break;
  175. case 'crm_business':
  176. $type = Message::BUSINESS_PASS;
  177. break;
  178. case 'crm_contract':
  179. $type = Message::CONTRACT_END;
  180. break;
  181. }
  182. //站内信
  183. $send_user_id = stringToArray($userId);
  184. if ($send_user_id && empty($param['check_status'])) {
  185. (new Message())->send(
  186. $type,
  187. [
  188. 'title' => $data['name'],
  189. 'action_id' => $this->param['types_id']
  190. ],
  191. $send_user_id
  192. );
  193. }
  194. return resultArray(['data' => '操作成功!']);
  195. }
  196. /**
  197. * 相关团队创建
  198. *
  199. * @return \think\response\Json
  200. * @throws \think\db\exception\DataNotFoundException
  201. * @throws \think\db\exception\ModelNotFoundException
  202. * @throws \think\exception\DbException
  203. */
  204. public function teamSave()
  205. {
  206. $param = $this->param;
  207. $userInfo = $this->userInfo;
  208. $settingModel = model('Setting');
  209. $userModel = new \app\admin\model\User();
  210. $types_id = $param['types_id'];
  211. if (!$param['types'] || !$types_id) {
  212. return resultArray(['error' => '参数错误']);
  213. }
  214. if (!$param['user_id']) {
  215. return resultArray(['error' => '请先选择协作人']);
  216. }
  217. $errorMessage = [];
  218. foreach ($types_id as $k => $v) {
  219. $error = false;
  220. $typesName = '';
  221. //权限判断
  222. switch ($param['types']) {
  223. case 'crm_customer' :
  224. $typesName = '客户';
  225. $customerModel = new \app\crm\model\Customer();
  226. $dataInfo = db('crm_customer')->where(['customer_id' => $v])->find();
  227. //判断权限
  228. $auth_user_ids = $userModel->getUserByPer('crm', 'customer', 'teamSave');
  229. //判断是否客户池数据
  230. $wherePool = $customerModel->getWhereByPool();
  231. $resPool = db('crm_customer')->alias('customer')->where(['customer.customer_id' => $v])->where($wherePool)->find();
  232. if (!$resPool && !in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
  233. $error = true;
  234. $errorMessage = "客户'" . $dataInfo['name'] . "'操作失败,错误原因:无权操作";
  235. }
  236. if (in_array($dataInfo['owner_user_id'], $param['user_id'])) {
  237. $error = true;
  238. $errorMessage = "客户'" . $dataInfo['name'] . "'操作失败,错误原因:不能对负责人进行添加或移出操作!";
  239. }
  240. $message_type = Message::TEAM_CUSTOMER;
  241. continue;
  242. case 'crm_business' :
  243. $typesName = '商机';
  244. $businessModel = new \app\crm\model\Business();
  245. $dataInfo = db('crm_business')->where(['business_id' => $v])->find();
  246. //判断权限
  247. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'teamSave');
  248. if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
  249. $error = true;
  250. $errorMessage = "商机'" . $dataInfo['name'] . "'操作失败,错误原因:无权操作";
  251. }
  252. if (in_array($dataInfo['owner_user_id'], $param['user_id'])) {
  253. $error = true;
  254. $errorMessage = "商机'" . $dataInfo['name'] . "'操作失败,错误原因:不能对负责人进行添加或移出操作!";
  255. }
  256. $message_type = Message::TEAM_BUSINESS;
  257. continue;
  258. case 'crm_contract' :
  259. $typesName = '合同';
  260. $contractModel = new \app\crm\model\Contract();
  261. $dataInfo = db('crm_contract')->where(['contract_id' => $v])->find();
  262. //判断权限
  263. $auth_user_ids = $userModel->getUserByPer('crm', 'contract', 'teamSave');
  264. if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
  265. $error = true;
  266. $errorMessage = "合同'" . $dataInfo['name'] . "'操作失败,错误原因:无权操作";
  267. }
  268. if (in_array($dataInfo['owner_user_id'], $param['user_id'])) {
  269. $error = true;
  270. $errorMessage = "合同'" . $dataInfo['name'] . "'操作失败,错误原因:不能对负责人进行添加或移出操作!";
  271. }
  272. $message_type = Message::TEAM_CONTRACT;
  273. continue;
  274. case 'crm_leads' :
  275. $typesName = '线索';
  276. $leadsModel = new \app\crm\model\Leads();
  277. $dataInfo = db('crm_leads')->where(['leads_id' => $v])->find();
  278. //判断权限
  279. $auth_user_ids = $userModel->getUserByPer('crm', 'leads', 'teamSave');
  280. if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
  281. $error = true;
  282. $errorMessage = "线索'" . $dataInfo['name'] . "'操作失败,错误原因:无权操作";
  283. }
  284. if (in_array($dataInfo['owner_user_id'], $param['user_id'])) {
  285. $error = true;
  286. $errorMessage = "线索'" . $dataInfo['name'] . "'操作失败,错误原因:不能对负责人进行添加或移出操作!";
  287. }
  288. $message_type = Message::TEAM_CONTRACT;
  289. continue;
  290. case 'crm_receivables' :
  291. $typesName = '回款';
  292. $receivablesModel = new \app\crm\model\Receivables();
  293. $dataInfo = db('crm_receivables')->where(['receivables_id' => $v])->find();
  294. //判断权限
  295. $auth_user_ids = $userModel->getUserByPer('crm', 'receivables', 'teamSave');
  296. if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
  297. $error = true;
  298. $errorMessage = "回款'" . $dataInfo['name'] . "'操作失败,错误原因:无权操作";
  299. }
  300. if (in_array($dataInfo['owner_user_id'], $param['user_id'])) {
  301. $error = true;
  302. $errorMessage = "回款'" . $dataInfo['name'] . "'操作失败,错误原因:不能对负责人进行添加或移出操作!";
  303. }
  304. $message_type = Message::TEAM_CONTRACT;
  305. continue;
  306. case 'crm_contacts' :
  307. $typesName = '联系人';
  308. $leadsModel = new \app\crm\model\Leads();
  309. $dataInfo = db('crm_contacts')->where(['contacts_id' => $v])->find();
  310. //判断权限
  311. $auth_user_ids = $userModel->getUserByPer('crm', 'contacts', 'teamSave');
  312. if (!in_array($dataInfo['owner_user_id'], $auth_user_ids)) {
  313. $error = true;
  314. $errorMessage = "联系人'" . $dataInfo['name'] . "'操作失败,错误原因:无权操作";
  315. }
  316. if (in_array($dataInfo['owner_user_id'], $param['user_id'])) {
  317. $error = true;
  318. $errorMessage = "联系人'" . $dataInfo['name'] . "'操作失败,错误原因:不能对负责人进行添加或移出操作!";
  319. }
  320. $message_type = Message::TEAM_CONTRACT;
  321. continue;
  322. }
  323. if ($error !== true) {
  324. $param['type_id'] = $v;
  325. $param['type'] = $param['type'] ?: 1;
  326. $param['is_del'] = $param['is_del'] ?: 3;
  327. $param['owner_user_id'] = $userInfo['id'];
  328. $param['target_time'] = strtotime($param['target_time']);
  329. if ($param['is_del'] == 3) {
  330. $res = $settingModel->createTeamData($param);
  331. if (!$res) {
  332. $errorMessage = $typesName . $dataInfo['name'] . "'操作失败,错误原因:修改失败";
  333. } else {
  334. (new Message())->send(
  335. $message_type,
  336. [
  337. 'title' => $dataInfo['name'],
  338. 'action_id' => $v
  339. ],
  340. $param['user_id']
  341. );
  342. $username = db('admin_user')->where('id', ['in', $param['user_id']])->column('realname');
  343. RecordActionLog($userInfo['id'], $param['types'], 'teamSave', $dataInfo['name'], '', '', '给' . $typesName . $dataInfo['name'] . '添加了团队成员 :' . implode(',', $username));
  344. updateActionLog($userInfo['id'], $param['types'], $v, '', '', $typesName . $dataInfo['name'] . '添加了团队成员' . implode(',', $username));
  345. }
  346. } else {
  347. $res = $settingModel->createTeamData($param);
  348. if (!$res) {
  349. $errorMessage = $typesName . $dataInfo['name'] . "'操作失败,错误原因:修改失败";
  350. } else {
  351. (new Message())->send(
  352. Message::TEAM_END,
  353. [
  354. 'title' => $dataInfo['name'],
  355. 'action_id' => $v
  356. ],
  357. $param['user_id']
  358. );
  359. }
  360. $username = db('admin_user')->where('id', ['in', $param['user_id']])->column('realname');
  361. RecordActionLog($userInfo['id'], $param['types'], 'teamSave', $dataInfo['name'], '', '', '移除了' . $typesName . $dataInfo['name'] . '团队成员 :' . implode(',', $username));
  362. updateActionLog($userInfo['id'], $param['types'], $v, '', '', $typesName . $dataInfo['name'] . '移除了团队成员' . implode(',', $username));
  363. }
  364. }
  365. }
  366. if ($errorMessage) {
  367. return resultArray(['error' => $errorMessage]);
  368. } else {
  369. return resultArray(['data' => '保存成功']);
  370. }
  371. }
  372. /**
  373. * 合同到期提醒天数
  374. *
  375. * @return \think\response\Json
  376. * @throws \think\Exception
  377. * @throws \think\exception\PDOException
  378. */
  379. public function contractDay()
  380. {
  381. //权限判断
  382. if (!checkPerByAction('admin', 'crm', 'setting')) {
  383. header('Content-Type:application/json; charset=utf-8');
  384. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  385. }
  386. $param = $this->param;
  387. $userInfo = $this->userInfo;
  388. $data = [];
  389. $contract_day = $param['contract_day'] ? intval($param['contract_day']) : 0;
  390. $contract_config = $param['contract_config'] ? intval($param['contract_config']) : 0;
  391. $res = db('crm_config')->where(['name' => 'contract_config'])->update(['value' => $contract_config]);
  392. if ($contract_day && $contract_config == 1) $res = db('crm_config')->where(['name' => 'contract_day'])->update(['value' => $contract_day]);
  393. # 系统操作日志
  394. SystemActionLog($userInfo['id'], 'crm_config', 'customer', 1, 'update', '', '', '', '编辑了合同到期提醒设置');
  395. return resultArray(['data' => '设置成功']);
  396. }
  397. /**
  398. * 记录类型编辑
  399. *
  400. * @return \think\response\Json
  401. * @throws \think\Exception
  402. * @throws \think\db\exception\DataNotFoundException
  403. * @throws \think\db\exception\ModelNotFoundException
  404. * @throws \think\exception\DbException
  405. * @throws \think\exception\PDOException
  406. */
  407. public function recordEdit()
  408. {
  409. $param = $this->param;
  410. $userInfo = $this->userInfo;
  411. //权限判断
  412. if (!checkPerByAction('admin', 'crm', 'setting')) {
  413. header('Content-Type:application/json; charset=utf-8');
  414. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  415. }
  416. if ($param['value']) {
  417. $array = json_encode($param['value']);
  418. $record_type = db('crm_config')->where(['name' => 'record_type'])->find();
  419. if ($record_type) {
  420. $res = db('crm_config')->where(['name' => 'record_type'])->update(['value' => $array]);
  421. $id = $record_type['id'];
  422. } else {
  423. $data = array();
  424. $data['name'] = 'record_type';
  425. $data['value'] = $array;
  426. $data['description'] = '跟进记录类型';
  427. $res = db('crm_config')->insertGetId($data);
  428. $id = $res;
  429. $record_type['description'] = '跟进记录类型';
  430. }
  431. if ($res) {
  432. SystemActionLog($userInfo['id'], 'crm_config', 'customer', $id, 'update', $record_type['description'], '', '', '编辑了跟进记录类型:' . $record_type['description']);
  433. return resultArray(['data' => '设置成功']);
  434. } else {
  435. return resultArray(['error' => '设置失败,请重试!']);
  436. }
  437. } else {
  438. $record_type = db('crm_config')->where(['name' => 'record_type'])->find();
  439. $record_type['value'] = json_decode($record_type['value']);
  440. return resultArray(['data' => $record_type]);
  441. }
  442. }
  443. /**
  444. * 跟进记录 记录方式展示
  445. *
  446. * @return \think\response\Json
  447. * @throws \think\db\exception\DataNotFoundException
  448. * @throws \think\db\exception\ModelNotFoundException
  449. * @throws \think\exception\DbException
  450. */
  451. public function recordList()
  452. {
  453. $record_type = db('crm_config')->where(['name' => 'record_type'])->find();
  454. if ($record_type) {
  455. $arr = json_decode($record_type['value']);
  456. return resultArray(['data' => $arr]);
  457. } else {
  458. return resultArray(['data' => array()]);
  459. }
  460. }
  461. /**
  462. * 拥有、锁定客户数限制列表
  463. *
  464. * @return \think\response\Json
  465. * @throws \think\Exception
  466. * @throws \think\db\exception\DataNotFoundException
  467. * @throws \think\db\exception\ModelNotFoundException
  468. * @throws \think\exception\DbException
  469. */
  470. public function customerConfigList()
  471. {
  472. $param = $this->param;
  473. $param['types'] = $param['types'] ?: 1;
  474. $customerConfigModel = new \app\crm\model\CustomerConfig();
  475. $data = $customerConfigModel->getDataList($param);
  476. return resultArray(['data' => $data]);
  477. }
  478. /**
  479. * 拥有、锁定客户数限制 创建/编辑 todo 创建和编辑走一个接口,前端非要这么搞
  480. *
  481. * @return \think\response\Json
  482. * @throws \think\db\exception\DataNotFoundException
  483. * @throws \think\db\exception\ModelNotFoundException
  484. * @throws \think\exception\DbException
  485. */
  486. public function customerConfigSave()
  487. {
  488. //权限判断
  489. if (!checkPerByAction('admin', 'crm', 'setting')) {
  490. header('Content-Type:application/json; charset=utf-8');
  491. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  492. }
  493. $userInfo = $this->userInfo;
  494. $this->param['user_id'] = $userInfo['id'];
  495. $customerConfigModel = new \app\crm\model\CustomerConfig();
  496. if (!$customerConfigModel->createData($this->param)) {
  497. return resultArray(['error' => $customerConfigModel->getError()]);
  498. }
  499. return resultArray(['data' => empty($param['id']) ? '创建成功!' : '编辑成功!']);
  500. }
  501. /**
  502. * 拥有、锁定客户数限制 编辑 todo 编辑不走这个接口,前端非要走创建接口
  503. *
  504. * @return \think\response\Json
  505. */
  506. public function customerConfigUpdate()
  507. {
  508. //权限判断
  509. if (!checkPerByAction('admin', 'crm', 'setting')) {
  510. header('Content-Type:application/json; charset=utf-8');
  511. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  512. }
  513. $param = $this->param;
  514. $customerConfigModel = new \app\crm\model\CustomerConfig();
  515. $res = $customerConfigModel->updateDataById($param, $param['id']);
  516. if (!$res) {
  517. return resultArray(['error' => $customerConfigModel->getError()]);
  518. }
  519. return resultArray(['data' => '编辑成功']);
  520. }
  521. /**
  522. * 拥有、锁定客户数限制 删除
  523. *
  524. * @return \think\response\Json
  525. */
  526. public function customerConfigDel()
  527. {
  528. //权限判断
  529. if (!checkPerByAction('admin', 'crm', 'setting')) {
  530. header('Content-Type:application/json; charset=utf-8');
  531. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  532. }
  533. $param = $this->param;
  534. $customerConfigModel = new \app\crm\model\CustomerConfig();
  535. $res = $customerConfigModel->delDataById($param['id']);
  536. if (!$res) {
  537. return resultArray(['error' => $customerConfigModel->getError()]);
  538. }
  539. return resultArray(['data' => '删除成功']);
  540. }
  541. /**
  542. * 编号列表
  543. *
  544. * @return \think\response\Json
  545. * @throws \think\db\exception\DataNotFoundException
  546. * @throws \think\db\exception\ModelNotFoundException
  547. * @throws \think\exception\DbException
  548. */
  549. public function numberSequenceList()
  550. {
  551. $param = $this->param;
  552. $numberSequenceModel = new \app\crm\model\NumberSequence();
  553. $data = $numberSequenceModel->getDataList($param);
  554. return resultArray(['data' => $data]);
  555. }
  556. /**
  557. * 编号修改
  558. *
  559. * @return \think\response\Json
  560. */
  561. public function numberSequenceUpdate()
  562. {
  563. //权限判断
  564. if (!checkPerByAction('admin', 'crm', 'setting')) {
  565. header('Content-Type:application/json; charset=utf-8');
  566. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  567. }
  568. $param = $this->param;
  569. $numberSequenceModel = new \app\crm\model\NumberSequence();
  570. $res = $numberSequenceModel->numberSequenceUpdate($param, $param['id']);
  571. if (!$res) {
  572. return resultArray(['error' => $numberSequenceModel->getError()]);
  573. }
  574. return resultArray(['data' => '编辑成功']);
  575. }
  576. /**
  577. * 编号删除
  578. *
  579. * @return \think\response\Json
  580. */
  581. public function numberSequenceDel()
  582. {
  583. //权限判断
  584. if (!checkPerByAction('admin', 'crm', 'setting')) {
  585. header('Content-Type:application/json; charset=utf-8');
  586. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  587. }
  588. $param = $this->param;
  589. $numberSequenceModel = new \app\crm\model\NumberSequence();
  590. $res = $numberSequenceModel->delDataById($param['id']);
  591. if (!$res) {
  592. return resultArray(['error' => $numberSequenceModel->getError()]);
  593. }
  594. return resultArray(['data' => '删除成功']);
  595. }
  596. /**
  597. * 设置回访提醒
  598. *
  599. * @return \think\response\Json
  600. * @throws \think\Exception
  601. * @throws \think\exception\PDOException
  602. */
  603. public function setVisitDay()
  604. {
  605. $status = !empty($this->param['status']) ? $this->param['status'] : 0;
  606. $day = !empty($this->param['day']) ? $this->param['day'] : 0;
  607. $userInfo = $this->userInfo;
  608. $settingModel = new \app\crm\model\Setting();
  609. if (!$settingModel->setVisitDay($status, $day, $userInfo['id'])) return resultArray(['error' => '操作失败!']);
  610. return resultArray(['data' => '操作成功!']);
  611. }
  612. /**
  613. * 获取回访提醒
  614. *
  615. * @return \think\response\Json
  616. */
  617. public function getVisitDay()
  618. {
  619. $settingModel = new \app\crm\model\Setting();
  620. $data = $settingModel->getVisitDay();
  621. return resultArray(['data' => $data]);
  622. }
  623. /**
  624. * 设置自动编号
  625. *
  626. * @return \think\response\Json
  627. */
  628. public function setNumber()
  629. {
  630. if (empty($this->param) || !is_array($this->param)) return resultArray(['error' => '参数错误!']);
  631. $userInfo = $this->userInfo;
  632. $settingModel = new \app\crm\model\Setting();
  633. if ($settingModel->setNumber($this->param, $userInfo['id']) === false) return resultArray(['error' => '操作失败!']);
  634. return resultArray(['data' => '操作成功!']);
  635. }
  636. /**
  637. * 手机端导航栏显示
  638. *
  639. * @author alvin guogaobo
  640. * @version 1.0 版本号
  641. * @since 2021/6/22 0022 11:27
  642. */
  643. public function appMenuConfig(){
  644. $param=$this->userInfo['id'];
  645. $settingModel = new \app\crm\model\Setting();
  646. $data=$settingModel->appMenuConfig($param);
  647. return resultArray(['data' => $data]);
  648. }
  649. /**
  650. * 手机端办公数量
  651. *
  652. * @author alvin guogaobo
  653. * @version 1.0 版本号
  654. * @since 2021/6/22 0022 13:44
  655. */
  656. public function oaNumber(){
  657. $userInfo=$this->userInfo;
  658. # 日志
  659. $logNum=db('oa_log')->where('create_user_id',$userInfo['id'])->count();
  660. #审批
  661. $examineNum=db('oa_examine')->where('create_user_id',$userInfo['id'])->count();
  662. #任务
  663. $taskNum=db('task')->where('create_user_id',$userInfo['id'])->count();
  664. #跟进
  665. $activityNum=db('crm_activity')->where(['create_user_id'=>$userInfo['id'],'type'=>1])->count();
  666. $data=[];
  667. $data['logNum']=$logNum;
  668. $data['examineNum']=$examineNum;
  669. $data['taskNum']=$taskNum;
  670. $data['activityNu']=$activityNum;
  671. return $data;
  672. }
  673. }