Business.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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\crm\traits\SearchConditionTrait;
  10. use app\crm\traits\StarTrait;
  11. use think\Hook;
  12. use think\Request;
  13. use think\Db;
  14. class Business extends ApiCommon
  15. {
  16. use StarTrait, SearchConditionTrait;
  17. /**
  18. * 用于判断权限
  19. * @permission 无限制
  20. * @allow 登录用户可访问
  21. * @other 其他根据系统设置
  22. **/
  23. public function _initialize()
  24. {
  25. $action = [
  26. 'permission' => [''],
  27. 'allow' => ['statuslist', 'advance', 'product', 'system', 'count', 'setprimary']
  28. ];
  29. Hook::listen('check_auth', $action);
  30. $request = Request::instance();
  31. $a = strtolower($request->action());
  32. if (!in_array($a, $action['permission'])) {
  33. parent::_initialize();
  34. }
  35. }
  36. /**
  37. * 商机列表
  38. * @return
  39. * @author Michael_xu
  40. */
  41. public function index()
  42. {
  43. $businessModel = model('Business');
  44. $param = $this->param;
  45. $userInfo = $this->userInfo;
  46. $param['user_id'] = $userInfo['id'];
  47. $data = $businessModel->getDataList($param);
  48. return resultArray(['data' => $data]);
  49. }
  50. /**
  51. * 添加商机
  52. * @param
  53. * @return
  54. * @author Michael_xu
  55. */
  56. public function save()
  57. {
  58. $businessModel = model('Business');
  59. $param = $this->param;
  60. $userInfo = $this->userInfo;
  61. $param['create_user_id'] = $userInfo['id'];
  62. $param['owner_user_id'] = $userInfo['id'];
  63. if ($businessModel->createData($param)) {
  64. return resultArray(['data' => '添加成功']);
  65. } else {
  66. return resultArray(['error' => $businessModel->getError()]);
  67. }
  68. }
  69. /**
  70. * 商机详情
  71. * @param
  72. * @return
  73. * @author Michael_xu
  74. */
  75. public function read()
  76. {
  77. $businessModel = model('Business');
  78. $businessStatusModel = model('BusinessStatus');
  79. $userModel = new \app\admin\model\User();
  80. $param = $this->param;
  81. $userInfo = $this->userInfo;
  82. $data = $businessModel->getDataById($param['id'], $userInfo['id']);
  83. //判断权限
  84. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'read');
  85. //读权限
  86. $roPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'read');
  87. $rwPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'update');
  88. if (!in_array($data['owner_user_id'], $auth_user_ids) && !$rwPre && !$roPre) {
  89. $authData['dataAuth'] = (int)0;
  90. return resultArray(['data' => $authData]);
  91. }
  92. //商机状态组
  93. $data['status_list'] = $businessStatusModel->getDataById($data['type_id']);
  94. $data['lose_reason'] = Db::name('CrmBusinessLog')
  95. ->where(['business_id' => $data['business_id']])
  96. ->order(['id' => 'DESC'])
  97. ->value('remark');
  98. if (!$data) {
  99. return resultArray(['error' => $businessModel->getError()]);
  100. }
  101. return resultArray(['data' => $data]);
  102. }
  103. /**
  104. * 编辑商机
  105. * @param
  106. * @return
  107. * @author Michael_xu
  108. */
  109. public function update()
  110. {
  111. $businessModel = model('Business');
  112. $userModel = new \app\admin\model\User();
  113. $param = $this->param;
  114. $userInfo = $this->userInfo;
  115. $param['user_id'] = $userInfo['id'];
  116. //判断权限
  117. $data = $businessModel->getDataById($param['id']);
  118. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
  119. //读写权限
  120. $rwPre = $userModel->rwPre($userInfo['id'], $data['ro_user_id'], $data['rw_user_id'], 'update');
  121. if (!in_array($data['owner_user_id'], $auth_user_ids) && !$rwPre) {
  122. header('Content-Type:application/json; charset=utf-8');
  123. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  124. }
  125. if ($businessModel->updateDataById($param, $param['id'])) {
  126. return resultArray(['data' => '编辑成功']);
  127. } else {
  128. return resultArray(['error' => $businessModel->getError()]);
  129. }
  130. }
  131. /**
  132. * 删除商机(逻辑删)
  133. * @param
  134. * @return
  135. * @author Michael_xu
  136. */
  137. public function delete()
  138. {
  139. $param = $this->param;
  140. $userInfo = $this->userInfo;
  141. $businessModel = model('Business');
  142. $recordModel = new \app\admin\model\Record();
  143. $fileModel = new \app\admin\model\File();
  144. $actionRecordModel = new \app\admin\model\ActionRecord();
  145. if (!is_array($param['id'])) {
  146. $business_id[] = $param['id'];
  147. } else {
  148. $business_id = $param['id'];
  149. }
  150. $delIds = [];
  151. $errorMessage = [];
  152. //数据权限判断
  153. $userModel = new \app\admin\model\User();
  154. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'delete');
  155. foreach ($business_id as $k => $v) {
  156. $isDel = true;
  157. //数据详情
  158. $data = $businessModel->getDataById($v);
  159. if (!$data) {
  160. $isDel = false;
  161. $errorMessage[] = 'id为' . $v . '的商机删除失败,错误原因:' . $businessModel->getError();
  162. }
  163. if (!in_array($data['owner_user_id'], $auth_user_ids)) {
  164. $isDel = false;
  165. $errorMessage[] = '名称为' . $data['name'] . '的商机删除失败,错误原因:无权操作';
  166. }
  167. if ($isDel) {
  168. if (db('crm_contract')->where(['business_id' => $v, 'check_status' => ['in', '0,1,2']])->value('contract_id')) {
  169. $isDel = false;
  170. $errorMessage[] = '名称为' . $data['name'] . '的商机删除失败,错误原因:商机下关联的有合同,无法删除!';
  171. }
  172. }
  173. if ($isDel) {
  174. $delIds[] = $v;
  175. }
  176. }
  177. if ($delIds) {
  178. $data = $businessModel->delDatas($delIds);
  179. if (!$data) {
  180. return resultArray(['error' => $businessModel->getError()]);
  181. }
  182. //删除跟进记录
  183. $recordModel->delDataByTypes(5, $delIds);
  184. //删除关联附件
  185. $fileModel->delRFileByModule('crm_business', $delIds);
  186. //删除关联操作记录
  187. $actionRecordModel->delDataById(['types' => 'crm_business', 'action_id' => $delIds]);
  188. $dataInfo = $businessModel->where('business_id',['in',$delIds])->select();
  189. foreach ($dataInfo as $k => $v) {
  190. RecordActionLog($userInfo['id'], 'crm_business', 'delete', $v['name'], '', '', '删除了商机:' . $v['name']);
  191. }
  192. }
  193. if ($errorMessage) {
  194. return resultArray(['error' => $errorMessage]);
  195. } else {
  196. return resultArray(['data' => '删除成功']);
  197. }
  198. }
  199. /**
  200. * 符合条件的商机状态组
  201. * @param
  202. * @return
  203. * @author Michael_xu
  204. */
  205. public function statusList()
  206. {
  207. $businessStatusModel = model('BusinessStatus');
  208. $key = 'BI_queryCache_StatusList_Data';
  209. $list = cache($key);
  210. if (!$list) {
  211. $userInfo = $this->userInfo;
  212. $list = db('crm_business_type')
  213. ->field(['name', 'status', 'structure_id', 'type_id'])
  214. ->where(['structure_id' => ['like', '%,' . $userInfo['structure_id'] . ',%'], 'status' => 1])
  215. ->where('is_display', 1)
  216. ->whereOr('structure_id', '')
  217. ->select();
  218. foreach ($list as $k => $v) {
  219. $list[$k]['statusList'] = $businessStatusModel->getDataList($v['type_id']);
  220. }
  221. cache($key, $list, config('business_status_cache_time'));
  222. }
  223. return resultArray(['data' => $list]);
  224. }
  225. /**
  226. * 商机转移
  227. * @param owner_user_id 变更负责人
  228. * @param is_remove 1移出,2转为团队成员
  229. * @param type 权限 1只读2读写
  230. * @return
  231. * @author Michael_xu
  232. */
  233. public function transfer()
  234. {
  235. $param = $this->param;
  236. $userInfo = $this->userInfo;
  237. $businessModel = model('Business');
  238. $settingModel = model('Setting');
  239. $userModel = new \app\admin\model\User();
  240. $authIds = $userModel->getUserByPer(); //权限范围的user_id
  241. if (!$param['owner_user_id']) {
  242. return resultArray(['error' => '变更负责人不能为空']);
  243. }
  244. if (!$param['business_id'] || !is_array($param['business_id'])) {
  245. return resultArray(['error' => '请选择需要转移的商机']);
  246. }
  247. $is_remove = $param['is_remove'] == 2 ? 2 : 1;
  248. $type = $param['type'] == 2 ? 2 : 1;
  249. $data = [];
  250. $data['owner_user_id'] = $param['owner_user_id'];
  251. $data['update_time'] = time();
  252. $ownerUserName = $userModel->getUserNameById($param['owner_user_id']);
  253. $errorMessage = [];
  254. foreach ($param['business_id'] as $business_id) {
  255. $businessInfo = $businessModel->getDataById($business_id);
  256. if (!$businessInfo) {
  257. $errorMessage[] = '名称:为《' . $businessInfo['name'] . '》的商机转移失败,错误原因:数据不存在;';
  258. continue;
  259. }
  260. //权限判断
  261. if (!in_array($businessInfo['owner_user_id'], $authIds)) {
  262. $errorMessage[] = $businessInfo['name'] . '"转移失败,错误原因:无权限;';
  263. continue;
  264. }
  265. //团队成员
  266. teamUserId(
  267. 'crm_business',
  268. $business_id,
  269. $type,
  270. [$businessInfo['owner_user_id']],
  271. $is_remove,
  272. 0
  273. );
  274. $resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
  275. if (!$resBusiness) {
  276. $errorMessage[] = $businessInfo['name'] . '"转移失败,错误原因:数据出错;';
  277. continue;
  278. } else {
  279. $businessArray = [];
  280. $teamBusiness = db('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $business_id)->find();
  281. if (!empty($teamBusiness['ro_user_id'])) {
  282. $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['ro_user_id']), [$teamBusiness['owner_user_id']]));
  283. $businessArray['ro_user_id'] = $businessRo;
  284. }
  285. if (!empty($teamBusiness['rw_user_id'])) {
  286. $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['rw_user_id']), [$teamBusiness['owner_user_id']]));
  287. $businessArray['rw_user_id'] = $businessRo;
  288. }
  289. db('crm_business')->where('business_id', $business_id)->update($businessArray);
  290. }
  291. //修改记录
  292. updateActionLog($userInfo['id'], 'crm_business', $business_id, '', '', '将商机转移给:' . $ownerUserName);
  293. RecordActionLog($userInfo['id'], 'crm_business', 'transfer', $businessInfo['name'], '', '', '将商机:' . $businessInfo['name'] . '转移给:' . $ownerUserName);
  294. }
  295. if (!$errorMessage) {
  296. return resultArray(['data' => '转移成功']);
  297. } else {
  298. return resultArray(['error' => $errorMessage]);
  299. }
  300. }
  301. /**
  302. * 相关产品
  303. * @param
  304. * @return
  305. * @author Michael_xu
  306. */
  307. public function product()
  308. {
  309. $productModel = model('Product');
  310. $userModel = new \app\admin\model\User();
  311. $param = $this->param;
  312. $userInfo = $this->userInfo;
  313. if (!$param['business_id']) {
  314. return resultArray(['error' => '参数错误']);
  315. }
  316. $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
  317. //判断权限
  318. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'read');
  319. //读写权限
  320. $roPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'read');
  321. $rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
  322. if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) {
  323. header('Content-Type:application/json; charset=utf-8');
  324. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  325. }
  326. $dataList = db('crm_business_product')->where(['business_id' => $param['business_id']])->select();
  327. foreach ($dataList as $k => $v) {
  328. $where = [];
  329. $where['product_id'] = $v['product_id'];
  330. $productInfo = db('crm_product')->where($where)->field('name,category_id')->find();
  331. $category_name = db('crm_product_category')->where(['category_id' => $productInfo['category_id']])->value('name');
  332. $dataList[$k]['name'] = $productInfo['name'] ?: '';
  333. $dataList[$k]['category_id_info'] = $category_name ?: '';
  334. }
  335. $list['list'] = $dataList ?: [];
  336. $list['total_price'] = $businessInfo['total_price'] ?: '0.00';
  337. $list['discount_rate'] = $businessInfo['discount_rate'] ?: '0.00';
  338. return resultArray(['data' => $list]);
  339. }
  340. /**
  341. * 商机状态推进
  342. * @param business_id 商机ID
  343. * @param status_id 推进商机状态ID
  344. * @return
  345. * @author Michael_xu
  346. */
  347. public function advance()
  348. {
  349. $param = $this->param;
  350. $userInfo = $this->userInfo;
  351. $userModel = new \app\admin\model\User();
  352. $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
  353. if (!$param['business_id']) {
  354. return resultArray(['error' => '参数错误']);
  355. }
  356. $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
  357. if ($businessInfo['is_end']) {
  358. return resultArray(['error' => '已结束,不能推进']);
  359. }
  360. //判断权限
  361. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
  362. //读写权限
  363. $rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
  364. if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
  365. header('Content-Type:application/json; charset=utf-8');
  366. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  367. }
  368. $status_id = $param['status_id'] ?: $businessInfo['status_id'];
  369. $statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
  370. if (!$statusInfo && !$is_end) {
  371. return resultArray(['error' => '参数错误']);
  372. }
  373. $data = [];
  374. $data['update_time'] = time();
  375. $data['is_end'] = $is_end;
  376. // if ($is_end) {
  377. // $status_id = $is_end;
  378. // }
  379. $data['status_id'] = $status_id;
  380. $data['status_time'] = time();
  381. $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
  382. if (!$res) {
  383. return resultArray(['error' => '推进失败,请重试']);
  384. } else {
  385. # 商机变更后的名称
  386. $businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name');
  387. if (empty($businessStatusName) && $is_end == 1) $businessStatusName = '赢单';
  388. if (empty($businessStatusName) && $is_end == 2) $businessStatusName = '输单';
  389. if (empty($businessStatusName) && $is_end == 3) $businessStatusName = '无效';
  390. # 添加活动记录
  391. Db::name('crm_activity')->insert([
  392. 'type' => 3,
  393. 'activity_type' => 5,
  394. 'activity_type_id' => $businessInfo['business_id'],
  395. 'content' => '阶段变更为 ' . $businessStatusName,
  396. 'create_user_id' => $businessInfo['owner_user_id'],
  397. 'update_time' => time(),
  398. 'create_time' => time(),
  399. 'customer_ids' => ',' . $businessInfo['customer_id'] . ','
  400. ]);
  401. //推进记录添加
  402. $temp['status_id'] = $status_id ?: 0;
  403. $temp['is_end'] = $is_end ?: 0;
  404. $temp['business_id'] = $param['business_id'];
  405. $temp['create_time'] = time();
  406. $temp['owner_user_id'] = $userInfo['id'];
  407. $temp['remark'] = $param['statusRemark'] ?: '';
  408. Db::name('CrmBusinessLog')->insert($temp);
  409. # 返回商机阶段数据
  410. $typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id');
  411. $businessStatus = db('crm_business_status')->where('type_id', $typeId)->select();
  412. $result = [
  413. 'business_id' => $param['business_id'],
  414. 'type_id' => $typeId,
  415. 'status_id' => $param['status_id'],
  416. 'status_list' => $businessStatus
  417. ];
  418. return resultArray(['data' => $result]);
  419. }
  420. }
  421. /**
  422. * 商机导出
  423. * @param
  424. * @return
  425. * @author Michael_xu
  426. */
  427. public function excelExport()
  428. {
  429. $param = $this->param;
  430. $userInfo = $this->userInfo;
  431. $param['user_id'] = $userInfo['id'];
  432. $action_name = '导出全部';
  433. if ($param['business_id']) {
  434. $param['business_id'] = ['condition' => 'in', 'value' => $param['business_id'], 'form_type' => 'text', 'name' => ''];
  435. $param['is_excel'] = 1;
  436. $action_name = '导出选中';
  437. }
  438. $excelModel = new \app\admin\model\Excel();
  439. // 导出的字段列表
  440. $fieldModel = new \app\admin\model\Field();
  441. $field_list = $fieldModel->getIndexFieldConfig('crm_business', $userInfo['id']);
  442. // 文件名
  443. $file_name = '5kcrm_business_' . date('Ymd');
  444. $model = model('Business');
  445. $temp_file = $param['temp_file'];
  446. unset($param['temp_file']);
  447. $page = $param['page'] ?: 1;
  448. unset($param['page']);
  449. unset($param['export_queue_index']);
  450. RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出商机');
  451. return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
  452. $param['page'] = $page;
  453. $param['limit'] = $limit;
  454. $data = $model->getDataList($param);
  455. $data['list'] = $model->exportHandle($data['list'], $field_list, 'business');
  456. return $data;
  457. });
  458. }
  459. /**
  460. * 设置关注
  461. *
  462. * @return \think\response\Json
  463. * @throws \think\Exception
  464. * @throws \think\exception\PDOException
  465. */
  466. public function star()
  467. {
  468. $userId = $this->userInfo['id'];
  469. $targetId = $this->param['target_id'];
  470. $type = $this->param['type'];
  471. if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
  472. if (!$this->setStar($type, $userId, $targetId)) {
  473. return resultArray(['error' => '设置关注失败!']);
  474. }
  475. return resultArray(['data' => '设置关注成功!']);
  476. }
  477. /**
  478. * 系统信息
  479. *
  480. * @return \think\response\Json
  481. * @throws \think\db\exception\DataNotFoundException
  482. * @throws \think\db\exception\ModelNotFoundException
  483. * @throws \think\exception\DbException
  484. */
  485. public function system()
  486. {
  487. if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']);
  488. $businessModel = new \app\crm\model\Business();
  489. $data = $businessModel->getSystemInfo($this->param['id']);
  490. return resultArray(['data' => $data]);
  491. }
  492. /**
  493. * table栏数量统计
  494. *
  495. * @return \think\response\Json
  496. * @throws \think\db\exception\DataNotFoundException
  497. * @throws \think\db\exception\ModelNotFoundException
  498. * @throws \think\exception\DbException
  499. */
  500. public function count()
  501. {
  502. if (empty($this->param['business_id'])) return resultArray(['error' => '参数错误!']);
  503. $businessId = $this->param['business_id'];
  504. $userInfo = $this->userInfo;
  505. # 查询联系人和商机关联数据
  506. $contactsIds = Db::name('crm_contacts_business')->where('business_id', $businessId)->column('contacts_id');
  507. # 联系人
  508. $contactsAuth = $this->getContactsSearchWhere($userInfo['id']);
  509. $contactsCount = Db::name('crm_contacts')->whereIn('contacts_id', $contactsIds)->where($contactsAuth)->count();
  510. # 合同
  511. $contractAuth = $this->getContractSearchWhere($userInfo['id']);
  512. $contractCount = Db::name('crm_contract')->where('business_id', $businessId)->where($contractAuth)->count();
  513. # 查询商机和产品的关联表
  514. $productIds = Db::name('crm_business_product')->where('business_id', $businessId)->column('product_id');
  515. # 产品
  516. $productAuth = $this->getProductSearchWhere();
  517. $productCount = Db::name('crm_product')->whereIn('product_id', $productIds)->whereIn('owner_user_id', $productAuth)->count();
  518. # 附件
  519. $fileCount = Db::name('crm_business_file')->alias('business')->join('__ADMIN_FILE__ file', 'file.file_id = business.file_id', 'LEFT')->where('business_id', $businessId)->count();
  520. # 团队
  521. $business = Db::name('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $businessId)->find();
  522. $business['ro_user_id'] = explode(',', trim($business['ro_user_id'], ','));
  523. $business['rw_user_id'] = explode(',', trim($business['rw_user_id'], ','));
  524. $business['owner_user_id'] = [$business['owner_user_id']];
  525. $teamCount = array_filter(array_unique(array_merge($business['ro_user_id'], $business['rw_user_id'], $business['owner_user_id'])));
  526. $data = [
  527. 'contactCount' => $contactsCount,
  528. 'contractCount' => $contractCount,
  529. 'fileCount' => $fileCount,
  530. 'memberCount' => count($teamCount),
  531. 'productCount' => $productCount
  532. ];
  533. return resultArray(['data' => $data]);
  534. }
  535. /**
  536. * 设置首要联系人
  537. *
  538. * @return \think\response\Json
  539. * @throws \think\Exception
  540. * @throws \think\exception\PDOException
  541. */
  542. public function setPrimary()
  543. {
  544. $businessId = $this->param['business_id'];
  545. $contactsId = $this->param['contacts_id'];
  546. if (empty($businessId) || empty($contactsId)) return resultArray(['error' => '参数错误!']);
  547. if (!Db::name('crm_business')->where('business_id', $businessId)->update(['contacts_id' => $contactsId])) {
  548. return resultArray(['error' => '操作失败!']);
  549. }
  550. return resultArray(['data' => '操作成功!']);
  551. }
  552. }