Leads.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <?php
  2. namespace app\admin\controller\qingdong\customer;
  3. use addons\qingdong\model\File;
  4. use addons\qingdong\model\FormField;
  5. use addons\qingdong\model\Staff;
  6. use app\admin\controller\qingdong\Base;
  7. use addons\qingdong\model\Form;
  8. use addons\qingdong\model\LeadsOther;
  9. use addons\qingdong\model\OperationLog;
  10. use addons\qingdong\model\Record;
  11. use addons\qingdong\model\Customer;
  12. use addons\qingdong\model\Contacts;
  13. use addons\qingdong\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. * 操作文档:https://doc.fastadmin.net/qingdong
  25. * 软件介绍:https://www.fastadmin.net/store/qingdong.html
  26. * 售后微信:qingdong_crm
  27. */
  28. class Leads extends Base
  29. {
  30. protected $relationSearch = true;
  31. protected $searchFields = 'id,name';
  32. /**
  33. * @var \addons\qingdong\model\Leads
  34. */
  35. protected $model = null;
  36. public function _initialize()
  37. {
  38. parent::_initialize();
  39. $this->model = new \addons\qingdong\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->qingdongValidate($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->qingdongValidate($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. try {
  223. $customer = [
  224. 'leads_id' => $row['id'],
  225. 'name' => $row['name'],
  226. 'level' => $row['level'],
  227. 'industry' => $row['industry'],
  228. 'remarks' => $row['remarks'],
  229. 'source' => $row['source'],
  230. 'follow' => $row['follow'],
  231. 'address' => $row['address'],
  232. 'address_detail' => $row['address_detail'],
  233. 'create_staff_id' => $row['owner_staff_id'],
  234. 'owner_staff_id' => $row['owner_staff_id'],
  235. ];
  236. //线索转化
  237. $leads_id = '';
  238. if (isset($customer['leads_id'])) {
  239. $leads_id = $customer['leads_id'];
  240. }
  241. $customer_id = Customer::createCustomer($customer, $leads_id);
  242. $contracts = [
  243. 'customer_id' => $customer_id,
  244. 'is_major' => 1,
  245. 'name' => $row['name'],
  246. 'mobile' => $row['mobile'],
  247. 'remarks' => $row['remarks'],
  248. 'create_staff_id' => $row['owner_staff_id'],
  249. 'owner_staff_id' => $row['owner_staff_id'],
  250. ];
  251. $contacts_id = Contacts::createContacts($contracts);
  252. } catch (Exception $e) {
  253. $this->error($e->getMessage());
  254. }
  255. $this->success('转变成功');
  256. }
  257. /**
  258. * 获取附件记录
  259. */
  260. public function get_file($ids = null)
  261. {
  262. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  263. $list = LeadsFile::where(['leads_id' => $ids])->with(['file'])->field('file_id')->paginate($limit);
  264. $result = array("total" => $list->total(), "rows" => $list->items());
  265. return json($result);
  266. }
  267. /**
  268. * 转移线索
  269. */
  270. public function transfer($ids = null)
  271. {
  272. $row = $this->model::where(['id' => $ids])->find();
  273. if (empty($row)) {
  274. $this->error('线索不存在');
  275. }
  276. if ($this->request->isPost()) {
  277. $staff_id = input('staff_id');
  278. if (empty($staff_id)) {
  279. $this->error('参数错误');
  280. }
  281. $staff = Staff::get($staff_id);
  282. if (empty($staff)) {
  283. $this->error('接收对象不存在');
  284. }
  285. try {
  286. $this->model::transfer($ids, $staff_id);
  287. } catch (Exception $e) {
  288. $this->error($e->getMessage());
  289. }
  290. $this->success('转变成功');
  291. }
  292. $staffs = Staff::getList();
  293. $this->assign('staffs', $staffs);
  294. $this->assign('row', $row);
  295. return $this->view->fetch();
  296. }
  297. /**
  298. * 删除
  299. */
  300. public function del($ids = "")
  301. {
  302. if (!$this->request->isPost()) {
  303. $this->error(__("Invalid parameters"));
  304. }
  305. $ids = $ids ? $ids : $this->request->post("ids");
  306. $row = $this->model->get($ids);
  307. $this->modelValidate = true;
  308. if (!$row) {
  309. $this->error(__('No Results were found'));
  310. }
  311. $row->delete();
  312. $this->success();
  313. }
  314. /**
  315. * 导入
  316. */
  317. public function import()
  318. {
  319. set_time_limit(0);
  320. if ($this->request->isPost()) {
  321. $file = $this->request->request('file');
  322. $staff_id = $this->request->request('staff_id', 0);
  323. if (!$file) {
  324. $this->error(__('Parameter %s can not be empty', 'file'));
  325. }
  326. $filePath = ROOT_PATH . 'public' . $file;
  327. if (!is_file($filePath)) {
  328. $this->error(__('No results were found'));
  329. }
  330. //实例化reader
  331. $ext = pathinfo($filePath, PATHINFO_EXTENSION);
  332. if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
  333. $this->error(__('Unknown data format'));
  334. }
  335. if ($ext === 'csv') {
  336. $file = fopen($filePath, 'r');
  337. $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
  338. $fp = fopen($filePath, "w");
  339. $n = 0;
  340. while ($line = fgets($file)) {
  341. $line = rtrim($line, "\n\r\0");
  342. $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
  343. if ($encoding != 'utf-8') {
  344. $line = mb_convert_encoding($line, 'utf-8', $encoding);
  345. }
  346. if ($n == 0 || preg_match('/^".*"$/', $line)) {
  347. fwrite($fp, $line . "\n");
  348. } else {
  349. fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
  350. }
  351. $n++;
  352. }
  353. fclose($file) || fclose($fp);
  354. $reader = new Csv();
  355. } elseif ($ext === 'xls') {
  356. $reader = new Xls();
  357. } else {
  358. $reader = new Xlsx();
  359. }
  360. if (!$PHPExcel = $reader->load($filePath)) {
  361. $this->error(__('Unknown data format'));
  362. }
  363. $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
  364. $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
  365. $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
  366. $maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
  367. //开始读取数据
  368. $fields = [];
  369. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  370. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  371. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  372. $fields[$currentRow][] = $val;
  373. }
  374. }
  375. if (!isset($fields[1])) {
  376. $this->error('导入文件第一行没有数据');
  377. }
  378. $lastid = $this->model->withTrashed()->order('id desc')->value('id');
  379. $contacts_lastid = (new Contacts())->withTrashed()->order('id desc')->value('id');
  380. $lastid = $lastid + 5;//防止重复
  381. $contacts_lastid = $contacts_lastid + 5;//防止重复
  382. $leadRow = [];
  383. $errorInfo = [];
  384. $formrow = [];
  385. $names = $this->model->where([])->column('name');
  386. $fieldnames = FormField::where(['types' => FormField::LEADS_TYPE])->column('field', 'name');
  387. if(!$fieldnames){
  388. $this->error('请在系统管理->字段管理中保存线索管理表单生成线索导入字段');
  389. }
  390. $forms = Form::getDataValue('leads');
  391. foreach($forms as $k=>$v){
  392. $formrow[$v['id']] = $v['name'];
  393. }
  394. $fn = [];
  395. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  396. $values = [];
  397. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  398. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  399. $values[] = is_null($val) ? '' : $val;
  400. }
  401. foreach ($values as $l) {
  402. $fn[] = $fieldnames[$l] ?? '';
  403. }
  404. }
  405. for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
  406. $values = [];
  407. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  408. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  409. if ($val instanceof RichText) {//富文本转换字符串
  410. $val = $val->__toString();
  411. }
  412. $values[] = is_null($val) ? NULL : $val;
  413. }
  414. $lastid++;
  415. $contacts_lastid++;
  416. $addLeads = ['id' => $lastid, 'owner_staff_id' => $staff_id, 'create_staff_id' => $staff_id];
  417. foreach ($values as $kv => $value) {
  418. if (!isset($fn[$kv]) || empty($fn[$kv])) {
  419. continue;
  420. }
  421. $addLeads[$fn[$kv]] = $value;
  422. }
  423. //日期处理
  424. foreach($formrow as $k=>$v){
  425. if($v=='日期选择框'){
  426. if(isset($addLeads[$k]) && $addLeads[$k]){
  427. $addLeads[$k] =date("Y-m-d", ($addLeads[$k] - 25569) * 24 * 3600);
  428. }
  429. }
  430. if($v=='时间选择框'){
  431. if(isset($addLeads[$k]) && $addLeads[$k]){
  432. $addLeads[$k] =date("Y-m-d H:i:s", ($addLeads[$k] - 25569) * 24 * 3600);
  433. }
  434. }
  435. }
  436. if (!isset($addLeads['name']) || empty($addLeads['name'])) {
  437. $errorInfo[] = "第{$currentRow}行,线索名称不能为空;";
  438. continue;
  439. }
  440. if (in_array($addLeads['name'], $names)) {
  441. $errorInfo[] = "第{$currentRow}行,线索名称`{$addLeads['name']}`已存在;";
  442. continue;
  443. }
  444. $leadRow[] = $addLeads;
  445. }
  446. if (!empty($errorInfo)) {
  447. $this->error(implode(',', $errorInfo));
  448. }
  449. Db::startTrans();
  450. try {
  451. $this->model::importleads($leadRow);
  452. Db::commit();
  453. } catch (Exception $e) {
  454. Db::rollback();
  455. $this->error($e->getMessage());
  456. }
  457. $this->success('导入成功');
  458. }
  459. $this->assign('staffs', Staff::getList());
  460. return $this->view->fetch();
  461. }
  462. /**
  463. * 模板
  464. */
  465. public function template()
  466. {
  467. $title = [];
  468. $contractData = Form::getDataValue('leads');
  469. foreach ($contractData as $val) {
  470. $title[] = $val['config']['label'];
  471. }
  472. $file = export_excel($title, [], '线索');
  473. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  474. header('Content-Disposition: attachment;filename=' . $file['fileName']);
  475. header('Cache-Control: max-age=0');
  476. $obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  477. // 以下内容是excel文件的信息描述信息
  478. $obj->getProperties()->setTitle('导出文件'); //设置标题
  479. $obj->setActiveSheetIndex(0);
  480. $obj->getActiveSheet()->setTitle('导出文件');
  481. /* 循环读取每个单元格的数据 */
  482. $a = 'A';
  483. $currentSheet = $obj->getActiveSheet();
  484. foreach ($title as $key => $value) {
  485. //读取工作表1
  486. // 设置第一行加粗
  487. $obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true);
  488. //这里是设置单元格的内容
  489. $currentSheet->getCell($a . '1')->setValue($value);
  490. $a++;
  491. }
  492. $PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj);
  493. $PHPWriter->save('php://output');
  494. }
  495. /**
  496. * 导出信息
  497. */
  498. public function export()
  499. {
  500. $this->request->filter(['strip_tags', 'trim']);
  501. $ids = input('ids');
  502. $isall = input('isall');
  503. $wheres = array();
  504. //导出其中几条
  505. if (isset($ids)) {
  506. $wheres['id'] = array('in', $ids);
  507. }
  508. //导出全部
  509. if (isset($isall)) {
  510. if ($isall == 3) {
  511. unset($wheres['id']);
  512. }
  513. }
  514. $type = input('type', 0);
  515. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  516. switch ($type) {
  517. case 1:
  518. $staff = Staff::info();
  519. $wheres['owner_staff_id'] = $staff->id;
  520. break;
  521. case 2:
  522. $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
  523. break;
  524. case 3:
  525. $start = date('Y-m-d 00:00:00');
  526. $end = date('Y-m-d 23:59:59');
  527. $record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
  528. $relationId = [];
  529. foreach ($record as $k => $v) {
  530. $whereRe['id'] = array('gt', $v['id']);
  531. $whereRe['relation_id'] = $v['relation_id'];
  532. $recordData = Record::where($whereRe)->count();
  533. if ($recordData == 0) {
  534. $relationId[] = $v['relation_id'];
  535. }
  536. }
  537. $wheres['id'] = array('in', $relationId);
  538. $staff = Staff::info();
  539. $wheres['owner_staff_id'] = $staff->id;
  540. break;
  541. case 4:
  542. $start = date('Y-m-d 00:00:00');
  543. $end = date('Y-m-d 23:59:59');
  544. $record = collection(Record::where(array('relation_type' => 1, 'next_time' => array(array('egt', $start), array('elt', $end))))->field("id,relation_id")->select())->toArray();
  545. $relationId = [];
  546. foreach ($record as $k => $v) {
  547. $whereRe['id'] = array('gt', $v['id']);
  548. $whereRe['relation_id'] = $v['relation_id'];
  549. $recordData = Record::where($whereRe)->count();
  550. if ($recordData >= 1) {
  551. $relationId[] = $v['relation_id'];
  552. }
  553. }
  554. $wheres['id'] = array('in', $relationId);
  555. $staff = Staff::info();
  556. $wheres['owner_staff_id'] = $staff->id;
  557. break;
  558. case 5:
  559. $record = collection(Record::where(array('relation_type' => 4))->column('relation_id'))->toArray();
  560. $wheres['id'] = array('not in', $record);
  561. $staff = Staff::info();
  562. $wheres['owner_staff_id'] = $staff->id;
  563. break;
  564. default:
  565. $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
  566. break;
  567. }
  568. $wheres['is_transform'] = 0;
  569. $list = $this->model->with([
  570. 'ownerStaff','leadsOther'
  571. ])->where($where)->where($wheres)->order($sort, $order)->select();
  572. $list = collection($list)->toArray();
  573. if (!$list) {
  574. $this->error('无导出数据');
  575. }
  576. $title = [
  577. '序号',
  578. '归属人',
  579. '创建时间',
  580. ];
  581. $contractData = Form::getDataValue('leads');
  582. foreach ($contractData as $val) {
  583. $title[] = $val['config']['label'];
  584. }
  585. foreach ($list as $k => $v) {
  586. if($v['leads_other']){//其他线索
  587. $other=$v['leads_other']['otherdata'];
  588. $other=json_decode($other,true);
  589. $v = array_merge($v, $other);
  590. }
  591. $field = array(
  592. $k + 1,
  593. $v['owner_staff']['name'],
  594. $v['createtime']
  595. );
  596. foreach ($contractData as $val) {
  597. if ($val['component'] == 'uploadImage' || $val['component'] == 'uploadFile') {
  598. $field[] = $v[$val['id'] . '_str'] ?? '';
  599. } else {
  600. $field[] = ($v[$val['id']] ?? '');
  601. }
  602. }
  603. $data[] = $field;
  604. }
  605. $file = export_excel($title, $data, '线索');
  606. if ($file['filePath']) {
  607. $this->success('导出成功', '', $file);
  608. }
  609. $this->error('导出失败');
  610. }
  611. /**
  612. * 移入线索池
  613. */
  614. public function movepool()
  615. {
  616. $ids = input('ids');
  617. $reuslt= $this->model->where(['id' => $ids])->update(['owner_staff_id' => 0,'updatetime'=>time()]);
  618. if(!$reuslt){
  619. $this->error('放入失败');
  620. }
  621. $this->success('放入成功');
  622. }
  623. }