Leads.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. <?php
  2. namespace app\admin\controller\qingdongams\customer;
  3. use addons\qingdongams\model\File;
  4. use addons\qingdongams\model\FormField;
  5. use addons\qingdongams\model\Staff;
  6. use app\admin\controller\qingdongams\Base;
  7. use addons\qingdongams\model\Form;
  8. use addons\qingdongams\model\LeadsOther;
  9. use addons\qingdongams\model\OperationLog;
  10. use addons\qingdongams\model\Record;
  11. use addons\qingdongams\model\Customer;
  12. use addons\qingdongams\model\Contacts;
  13. use addons\qingdongams\model\LeadsFile;
  14. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  15. use PhpOffice\PhpSpreadsheet\IOFactory;
  16. use PhpOffice\PhpSpreadsheet\Reader\Csv;
  17. use PhpOffice\PhpSpreadsheet\Reader\Xls;
  18. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  19. use PhpOffice\PhpSpreadsheet\RichText\RichText;
  20. use think\Db;
  21. use think\Exception;
  22. /**
  23. * 线索
  24. * @desc 操作文档:https://doc.fastadmin.net/qingdongams
  25. * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
  26. * @desc 售后微信:qingdong_crm
  27. */
  28. class Leads extends Base
  29. {
  30. protected $relationSearch = true;
  31. protected $searchFields = 'id,name';
  32. /**
  33. * @var \addons\qingdongams\model\Leads
  34. */
  35. protected $model = null;
  36. public function _initialize()
  37. {
  38. parent::_initialize();
  39. $this->model = new \addons\qingdongams\model\Leads;
  40. }
  41. /**
  42. * 查看
  43. */
  44. public function index()
  45. {
  46. $this->request->filter(['strip_tags', 'trim']);
  47. if ($this->request->isAjax()) {
  48. //0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的
  49. $type = input('type', 0);
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. switch ($type) {
  52. case 1:
  53. $staff = Staff::info();
  54. $wheres['owner_staff_id'] = $staff->id;
  55. break;
  56. case 2:
  57. $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
  58. break;
  59. case 3:
  60. $start = date('Y-m-d 00:00:00');
  61. $end = date('Y-m-d 23:59:59');
  62. $record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
  63. $relationId = [];
  64. foreach ($record as $k => $v) {
  65. $whereRe['id'] = array('gt', $v['id']);
  66. $whereRe['relation_id'] = $v['relation_id'];
  67. $recordData = Record::where($whereRe)->count();
  68. if ($recordData == 0) {
  69. $relationId[] = $v['relation_id'];
  70. }
  71. }
  72. $wheres['id'] = array('in', $relationId);
  73. $staff = Staff::info();
  74. $wheres['owner_staff_id'] = $staff->id;
  75. break;
  76. case 4:
  77. $start = date('Y-m-d 00:00:00');
  78. $end = date('Y-m-d 23:59:59');
  79. $record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
  80. $relationId = [];
  81. foreach ($record as $k => $v) {
  82. $whereRe['id'] = array('gt', $v['id']);
  83. $whereRe['relation_id'] = $v['relation_id'];
  84. $recordData = Record::where($whereRe)->count();
  85. if ($recordData >= 1) {
  86. $relationId[] = $v['relation_id'];
  87. }
  88. }
  89. $wheres['id'] = array('in', $relationId);
  90. $staff = Staff::info();
  91. $wheres['owner_staff_id'] = $staff->id;
  92. break;
  93. case 5:
  94. $record = collection(Record::where(array('relation_type' => 4))->column('relation_id'))->toArray();
  95. $wheres['id'] = array('not in', $record);
  96. $staff = Staff::info();
  97. $wheres['owner_staff_id'] = $staff->id;
  98. break;
  99. default:
  100. $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
  101. break;
  102. }
  103. $wheres['is_transform'] = 0;
  104. $list = $this->model->where($where)->where($wheres)->order($sort, $order)->with(['ownerStaff'])->paginate($limit);
  105. $result = array("total" => $list->total(), "rows" => $list->items());
  106. return json($result);
  107. }
  108. $field = FormField::getFields(FormField::LEADS_TYPE);
  109. $this->assignconfig('fields', $field);
  110. return $this->view->fetch();
  111. }
  112. /**
  113. * 添加
  114. */
  115. public function add()
  116. {
  117. if ($this->request->isPost()) {
  118. $params = $this->request->post("row/a");
  119. if ($params) {
  120. $params = $this->preExcludeFields($params);
  121. // 表单验证
  122. if (($result = $this->qingdongamsValidate($params, 'Leads', 'create')) !== true) {
  123. $this->error($result);
  124. }
  125. $result = FormField::checkFields('leads', $params);
  126. if ($result !== true) {
  127. $this->error($result);
  128. }
  129. $result = false;
  130. Db::startTrans();
  131. try {
  132. $params = Form::updateFormParams('leads', $params);
  133. $result = $this->model::createLeads($params);
  134. Db::commit();
  135. } catch (Exception $e) {
  136. Db::rollback();
  137. $this->error($e->getMessage());
  138. }
  139. if ($result !== false) {
  140. $this->success();
  141. } else {
  142. $this->error(__('No rows were inserted'));
  143. }
  144. }
  145. $this->error(__('Parameter %s can not be empty', ''));
  146. }
  147. $staffs = Staff::getList($this->_staff->id);
  148. $this->assign('staffs', $staffs);
  149. $this->view->assign('form_data', Form::getDataValue('leads'));
  150. return $this->view->fetch();
  151. }
  152. /**
  153. * 修改
  154. */
  155. public function edit($ids = null)
  156. {
  157. $row = $this->model->get($ids);
  158. if ($this->request->isPost()) {
  159. $params = $this->request->post("row/a");
  160. if ($params) {
  161. $params = $this->preExcludeFields($params);
  162. // 表单验证
  163. if (($result = $this->qingdongamsValidate($params, 'Leads', 'create')) !== true) {
  164. $this->error($result);
  165. }
  166. $result = FormField::checkFields('leads', $params, $ids);
  167. if ($result !== true) {
  168. $this->error($result);
  169. }
  170. $result = false;
  171. Db::startTrans();
  172. try {
  173. $params = Form::updateFormParams('leads', $params);
  174. $params['id'] = $ids;
  175. $result = $this->model::updateLeads($params);
  176. Db::commit();
  177. } catch (Exception $e) {
  178. Db::rollback();
  179. $this->error($e->getMessage());
  180. }
  181. if ($result !== false) {
  182. $this->success();
  183. } else {
  184. $this->error(__('No rows were inserted'));
  185. }
  186. }
  187. $this->error(__('Parameter %s can not be empty', ''));
  188. }
  189. $row = $row->toArray();
  190. $row = LeadsOther::getOther($row);
  191. $this->assign('row', $row);
  192. $this->view->assign('form_data', Form::getDataValue('leads', $row));
  193. return $this->view->fetch();
  194. }
  195. /**
  196. * 线索详情
  197. */
  198. public function detail($ids = null)
  199. {
  200. $row = $this->model->with(['create_staff', 'owner_staff'])->where(['id' => $ids])->find();
  201. //跟进记录
  202. $this->assign('records', Record::getList(Record::LEADS_TYPE, $ids));
  203. //操作记录
  204. $this->assign('operation_log', OperationLog::getList(OperationLog::LEADS_TYPE, $ids));
  205. $row = $row->toArray();
  206. $row = LeadsOther::getOther($row);
  207. $this->view->assign('form_data', Form::getDataValue('leads', $row));
  208. $this->assign('row', $row);
  209. $this->assign('ids', $ids);
  210. $this->assignconfig("idinfo", ['id' => $ids]);
  211. return $this->view->fetch();
  212. }
  213. /**
  214. * 转为客户
  215. */
  216. public function convert_customer($ids = null)
  217. {
  218. $row = $this->model->get($ids);
  219. if (empty($row)) {
  220. $this->error('线索不存在');
  221. }
  222. $form=Form::getDataValue(Form::LEADS_TYPE);
  223. $fields=[];
  224. foreach ($form as $v){
  225. if(isset($v['matching']) && $v['matching']){
  226. $fields[$v['matching']]=$v['id'];
  227. }
  228. }
  229. try {
  230. $customer=[
  231. 'leads_id' => $row['id'],
  232. 'create_staff_id' => $row['owner_staff_id'],
  233. 'owner_staff_id' => $row['owner_staff_id'],
  234. ];
  235. foreach ($fields as $k => $f) {
  236. $customer[$k] = $row[$f] ?? '';
  237. }
  238. //线索转化
  239. $leads_id = '';
  240. if (isset($customer['leads_id'])) {
  241. $leads_id = $customer['leads_id'];
  242. }
  243. $customer_id = Customer::createCustomer($customer, $leads_id);
  244. $contracts = [
  245. 'customer_id' => $customer_id,
  246. 'is_major' => 1,
  247. 'name' => $row['name'],
  248. 'mobile' => $row['mobile'],
  249. 'remarks' => $row['remarks'],
  250. 'create_staff_id' => $row['owner_staff_id'],
  251. 'owner_staff_id' => $row['owner_staff_id'],
  252. ];
  253. $contacts_id = Contacts::createContacts($contracts);
  254. } catch (Exception $e) {
  255. $this->error($e->getMessage());
  256. }
  257. $this->success('转变成功');
  258. }
  259. /**
  260. * 获取附件记录
  261. */
  262. public function get_file($ids = null)
  263. {
  264. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  265. $list = LeadsFile::where(['leads_id' => $ids])->with(['file'])->field('file_id')->paginate($limit);
  266. $result = array("total" => $list->total(), "rows" => $list->items());
  267. return json($result);
  268. }
  269. /**
  270. * 转移线索
  271. */
  272. public function transfer($ids = null)
  273. {
  274. $row = $this->model::where(['id' => $ids])->find();
  275. if (empty($row)) {
  276. $this->error('线索不存在');
  277. }
  278. if ($this->request->isPost()) {
  279. $staff_id = input('staff_id');
  280. if (empty($staff_id)) {
  281. $this->error('参数错误');
  282. }
  283. $staff = Staff::get($staff_id);
  284. if (empty($staff)) {
  285. $this->error('接收对象不存在');
  286. }
  287. try {
  288. $this->model::transfer($ids, $staff_id);
  289. } catch (Exception $e) {
  290. $this->error($e->getMessage());
  291. }
  292. $this->success('转变成功');
  293. }
  294. $staffs = Staff::getList();
  295. $this->assign('staffs', $staffs);
  296. $this->assign('row', $row);
  297. return $this->view->fetch();
  298. }
  299. /**
  300. * 删除
  301. */
  302. public function del($ids = "")
  303. {
  304. if (!$this->request->isPost()) {
  305. $this->error(__("Invalid parameters"));
  306. }
  307. $ids = $ids ? $ids : $this->request->post("ids");
  308. $row = $this->model->get($ids);
  309. $this->modelValidate = true;
  310. if (!$row) {
  311. $this->error(__('No Results were found'));
  312. }
  313. $row->delete();
  314. $this->success();
  315. }
  316. /**
  317. * 导入
  318. */
  319. public function import()
  320. {
  321. set_time_limit(0);
  322. if ($this->request->isPost()) {
  323. $file = $this->request->request('file');
  324. $staff_id = $this->request->request('staff_id', 0);
  325. if (!$file) {
  326. $this->error(__('Parameter %s can not be empty', 'file'));
  327. }
  328. $filePath = ROOT_PATH . 'public' . $file;
  329. if (!is_file($filePath)) {
  330. $this->error(__('No results were found'));
  331. }
  332. //实例化reader
  333. $ext = pathinfo($filePath, PATHINFO_EXTENSION);
  334. if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
  335. $this->error(__('Unknown data format'));
  336. }
  337. if ($ext === 'csv') {
  338. $file = fopen($filePath, 'r');
  339. $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
  340. $fp = fopen($filePath, "w");
  341. $n = 0;
  342. while ($line = fgets($file)) {
  343. $line = rtrim($line, "\n\r\0");
  344. $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
  345. if ($encoding != 'utf-8') {
  346. $line = mb_convert_encoding($line, 'utf-8', $encoding);
  347. }
  348. if ($n == 0 || preg_match('/^".*"$/', $line)) {
  349. fwrite($fp, $line . "\n");
  350. } else {
  351. fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
  352. }
  353. $n++;
  354. }
  355. fclose($file) || fclose($fp);
  356. $reader = new Csv();
  357. } elseif ($ext === 'xls') {
  358. $reader = new Xls();
  359. } else {
  360. $reader = new Xlsx();
  361. }
  362. if (!$PHPExcel = $reader->load($filePath)) {
  363. $this->error(__('Unknown data format'));
  364. }
  365. $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
  366. $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
  367. $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
  368. $maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
  369. //开始读取数据
  370. $fields = [];
  371. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  372. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  373. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  374. $fields[$currentRow][] = $val;
  375. }
  376. }
  377. if (!isset($fields[1])) {
  378. $this->error('导入文件第一行没有数据');
  379. }
  380. $lastid = $this->model->withTrashed()->order('id desc')->value('id');
  381. $contacts_lastid = (new Contacts())->withTrashed()->order('id desc')->value('id');
  382. $lastid = $lastid + 5;//防止重复
  383. $contacts_lastid = $contacts_lastid + 5;//防止重复
  384. $leadRow = [];
  385. $errorInfo = [];
  386. $formrow = [];
  387. $names = $this->model->where([])->column('name');
  388. $fieldnames = FormField::where(['types' => FormField::LEADS_TYPE])->column('field', 'name');
  389. if(!$fieldnames){
  390. $this->error('请在系统管理->字段管理中保存线索管理表单生成线索导入字段');
  391. }
  392. $forms = Form::getDataValue('leads');
  393. foreach($forms as $k=>$v){
  394. $formrow[$v['id']] = $v['name'];
  395. }
  396. $fn = [];
  397. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  398. $values = [];
  399. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  400. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  401. $values[] = is_null($val) ? '' : $val;
  402. }
  403. foreach ($values as $l) {
  404. $fn[] = $fieldnames[$l] ?? '';
  405. }
  406. }
  407. for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
  408. $values = [];
  409. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  410. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  411. if ($val instanceof RichText) {//富文本转换字符串
  412. $val = $val->__toString();
  413. }
  414. $values[] = is_null($val) ? NULL : $val;
  415. }
  416. $lastid++;
  417. $contacts_lastid++;
  418. $addLeads = ['id' => $lastid, 'owner_staff_id' => $staff_id, 'create_staff_id' => $staff_id];
  419. foreach ($values as $kv => $value) {
  420. if (!isset($fn[$kv]) || empty($fn[$kv])) {
  421. continue;
  422. }
  423. $addLeads[$fn[$kv]] = $value;
  424. }
  425. //日期处理
  426. foreach($formrow as $k=>$v){
  427. if($v=='日期选择框'){
  428. if(isset($addLeads[$k]) && $addLeads[$k]){
  429. $addLeads[$k] =date("Y-m-d", ($addLeads[$k] - 25569) * 24 * 3600);
  430. }
  431. }
  432. if($v=='时间选择框'){
  433. if(isset($addLeads[$k]) && $addLeads[$k]){
  434. $addLeads[$k] =date("Y-m-d H:i:s", ($addLeads[$k] - 25569) * 24 * 3600);
  435. }
  436. }
  437. }
  438. if (!isset($addLeads['name']) || empty($addLeads['name'])) {
  439. $errorInfo[] = "第{$currentRow}行,线索名称不能为空;";
  440. continue;
  441. }
  442. if (in_array($addLeads['name'], $names)) {
  443. $errorInfo[] = "第{$currentRow}行,线索名称`{$addLeads['name']}`已存在;";
  444. continue;
  445. }
  446. $leadRow[] = $addLeads;
  447. }
  448. if (!empty($errorInfo)) {
  449. $this->error(implode(',', $errorInfo));
  450. }
  451. Db::startTrans();
  452. try {
  453. $this->model::importleads($leadRow);
  454. Db::commit();
  455. } catch (Exception $e) {
  456. Db::rollback();
  457. $this->error($e->getMessage());
  458. }
  459. $this->success('导入成功');
  460. }
  461. $this->assign('staffs', Staff::getList());
  462. return $this->view->fetch();
  463. }
  464. /**
  465. * 模板
  466. */
  467. public function template()
  468. {
  469. $title = [];
  470. $contractData = Form::getDataValue('leads');
  471. foreach ($contractData as $val) {
  472. $title[] = $val['config']['label'];
  473. }
  474. $file = export_excel($title, [], '线索');
  475. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  476. header('Content-Disposition: attachment;filename=' . $file['fileName']);
  477. header('Cache-Control: max-age=0');
  478. $obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  479. // 以下内容是excel文件的信息描述信息
  480. $obj->getProperties()->setTitle('导出文件'); //设置标题
  481. $obj->setActiveSheetIndex(0);
  482. $obj->getActiveSheet()->setTitle('导出文件');
  483. /* 循环读取每个单元格的数据 */
  484. $a = 'A';
  485. $currentSheet = $obj->getActiveSheet();
  486. foreach ($title as $key => $value) {
  487. //读取工作表1
  488. // 设置第一行加粗
  489. $obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true);
  490. //这里是设置单元格的内容
  491. $currentSheet->getCell($a . '1')->setValue($value);
  492. $a++;
  493. }
  494. $PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj);
  495. $PHPWriter->save('php://output');
  496. }
  497. /**
  498. * 导出信息
  499. */
  500. public function export()
  501. {
  502. $this->request->filter(['strip_tags', 'trim']);
  503. $ids = input('ids');
  504. $isall = input('isall');
  505. $wheres = array();
  506. //导出其中几条
  507. if (isset($ids)) {
  508. $wheres['id'] = array('in', $ids);
  509. }
  510. //导出全部
  511. if (isset($isall)) {
  512. if ($isall == 3) {
  513. unset($wheres['id']);
  514. }
  515. }
  516. $type = input('type', 0);
  517. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  518. switch ($type) {
  519. case 1:
  520. $staff = Staff::info();
  521. $wheres['owner_staff_id'] = $staff->id;
  522. break;
  523. case 2:
  524. $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
  525. break;
  526. case 3:
  527. $start = date('Y-m-d 00:00:00');
  528. $end = date('Y-m-d 23:59:59');
  529. $record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
  530. $relationId = [];
  531. foreach ($record as $k => $v) {
  532. $whereRe['id'] = array('gt', $v['id']);
  533. $whereRe['relation_id'] = $v['relation_id'];
  534. $recordData = Record::where($whereRe)->count();
  535. if ($recordData == 0) {
  536. $relationId[] = $v['relation_id'];
  537. }
  538. }
  539. $wheres['id'] = array('in', $relationId);
  540. $staff = Staff::info();
  541. $wheres['owner_staff_id'] = $staff->id;
  542. break;
  543. case 4:
  544. $start = date('Y-m-d 00:00:00');
  545. $end = date('Y-m-d 23:59:59');
  546. $record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
  547. $relationId = [];
  548. foreach ($record as $k => $v) {
  549. $whereRe['id'] = array('gt', $v['id']);
  550. $whereRe['relation_id'] = $v['relation_id'];
  551. $recordData = Record::where($whereRe)->count();
  552. if ($recordData >= 1) {
  553. $relationId[] = $v['relation_id'];
  554. }
  555. }
  556. $wheres['id'] = array('in', $relationId);
  557. $staff = Staff::info();
  558. $wheres['owner_staff_id'] = $staff->id;
  559. break;
  560. case 5:
  561. $record = collection(Record::where(array('relation_type' => 4))->column('relation_id'))->toArray();
  562. $wheres['id'] = array('not in', $record);
  563. $staff = Staff::info();
  564. $wheres['owner_staff_id'] = $staff->id;
  565. break;
  566. default:
  567. $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
  568. break;
  569. }
  570. $wheres['is_transform'] = 0;
  571. $list = $this->model->with([
  572. 'ownerStaff','leadsOther'
  573. ])->where($where)->where($wheres)->order($sort, $order)->select();
  574. $list = collection($list)->toArray();
  575. if (!$list) {
  576. $this->error('无导出数据');
  577. }
  578. $title = [
  579. '序号',
  580. '归属人',
  581. '创建时间',
  582. ];
  583. $contractData = Form::getDataValue('leads');
  584. foreach ($contractData as $val) {
  585. $title[] = $val['config']['label'];
  586. }
  587. foreach ($list as $k => $v) {
  588. if($v['leads_other']){//其他线索
  589. $other=$v['leads_other']['otherdata'];
  590. $other=json_decode($other,true);
  591. $v = array_merge($v, $other);
  592. }
  593. $field = array(
  594. $k + 1,
  595. $v['owner_staff']['name'],
  596. $v['createtime']
  597. );
  598. foreach ($contractData as $val) {
  599. if ($val['component'] == 'uploadImage' || $val['component'] == 'uploadFile') {
  600. $field[] = $v[$val['id'] . '_str'] ?? '';
  601. } else {
  602. $field[] = ($v[$val['id']] ?? '');
  603. }
  604. }
  605. $data[] = $field;
  606. }
  607. $file = export_excel($title, $data, '线索');
  608. if ($file['filePath']) {
  609. $this->success('导出成功', '', $file);
  610. }
  611. $this->error('导出失败');
  612. }
  613. //移入线索池
  614. public function movePool()
  615. {
  616. $id = input('id');
  617. $row = $this->model->where(['id' => $id])->find();
  618. if (empty($row)) {
  619. $this->error('线索不存在');
  620. }
  621. Db::startTrans();
  622. try {
  623. $this->model->movePool($id);
  624. Db::commit();
  625. } catch (Exception $e) {
  626. Db::rollback();
  627. $this->error($e->getMessage());
  628. }
  629. $this->success('放入成功');
  630. }
  631. }