Contacts.php 24 KB

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