Contacts.php 26 KB

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