Business.php 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. db('crm_business_data')->whereIn('business_id', $delIds)->delete();
  184. //删除跟进记录
  185. $recordModel->delDataByTypes(5, $delIds);
  186. //删除关联附件
  187. $fileModel->delRFileByModule('crm_business', $delIds);
  188. //删除关联操作记录
  189. $actionRecordModel->delDataById(['types' => 'crm_business', 'action_id' => $delIds]);
  190. $dataInfo = $businessModel->where('business_id',['in',$delIds])->select();
  191. foreach ($dataInfo as $k => $v) {
  192. RecordActionLog($userInfo['id'], 'crm_business', 'delete', $v['name'], '', '', '删除了商机:' . $v['name']);
  193. }
  194. }
  195. if ($errorMessage) {
  196. return resultArray(['error' => $errorMessage]);
  197. } else {
  198. return resultArray(['data' => '删除成功']);
  199. }
  200. }
  201. /**
  202. * 符合条件的商机状态组
  203. * @param
  204. * @return
  205. * @author Michael_xu
  206. */
  207. public function statusList()
  208. {
  209. $businessStatusModel = model('BusinessStatus');
  210. $key = 'BI_queryCache_StatusList_Data';
  211. $list = cache($key);
  212. if (!$list) {
  213. $userInfo = $this->userInfo;
  214. $list = db('crm_business_type')
  215. ->field(['name', 'status', 'structure_id', 'type_id'])
  216. ->where(['structure_id' => ['like', '%,' . $userInfo['structure_id'] . ',%'], 'status' => 1])
  217. ->where('is_display', 1)
  218. ->whereOr('structure_id', '')
  219. ->select();
  220. foreach ($list as $k => $v) {
  221. $list[$k]['statusList'] = $businessStatusModel->getDataList($v['type_id']);
  222. }
  223. cache($key, $list, config('business_status_cache_time'));
  224. }else{
  225. cache($key, NULL);
  226. }
  227. return resultArray(['data' => $list]);
  228. }
  229. /**
  230. * 商机转移
  231. * @param owner_user_id 变更负责人
  232. * @param is_remove 1移出,2转为团队成员
  233. * @param type 权限 1只读2读写
  234. * @return
  235. * @author Michael_xu
  236. */
  237. public function transfer()
  238. {
  239. $param = $this->param;
  240. $userInfo = $this->userInfo;
  241. $businessModel = model('Business');
  242. $settingModel = model('Setting');
  243. $userModel = new \app\admin\model\User();
  244. $authIds = $userModel->getUserByPer(); //权限范围的user_id
  245. if (!$param['owner_user_id']) {
  246. return resultArray(['error' => '变更负责人不能为空']);
  247. }
  248. if (!$param['business_id'] || !is_array($param['business_id'])) {
  249. return resultArray(['error' => '请选择需要转移的商机']);
  250. }
  251. $is_remove = $param['is_remove'] == 2 ? 2 : 1;
  252. $type = $param['type'] == 2 ? 2 : 1;
  253. $data = [];
  254. $data['owner_user_id'] = $param['owner_user_id'];
  255. $data['update_time'] = time();
  256. $ownerUserName = $userModel->getUserNameById($param['owner_user_id']);
  257. $errorMessage = [];
  258. foreach ($param['business_id'] as $business_id) {
  259. $businessInfo = $businessModel->getDataById($business_id);
  260. if (!$businessInfo) {
  261. $errorMessage[] = '名称:为《' . $businessInfo['name'] . '》的商机转移失败,错误原因:数据不存在;';
  262. continue;
  263. }
  264. //权限判断
  265. if (!in_array($businessInfo['owner_user_id'], $authIds)) {
  266. $errorMessage[] = $businessInfo['name'] . '"转移失败,错误原因:无权限;';
  267. continue;
  268. }
  269. //团队成员
  270. teamUserId(
  271. $param,
  272. 'crm_business',
  273. $business_id,
  274. $type,
  275. [$businessInfo['owner_user_id']],
  276. $is_remove,
  277. 0
  278. );
  279. $resBusiness = db('crm_business')->where(['business_id' => $business_id])->update($data);
  280. if (!$resBusiness) {
  281. $errorMessage[] = $businessInfo['name'] . '"转移失败,错误原因:数据出错;';
  282. continue;
  283. } else {
  284. $businessArray = [];
  285. $teamBusiness = db('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $business_id)->find();
  286. if (!empty($teamBusiness['ro_user_id'])) {
  287. $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['ro_user_id']), [$teamBusiness['owner_user_id']]));
  288. $businessArray['ro_user_id'] = $businessRo;
  289. }
  290. if (!empty($teamBusiness['rw_user_id'])) {
  291. $businessRo = arrayToString(array_diff(stringToArray($teamBusiness['rw_user_id']), [$teamBusiness['owner_user_id']]));
  292. $businessArray['rw_user_id'] = $businessRo;
  293. }
  294. db('crm_business')->where('business_id', $business_id)->update($businessArray);
  295. }
  296. //修改记录
  297. updateActionLog($userInfo['id'], 'crm_business', $business_id, '', '', '将商机转移给:' . $ownerUserName);
  298. RecordActionLog($userInfo['id'], 'crm_business', 'transfer', $businessInfo['name'], '', '', '将商机:' . $businessInfo['name'] . '转移给:' . $ownerUserName);
  299. }
  300. if (!$errorMessage) {
  301. return resultArray(['data' => '转移成功']);
  302. } else {
  303. return resultArray(['error' => $errorMessage]);
  304. }
  305. }
  306. /**
  307. * 相关产品
  308. * @param
  309. * @return
  310. * @author Michael_xu
  311. */
  312. public function product()
  313. {
  314. $productModel = model('Product');
  315. $userModel = new \app\admin\model\User();
  316. $param = $this->param;
  317. $userInfo = $this->userInfo;
  318. if (!$param['business_id']) {
  319. return resultArray(['error' => '参数错误']);
  320. }
  321. $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
  322. //判断权限
  323. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'read');
  324. //读写权限
  325. $roPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'read');
  326. $rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
  327. if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$roPre && !$rwPre) {
  328. header('Content-Type:application/json; charset=utf-8');
  329. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  330. }
  331. $dataList = db('crm_business_product')->where(['business_id' => $param['business_id']])->select();
  332. foreach ($dataList as $k => $v) {
  333. $where = [];
  334. $where['product_id'] = $v['product_id'];
  335. $productInfo = db('crm_product')->where($where)->field('name,category_id')->find();
  336. $category_name = db('crm_product_category')->where(['category_id' => $productInfo['category_id']])->value('name');
  337. $dataList[$k]['name'] = $productInfo['name'] ?: '';
  338. $dataList[$k]['category_id_info'] = $category_name ?: '';
  339. }
  340. $list['list'] = $dataList ?: [];
  341. $list['total_price'] = $businessInfo['total_price'] ?: '0.00';
  342. $list['discount_rate'] = $businessInfo['discount_rate'] ?: '0.00';
  343. return resultArray(['data' => $list]);
  344. }
  345. /**
  346. * 商机状态推进
  347. * @param business_id 商机ID
  348. * @param status_id 推进商机状态ID
  349. * @return
  350. * @author Michael_xu
  351. */
  352. public function advance()
  353. {
  354. $param = $this->param;
  355. $userInfo = $this->userInfo;
  356. $userModel = new \app\admin\model\User();
  357. $is_end = $param['is_end'] ?: 0; //1赢单2输单3无效
  358. if (!$param['business_id']) {
  359. return resultArray(['error' => '参数错误']);
  360. }
  361. $businessInfo = db('crm_business')->where(['business_id' => $param['business_id']])->find();
  362. if ($businessInfo['is_end']) {
  363. return resultArray(['error' => '已结束,不能推进']);
  364. }
  365. //判断权限
  366. $auth_user_ids = $userModel->getUserByPer('crm', 'business', 'update');
  367. //读写权限
  368. $rwPre = $userModel->rwPre($userInfo['id'], $businessInfo['ro_user_id'], $businessInfo['rw_user_id'], 'update');
  369. if (!in_array($businessInfo['owner_user_id'], $auth_user_ids) && !$rwPre) {
  370. header('Content-Type:application/json; charset=utf-8');
  371. exit(json_encode(['code' => 102, 'error' => '无权操作']));
  372. }
  373. $status_id = $param['status_id'] ?: $businessInfo['status_id'];
  374. $statusInfo = db('crm_business_status')->where(['type_id' => $businessInfo['type_id'], 'status_id' => $status_id])->find();
  375. if (!$statusInfo && !$is_end) {
  376. return resultArray(['error' => '参数错误']);
  377. }
  378. $data = [];
  379. $data['update_time'] = time();
  380. $data['is_end'] = $is_end;
  381. // if ($is_end) {
  382. // $status_id = $is_end;
  383. // }
  384. $data['status_id'] = $status_id;
  385. $data['status_time'] = time();
  386. $res = db('crm_business')->where(['business_id' => $param['business_id']])->update($data);
  387. if (!$res) {
  388. return resultArray(['error' => '推进失败,请重试']);
  389. } else {
  390. # 商机变更后的名称
  391. $businessStatusName = Db::name('crm_business_status')->where('status_id', $param['status_id'])->value('name');
  392. if (empty($businessStatusName) && $is_end == 1) $businessStatusName = '赢单';
  393. if (empty($businessStatusName) && $is_end == 2) $businessStatusName = '输单';
  394. if (empty($businessStatusName) && $is_end == 3) $businessStatusName = '无效';
  395. # 添加活动记录
  396. Db::name('crm_activity')->insert([
  397. 'type' => 3,
  398. 'activity_type' => 5,
  399. 'activity_type_id' => $businessInfo['business_id'],
  400. 'content' => '阶段变更为 ' . $businessStatusName,
  401. 'create_user_id' => $businessInfo['owner_user_id'],
  402. 'update_time' => time(),
  403. 'create_time' => time(),
  404. 'customer_ids' => ',' . $businessInfo['customer_id'] . ','
  405. ]);
  406. //推进记录添加
  407. $temp['status_id'] = $status_id ?: 0;
  408. $temp['is_end'] = $is_end ?: 0;
  409. $temp['business_id'] = $param['business_id'];
  410. $temp['create_time'] = time();
  411. $temp['owner_user_id'] = $userInfo['id'];
  412. $temp['remark'] = $param['statusRemark'] ?: '';
  413. Db::name('CrmBusinessLog')->insert($temp);
  414. # 返回商机阶段数据
  415. $typeId = db('crm_business')->where('business_id', $param['business_id'])->value('type_id');
  416. $businessStatus = db('crm_business_status')->where('type_id', $typeId)->select();
  417. $result = [
  418. 'business_id' => $param['business_id'],
  419. 'type_id' => $typeId,
  420. 'status_id' => $param['status_id'],
  421. 'status_list' => $businessStatus
  422. ];
  423. return resultArray(['data' => $result]);
  424. }
  425. }
  426. /**
  427. * 商机导出
  428. * @param
  429. * @return
  430. * @author Michael_xu
  431. */
  432. public function excelExport()
  433. {
  434. $param = $this->param;
  435. $userInfo = $this->userInfo;
  436. $param['user_id'] = $userInfo['id'];
  437. $action_name = '导出全部';
  438. if ($param['business_id']) {
  439. $param['business_id'] = ['condition' => 'in', 'value' => $param['business_id'], 'form_type' => 'text', 'name' => ''];
  440. $param['is_excel'] = 1;
  441. $action_name = '导出选中';
  442. }
  443. $excelModel = new \app\admin\model\Excel();
  444. // 导出的字段列表
  445. $fieldModel = new \app\admin\model\Field();
  446. $field_list = $fieldModel->getIndexFieldConfig('crm_business', $userInfo['id']);
  447. // 文件名
  448. $file_name = '5kcrm_business_' . date('Ymd');
  449. $model = model('Business');
  450. $temp_file = $param['temp_file'];
  451. unset($param['temp_file']);
  452. $page = $param['page'] ?: 1;
  453. unset($param['page']);
  454. unset($param['export_queue_index']);
  455. RecordActionLog($userInfo['id'], 'crm_customer', 'excelexport', $action_name, '', '', '导出商机');
  456. return $excelModel->batchExportCsv($file_name, $temp_file, $field_list, $page, function ($page, $limit) use ($model, $param, $field_list) {
  457. $param['page'] = $page;
  458. $param['limit'] = $limit;
  459. $data = $model->getDataList($param);
  460. $data['list'] = $model->exportHandle($data['list'], $field_list, 'business');
  461. return $data;
  462. });
  463. }
  464. /**
  465. * 设置关注
  466. *
  467. * @return \think\response\Json
  468. * @throws \think\Exception
  469. * @throws \think\exception\PDOException
  470. */
  471. public function star()
  472. {
  473. $userId = $this->userInfo['id'];
  474. $targetId = $this->param['target_id'];
  475. $type = $this->param['type'];
  476. if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
  477. if (!$this->setStar($type, $userId, $targetId)) {
  478. return resultArray(['error' => '设置关注失败!']);
  479. }
  480. return resultArray(['data' => '设置关注成功!']);
  481. }
  482. /**
  483. * 系统信息
  484. *
  485. * @return \think\response\Json
  486. * @throws \think\db\exception\DataNotFoundException
  487. * @throws \think\db\exception\ModelNotFoundException
  488. * @throws \think\exception\DbException
  489. */
  490. public function system()
  491. {
  492. if (empty($this->param['id'])) return resultArray(['error' => '参数错误!']);
  493. $businessModel = new \app\crm\model\Business();
  494. $data = $businessModel->getSystemInfo($this->param['id']);
  495. return resultArray(['data' => $data]);
  496. }
  497. /**
  498. * table栏数量统计
  499. *
  500. * @return \think\response\Json
  501. * @throws \think\db\exception\DataNotFoundException
  502. * @throws \think\db\exception\ModelNotFoundException
  503. * @throws \think\exception\DbException
  504. */
  505. public function count()
  506. {
  507. if (empty($this->param['business_id'])) return resultArray(['error' => '参数错误!']);
  508. $businessId = $this->param['business_id'];
  509. $userInfo = $this->userInfo;
  510. # 查询联系人和商机关联数据
  511. $contactsIds = Db::name('crm_contacts_business')->where('business_id', $businessId)->column('contacts_id');
  512. # 联系人
  513. $contactsAuth = $this->getContactsSearchWhere($userInfo['id']);
  514. $contactsCount = Db::name('crm_contacts')->whereIn('contacts_id', $contactsIds)->where($contactsAuth)->count();
  515. # 合同
  516. $contractAuth = $this->getContractSearchWhere($userInfo['id']);
  517. $contractCount = Db::name('crm_contract')->where('business_id', $businessId)->where($contractAuth)->count();
  518. # 查询商机和产品的关联表
  519. $productIds = Db::name('crm_business_product')->where('business_id', $businessId)->column('product_id');
  520. # 产品
  521. $productAuth = $this->getProductSearchWhere();
  522. $productCount = Db::name('crm_product')->whereIn('product_id', $productIds)->whereIn('owner_user_id', $productAuth)->count();
  523. # 附件
  524. $fileCount = Db::name('crm_business_file')->alias('business')->join('__ADMIN_FILE__ file', 'file.file_id = business.file_id', 'LEFT')->where('business_id', $businessId)->count();
  525. # 团队
  526. $business = Db::name('crm_business')->field(['owner_user_id', 'ro_user_id', 'rw_user_id'])->where('business_id', $businessId)->find();
  527. $business['ro_user_id'] = explode(',', trim($business['ro_user_id'], ','));
  528. $business['rw_user_id'] = explode(',', trim($business['rw_user_id'], ','));
  529. $business['owner_user_id'] = [$business['owner_user_id']];
  530. $teamCount = array_filter(array_unique(array_merge($business['ro_user_id'], $business['rw_user_id'], $business['owner_user_id'])));
  531. $data = [
  532. 'contactCount' => $contactsCount,
  533. 'contractCount' => $contractCount,
  534. 'fileCount' => $fileCount,
  535. 'memberCount' => count($teamCount),
  536. 'productCount' => $productCount
  537. ];
  538. return resultArray(['data' => $data]);
  539. }
  540. /**
  541. * 设置首要联系人
  542. *
  543. * @return \think\response\Json
  544. * @throws \think\Exception
  545. * @throws \think\exception\PDOException
  546. */
  547. public function setPrimary()
  548. {
  549. $businessId = $this->param['business_id'];
  550. $contactsId = $this->param['contacts_id'];
  551. if (empty($businessId) || empty($contactsId)) return resultArray(['error' => '参数错误!']);
  552. if (!Db::name('crm_business')->where('business_id', $businessId)->update(['contacts_id' => $contactsId])) {
  553. return resultArray(['error' => '操作失败!']);
  554. }
  555. return resultArray(['data' => '操作成功!']);
  556. }
  557. }