Contract.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. <?php
  2. namespace app\admin\controller\qingdong\customer;
  3. use addons\qingdong\model\BusinessProduct;
  4. use addons\qingdong\model\ContactsOther;
  5. use addons\qingdong\model\ContractProduct;
  6. use addons\qingdong\model\CustomerOther;
  7. use addons\qingdong\model\ExamineRecord;
  8. use addons\qingdong\model\File;
  9. use addons\qingdong\model\FormField;
  10. use addons\qingdong\model\ProductPart;
  11. use addons\qingdong\model\Product;
  12. use addons\qingdong\model\Ratio;
  13. use addons\qingdong\model\Receivables;
  14. use addons\qingdong\model\Staff;
  15. use addons\qingdong\model\WordTemplate;
  16. use app\admin\controller\qingdong\Base;
  17. use addons\qingdong\model\ContractOther;
  18. use addons\qingdong\model\Form;
  19. use addons\qingdong\model\Contacts;
  20. use addons\qingdong\model\Customer;
  21. use addons\qingdong\model\OperationLog;
  22. use addons\qingdong\model\Record;
  23. use addons\qingdong\model\ContractFile;
  24. use addons\qingdong\model\Flow;
  25. use addons\qingdong\model\Business;
  26. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  27. use PhpOffice\PhpSpreadsheet\Reader\Csv;
  28. use PhpOffice\PhpSpreadsheet\Reader\Xls;
  29. use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
  30. use PhpOffice\PhpSpreadsheet\RichText\RichText;
  31. use PhpOffice\PhpWord\Settings;
  32. use PhpOffice\PhpWord\TemplateProcessor;
  33. use think\Db;
  34. use think\Exception;
  35. /**
  36. * 合同管理
  37. * 操作文档:https://doc.fastadmin.net/qingdong
  38. * 软件介绍:https://www.fastadmin.net/store/qingdong.html
  39. * 售后微信:qingdong_crm
  40. */
  41. class Contract extends Base {
  42. protected $relationSearch = true;
  43. /**
  44. * @var \addons\qingdong\model\Contract
  45. */
  46. protected $model = null;
  47. public function _initialize() {
  48. parent::_initialize();
  49. $this->model = new \addons\qingdong\model\Contract;
  50. }
  51. /**
  52. * 查看
  53. */
  54. public function index() {
  55. //设置过滤方法
  56. $this->request->filter(['strip_tags', 'trim']);
  57. if ($this->request->isAjax()) {
  58. if ($this->request->request('keyField')) {
  59. return $this->selectpage();
  60. }
  61. //0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的
  62. $type = input('type',0);
  63. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  64. switch($type){
  65. case 1:
  66. $staff = Staff::info();
  67. $wheres['owner_staff_id'] = $staff->id;
  68. break;
  69. case 2:
  70. $wheres['owner_staff_id'] = array('in',Staff::getLowerStaffId());
  71. break;
  72. case 3:
  73. $start = date('Y-m-d 00:00:00');
  74. $end = date('Y-m-d 23:59:59');
  75. $record = collection(Record::where(array('relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
  76. $relationId = [];
  77. foreach($record as $k=>$v){
  78. $whereRe['id'] = array('gt',$v['id']);
  79. $whereRe['relation_id'] = $v['relation_id'];
  80. $recordData = Record::where($whereRe)->count();
  81. if($recordData == 0){
  82. $relationId[] = $v['relation_id'];
  83. }
  84. }
  85. $wheres['id'] = array('in',$relationId);
  86. $staff = Staff::info();
  87. $wheres['owner_staff_id'] = $staff->id;
  88. break;
  89. case 4:
  90. $start = date('Y-m-d 00:00:00');
  91. $end = date('Y-m-d 23:59:59');
  92. $record = collection(Record::where(array('relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
  93. $relationId = [];
  94. foreach($record as $k=>$v){
  95. $whereRe['id'] = array('gt',$v['id']);
  96. $whereRe['relation_id'] = $v['relation_id'];
  97. $recordData = Record::where($whereRe)->count();
  98. if($recordData >=1){
  99. $relationId[] = $v['relation_id'];
  100. }
  101. }
  102. $wheres['id'] = array('in',$relationId);
  103. $staff = Staff::info();
  104. $wheres['owner_staff_id'] = $staff->id;
  105. break;
  106. case 5:
  107. $record = collection(Record::where(array('relation_type'=>3,'next_time'=>array('neq','')))->column('relation_id'))->toArray();
  108. $wheres['id'] = array('not in',$record);
  109. $staff = Staff::info();
  110. $wheres['owner_staff_id'] = $staff->id;
  111. break;
  112. default:
  113. $wheres['owner_staff_id'] = array('in',Staff::getMyStaffIds());
  114. break;
  115. }
  116. $ids=[];
  117. $group_id=input('group_id');
  118. $staff_id=input('staff_id');
  119. if ($group_id) {//角色组
  120. $ids = Staff::getGroupStaffIds($group_id);
  121. }
  122. if ($staff_id) {
  123. $ids = $staff_id;
  124. }
  125. if ($group_id || $staff_id) {
  126. $wheres['owner_staff_id'] = ['in', $ids];
  127. }
  128. $list = $this->model->where($where)
  129. ->where($wheres)
  130. ->with([
  131. 'customer',
  132. 'orderStaff',
  133. 'contacts'
  134. ])->order($sort, $order)->paginate($limit);
  135. $allmoney = $this->model->where($wheres)->where(array('check_status'=>2))->sum('money');
  136. $repayment_money = Receivables::where($wheres)->where(array('check_status'=>2))->sum('money'); //已回款
  137. $no_money = $allmoney - $repayment_money;
  138. if($no_money <= 0){
  139. $no_money = 0;
  140. }
  141. $result = array("total" => $list->total(), "rows" => $list->items(),'allmoney'=>$allmoney,'repayment_money'=>$repayment_money,'no_money'=>$no_money);
  142. return json($result);
  143. }
  144. $field = FormField::getFields(FormField::CONTRACT_TYPE);
  145. $this->assignconfig('fields', $field);
  146. return $this->view->fetch();
  147. }
  148. /**
  149. * 添加
  150. */
  151. public function add()
  152. {
  153. if ($this->request->isPost()) {
  154. $params = $this->request->post("row/a");
  155. if ($params) {
  156. $params = $this->preExcludeFields($params);
  157. // 表单验证
  158. if (($result = $this->qingdongValidate($params, 'Contract', 'create')) !== true) {
  159. $this->error($result);
  160. }
  161. $result = FormField::checkFields(FormField::CONTRACT_TYPE, $params);
  162. if ($result !== true) {
  163. $this->error($result);
  164. }
  165. $result = false;
  166. Db::startTrans();
  167. try {
  168. $params = Form::updateFormParams(Form::CONTRACT_TYPE, $params);
  169. if($params['product']){
  170. $params['product']=json_decode($params['product'],true);
  171. }
  172. $result = $this->model::createContract($params);
  173. Db::commit();
  174. } catch (Exception $e) {
  175. Db::rollback();
  176. $this->error($e->getMessage());
  177. }
  178. if ($result !== false) {
  179. $this->success();
  180. } else {
  181. $this->error(__('No rows were inserted'));
  182. }
  183. }
  184. $this->error(__('Parameter %s can not be empty', ''));
  185. }
  186. $flow= Flow::getsteplist(Flow::CONTRACT_STATUS);
  187. if (empty($flow)) {
  188. $this->error('无可用审批流,请联系管理员','qingdong/work/flow');
  189. }
  190. $customer_id = input('customer_id');
  191. if($customer_id){
  192. $business = Business::where(array('customer_id'=>$customer_id))->select();
  193. }else{
  194. $business = Business::getList();
  195. }
  196. $this->assign('flow',$flow);
  197. $this->assign('staff', Staff::getStaff());
  198. $this->assign('customers', Customer::getList());
  199. $this->assign('business', $business);
  200. $this->assign('customer_id', $customer_id);
  201. $this->assign('business_id', input('business_id'));
  202. $this->assign('staffs', Staff::allList());
  203. $this->assign('form_data', Form::getDataValue('contract'));
  204. $this->assign('ratio',Ratio::where(['status'=>1])->select());
  205. $this->assign('contractNum', 'C'.date('Ymd').rand(10000,99999));
  206. return $this->view->fetch();
  207. }
  208. /**
  209. * 修改合同
  210. */
  211. public function edit($ids = null) {
  212. $map['id'] = $ids;
  213. if ($this->request->isAjax()) {
  214. $params = $this->request->post('row/a');
  215. $params = $this->preExcludeFields($params);
  216. $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [3, 4]]])->find();
  217. if (empty($row)) {
  218. $this->error('合同审核中或已审核通过无法修改');
  219. }
  220. // 表单验证
  221. if (($result = $this->qingdongValidate($params, 'Contract', 'create')) !== true) {
  222. $this->error($result);
  223. }
  224. $result = FormField::checkFields(FormField::CONTRACT_TYPE, $params,$ids);
  225. if ($result !== true) {
  226. $this->error($result);
  227. }
  228. Db::startTrans();
  229. try {
  230. $params = Form::updateFormParams(Form::CONTRACT_TYPE, $params);
  231. $params['id']=$ids;
  232. $params['owner_staff_id'] = $row['owner_staff_id'];
  233. if($params['product']){
  234. $params['product']=json_decode($params['product'],true);
  235. }
  236. $result = $this->model::updateContract($params);
  237. Db::commit();
  238. } catch (Exception $e) {
  239. Db::rollback();
  240. $this->error($e->getMessage());
  241. }
  242. $this->success('修改成功');
  243. }
  244. $row = $this->model->where($map)->with(['customer','contacts','business'])->find();
  245. if(empty($row)){
  246. $this->error('信息不存在');
  247. }
  248. $row = $row->toArray();
  249. $row = ContractOther::getOther($row);
  250. $product=ContractProduct::where(['contract_id'=>$ids])->with(['productinfo'])->select();
  251. foreach ($product as $k=>$v){
  252. if($v['productinfo']){
  253. $v['product_name']=$v['productinfo']['name'];
  254. $v['cost_price']=$v['productinfo']['cost_price'];
  255. $v['type']=$v['productinfo']['type'];
  256. if($v['productinfo']['goods']){
  257. $v['goods_name']=$v['productinfo']['goods']['name'];
  258. }
  259. }
  260. $product[$k]=$v;
  261. }
  262. $row['product']=json_encode($product);
  263. $row['ratios']=json_decode($row['ratios'],true);
  264. $flow= Flow::getsteplist(Flow::CONTRACT_STATUS);
  265. if (empty($flow)) {
  266. $this->error('无可用审批流,请联系管理员','qingdong/work/flow');
  267. }
  268. $this->assign('flow',$flow);
  269. $this->view->assign("row", $row);
  270. $this->assign('customers', Customer::getList());
  271. $this->assign('business', Business::getList());
  272. $this->assign('staffs', Staff::getList());
  273. $this->assign('staff', Staff::getStaff());
  274. $this->assign('ratio',Ratio::where(['status'=>1])->select());
  275. $this->assign('form_data', Form::getDataValue('contract',$row));
  276. $this->assign('contacts', Contacts::where(['customer_id'=>$row['customer_id']])->field('id,name')->select());
  277. return $this->view->fetch();
  278. }
  279. /**
  280. * 获取附件记录
  281. */
  282. public function get_file($ids = null) {
  283. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  284. $list = ContractFile::where(['contract_id' => $ids])->with(['file'])->field('file_id')->paginate($limit);
  285. $result = array("total" => $list->total(), "rows" => $list->items());
  286. return json($result);
  287. }
  288. /**
  289. * 合同详情
  290. */
  291. public function detail($ids = null) {
  292. $row = $this->model->where(['id' => $ids])->with([
  293. 'customer',
  294. 'contacts',
  295. 'orderStaff',
  296. 'ownerStaff',
  297. 'business'
  298. ])->find();
  299. if (empty($row)) {
  300. $this->error(__('No Results were found'));
  301. }
  302. $row=$row->toArray();
  303. $row=ContractOther::getOther($row);
  304. $row['ratios'] = json_decode($row['ratios'], true);
  305. if ($row['ratios']) {
  306. foreach ($row['ratios'] as $k => $v) {
  307. $v['staff'] = Staff::where(['id' => $v['staff_id']])->field('id,name,img,post')->find()->toArray();
  308. $v['money'] = $row['money'] * ($v['ratio'] / 100);
  309. $row['ratios'][$k] = $v;
  310. }
  311. }
  312. $row['repayment_money'] = Receivables::where(['contract_id'=>$ids])->sum('money'); //已回款
  313. $row['no_money'] = $row['money'] -$row['repayment_money'];
  314. if($row['no_money'] <= 0){
  315. $row['no_money'] = 0;
  316. }
  317. $this->assign('examine_record',ExamineRecord::getList(ExamineRecord::CONTRACT_TYPE,$ids));
  318. $this->assign('flow',Flow::getstepdetail(Flow::CONTRACT_STATUS, $ids));
  319. //跟进记录
  320. $this->assign('records', Record::getList(Record::CONTRACT_TYPE, $ids));
  321. //操作记录
  322. $log=OperationLog::getList(OperationLog::CONTRACT_TYPE, $ids);
  323. $this->assign('operation_log',$log);
  324. $this->assign('row', $row);
  325. $this->assign('ids', $ids);
  326. $this->assign('form_data', Form::getDataValue('contract',$row));
  327. $this->assignconfig("idinfo", ['id' => $ids]);
  328. return $this->view->fetch();
  329. }
  330. /**
  331. * 获取联系人select
  332. */
  333. public function get_contacts_list(){
  334. $pageSize = input('pageSize');
  335. $pageNumber = input('pageNumber');
  336. $where = [];
  337. if ($keyValue = $this->request->request("keyValue")) {
  338. $where['id'] = ['in',$keyValue];
  339. }
  340. $ids=input('ids');
  341. $name = input('name');
  342. if(!empty($name)){
  343. $where['name'] = ['like','%'.$name.'%'];
  344. }
  345. $staff = Contacts::where($where)->where(['customer_id'=>$ids])
  346. ->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
  347. return json(['list' => $staff->items(), 'total' => $staff->total()]);
  348. }
  349. /**
  350. * 获取产品明细
  351. */
  352. public function get_contract_product(){
  353. $contract_id=input('contract_id',0,'intval');
  354. if(empty($contract_id)){
  355. $this->error('参数不能为空');
  356. }
  357. $products=ContractProduct::where(['contract_id'=>$contract_id])
  358. ->with(['productinfo'])->select();
  359. foreach($products as $k=>$v){
  360. if(!$v['productinfo']['id']){
  361. unset($products[$k]);
  362. }
  363. }
  364. return json(['rows' =>$products, 'total' => count($products)]);
  365. }
  366. /**
  367. * 获取回款计划
  368. */
  369. public function get_receivables_plan($ids = null) {
  370. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  371. $list = \addons\qingdong\model\ReceivablesPlan::where([
  372. 'contract_id' => $ids
  373. ])->with(['customer'])->paginate($limit);
  374. $result = array("total" => $list->total(), "rows" => $list->items());
  375. return json($result);
  376. }
  377. /**
  378. * 获取回款记录
  379. */
  380. public function get_receivables($ids = null) {
  381. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  382. $list = \addons\qingdong\model\Receivables::where([
  383. 'contract_id' => $ids
  384. ])->with(['customer','ownerStaff'])->paginate($limit);
  385. $result = array("total" => $list->total(), "rows" => $list->items());
  386. return json($result);
  387. }
  388. /**
  389. * 获取商机关联产品
  390. */
  391. public function get_business_product(){
  392. $business_id=input('business_id');
  393. if(empty($business_id)){
  394. $this->error('参数不能为空');
  395. }
  396. $business=BusinessProduct::where(['business_id'=>$business_id])->with(['productinfo'])->select();
  397. $this->success('请求成功','',$business);
  398. }
  399. /**
  400. * 获取产品
  401. */
  402. public function get_product()
  403. {
  404. $where = [];
  405. if ($keyValue = $this->request->request("keyValue")) {
  406. $where['id'] = $keyValue;
  407. }
  408. $name = input('name');
  409. if(!empty($name)){
  410. $where['name'] = ['like','%'.$name.'%'];
  411. }
  412. $countrys = Product::where($where)->field('id,name')->order('id desc')->select();
  413. return json(['list' => $countrys, 'total' => count($countrys)]);
  414. }
  415. /**
  416. * 获取产品配置
  417. */
  418. public function get_product_part()
  419. {
  420. $where = [];
  421. if ($keyValue = $this->request->request("keyValue")) {
  422. $where['id'] = $keyValue;
  423. }
  424. $name = input('name');
  425. if(!empty($name)){
  426. $where['name'] = ['like','%'.$name.'%'];
  427. }
  428. $countrys = ProductPart::where($where)->field('id,name')->order('id desc')->select();
  429. return json(['list' => $countrys, 'total' => count($countrys)]);
  430. }
  431. /**
  432. * 获取产品价格
  433. */
  434. public function get_product_price()
  435. {
  436. $id = input('id', 0);
  437. $price = Product::where(['id' => $id])->value('price') ?? 0;
  438. $this->success('请求成功', '', ['price' => $price]);
  439. }
  440. /**
  441. * 获取审批人列表
  442. */
  443. public function getstaff(){
  444. $pageSize = input('pageSize');
  445. $pageNumber = input('pageNumber');
  446. $where = [];
  447. if ($keyValue = $this->request->request("keyValue")) {
  448. $where['id'] = ['in',$keyValue];
  449. }
  450. $name = input('name');
  451. if(!empty($name)){
  452. $where['name'] = ['like','%'.$name.'%'];
  453. }
  454. $staff = Staff::where($where)->where(['id'=>['neq',$this->_staff->id]])->field('id,name')->order('id desc')->paginate($pageSize, false, ['page' => $pageNumber]);
  455. return json(['list' => $staff->items(), 'total' => $staff->total()]);
  456. }
  457. /**
  458. * 删除
  459. */
  460. public function del($ids = "") {
  461. if (!$this->request->isPost()) {
  462. $this->error(__("Invalid parameters"));
  463. }
  464. $map['id'] = array('in', $ids);
  465. $result = $this->model->destroy($map);
  466. if (!$result) {
  467. $this->error('删除失败');
  468. }
  469. $this->success('删除成功');
  470. }
  471. /**
  472. * 导入合同
  473. * @return string|void
  474. */
  475. public function import()
  476. {
  477. set_time_limit(0);
  478. if ($this->request->isPost()) {
  479. $file = $this->request->request('file');
  480. if (!$file) {
  481. $this->error(__('Parameter %s can not be empty', 'file'));
  482. }
  483. $filePath = ROOT_PATH . 'public' . $file;
  484. if (!is_file($filePath)) {
  485. $this->error(__('No results were found'));
  486. }
  487. //实例化reader
  488. $ext = pathinfo($filePath, PATHINFO_EXTENSION);
  489. if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
  490. $this->error(__('Unknown data format'));
  491. }
  492. if ($ext === 'csv') {
  493. $file = fopen($filePath, 'r');
  494. $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
  495. $fp = fopen($filePath, "w");
  496. $n = 0;
  497. while ($line = fgets($file)) {
  498. $line = rtrim($line, "\n\r\0");
  499. $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
  500. if ($encoding != 'utf-8') {
  501. $line = mb_convert_encoding($line, 'utf-8', $encoding);
  502. }
  503. if ($n == 0 || preg_match('/^".*"$/', $line)) {
  504. fwrite($fp, $line . "\n");
  505. } else {
  506. fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
  507. }
  508. $n++;
  509. }
  510. fclose($file) || fclose($fp);
  511. $reader = new Csv();
  512. } elseif ($ext === 'xls') {
  513. $reader = new Xls();
  514. } else {
  515. $reader = new Xlsx();
  516. }
  517. if (!$PHPExcel = $reader->load($filePath)) {
  518. $this->error(__('Unknown data format'));
  519. }
  520. $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
  521. $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
  522. $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
  523. $maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
  524. //开始读取数据
  525. $fields = [];
  526. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  527. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  528. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  529. $fields[$currentRow][] = $val;
  530. if ($val instanceof RichText) {//富文本转换字符串
  531. $val = $val->__toString();
  532. }
  533. $values[] = is_null($val) ? NULL : trim($val);
  534. }
  535. }
  536. if (!isset($fields[1])) {
  537. $this->error('导入文件第一行没有数据');
  538. }
  539. $lastid = $this->model->withTrashed()->order('id desc')->value('id');
  540. $lastid = $lastid + 5;//防止重复
  541. $contractRow = [];
  542. $errorInfo = [];
  543. $fieldnames = FormField::where(['types' => FormField::CONTRACT_TYPE])->column('field', 'name');
  544. if(!$fieldnames){
  545. $this->error('请在系统管理->字段管理中保存合同管理表单生成合同导入字段');
  546. }
  547. $customerNames=Customer::where([])->column('id,owner_staff_id','name');
  548. $contacts = Contacts::where([])->field('id,name,customer_id')->select();
  549. $contacts = collection($contacts)->toArray();
  550. $contactsNames = [];
  551. foreach ($contacts as $v) {
  552. $contactsNames[$v['customer_id']][$v['name']] = $v;
  553. }
  554. $businessNames=Business::where([])->column('id','name');
  555. $staffNames=Staff::where([])->column('id','name');
  556. $fn = [];
  557. $nums=$this->model->where([])->column('num');
  558. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  559. $values = [];
  560. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  561. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  562. $values[] = is_null($val) ? '' : $val;
  563. }
  564. foreach ($values as $l) {
  565. $fn[] = $fieldnames[$l] ?? '';
  566. }
  567. }
  568. for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
  569. $values = [];
  570. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  571. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  572. if ($val instanceof RichText) {//富文本转换字符串
  573. $val = $val->__toString();
  574. }
  575. $values[] = is_null($val) ? NULL : trim($val);
  576. }
  577. $lastid++;
  578. $addContract = ['id' => $lastid];
  579. $customer=isset($customerNames[$values[0]])?$customerNames[$values[0]]:0;
  580. if(empty($customer)){
  581. $errorInfo[] = "第{$currentRow}行,客户名称不存在;";
  582. continue;
  583. }
  584. $addContract['customer_id']=$customer['id'];
  585. $addContract['owner_staff_id']=$customer['owner_staff_id'];
  586. $addContract['create_staff_id']=$customer['owner_staff_id'];
  587. $contacts = isset($contactsNames[$addContract['customer_id']])?(isset($contactsNames[$addContract['customer_id']][$values[1]]) ? $contactsNames[$addContract['customer_id']][$values[1]] : []):[];
  588. if (!empty($values[1]) && empty($contacts)) {
  589. $errorInfo[] = "第{$currentRow}行,客户签约人名称不存在;";
  590. continue;
  591. }
  592. $addContract['contacts_id']=$contacts['id']??0;
  593. $business=isset($businessNames[$values[2]])?$businessNames[$values[2]]:[];
  594. if (!empty($values[2]) && empty($business)) {
  595. $errorInfo[] = "第{$currentRow}行,商机名称不存在;";
  596. continue;
  597. }
  598. $addContract['business_id']=$business['id']??0;
  599. $orderstaff=isset($staffNames[$values[3]])?$staffNames[$values[3]]:[];
  600. if (!empty($values[3]) && empty($orderstaff)) {
  601. $errorInfo[] = "第{$currentRow}行,商机名称不存在;";
  602. continue;
  603. }
  604. $addContract['order_staff_id']=$orderstaff['id']??0;
  605. foreach ($values as $kv => $value) {
  606. if (!isset($fn[$kv]) || empty($fn[$kv])) {
  607. continue;
  608. }
  609. $addContract[$fn[$kv]] = $value;
  610. }
  611. if (empty($addContract['num'])) {
  612. $errorInfo[] = "第{$currentRow}行,合同编号不能为空;";
  613. continue;
  614. }
  615. if (in_array($addContract['num'], $nums)) {
  616. $errorInfo[] = "第{$currentRow}行,合同编号`{$addContract['num']}`已存在;";
  617. continue;
  618. }
  619. if (empty($addContract['name'])) {
  620. $errorInfo[] = "第{$currentRow}行,合同名称不能为空;";
  621. continue;
  622. }
  623. $contractRow[] = $addContract;
  624. }
  625. if (!empty($errorInfo)) {
  626. $this->error(implode(',', $errorInfo));
  627. }
  628. Db::startTrans();
  629. try {
  630. $this->model::importContract($contractRow);
  631. Db::commit();
  632. } catch (Exception $e) {
  633. Db::rollback();
  634. $this->error($e->getMessage());
  635. }
  636. $this->success('导入成功');
  637. }
  638. $this->assign('staffs', Staff::getList());
  639. return $this->view->fetch();
  640. }
  641. /**
  642. * 模板
  643. */
  644. public function template()
  645. {
  646. $title = [
  647. '客户名称',
  648. '客户签约人',
  649. '商机名称',
  650. '公司签约人',
  651. ];
  652. $contractData = Form::getDataValue(Form::CONTRACT_TYPE);
  653. foreach ($contractData as $val) {
  654. $title[] = $val['config']['label'];
  655. }
  656. $file = export_excel($title, [], '合同');
  657. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  658. header('Content-Disposition: attachment;filename=' . $file['fileName']);
  659. header('Cache-Control: max-age=0');
  660. $obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  661. // 以下内容是excel文件的信息描述信息
  662. $obj->getProperties()->setTitle('导出文件'); //设置标题
  663. $obj->setActiveSheetIndex(0);
  664. $obj->getActiveSheet()->setTitle('导出文件');
  665. /* 循环读取每个单元格的数据 */
  666. $a = 'A';
  667. $currentSheet = $obj->getActiveSheet();
  668. foreach ($title as $key => $value) {
  669. //读取工作表1
  670. // 设置第一行加粗
  671. $obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true);
  672. //这里是设置单元格的内容
  673. $currentSheet->getCell($a . '1')->setValue($value);
  674. $a++;
  675. }
  676. $PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj);
  677. $PHPWriter->save('php://output');
  678. }
  679. /**
  680. * 导出信息
  681. */
  682. public function export()
  683. {
  684. $this->request->filter(['strip_tags', 'trim']);
  685. $ids = input('ids');
  686. $isall = input('isall');
  687. $wheres = array();
  688. //导出其中几条
  689. if (isset($ids)) {
  690. $wheres['id'] = array('in', $ids);
  691. }
  692. //导出全部
  693. if (isset($isall)) {
  694. if ($isall == 3) {
  695. unset($wheres['id']);
  696. }
  697. }
  698. //0:全部 1:我负责的 2:下属负责的 3:今日待跟进 4:今日已跟进 5:从未跟进的
  699. $type = input('type',0);
  700. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  701. switch($type){
  702. case 1:
  703. $staff = Staff::info();
  704. $wheres['owner_staff_id'] = $staff->id;
  705. break;
  706. case 2:
  707. $wheres['owner_staff_id'] = array('in',Staff::getLowerStaffId());
  708. break;
  709. case 3:
  710. $start = date('Y-m-d 00:00:00');
  711. $end = date('Y-m-d 23:59:59');
  712. $record = collection(Record::where(array('relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
  713. $relationId = [];
  714. foreach($record as $k=>$v){
  715. $whereRe['id'] = array('gt',$v['id']);
  716. $whereRe['relation_id'] = $v['relation_id'];
  717. $recordData = Record::where($whereRe)->count();
  718. if($recordData == 0){
  719. $relationId[] = $v['relation_id'];
  720. }
  721. }
  722. $wheres['id'] = array('in',$relationId);
  723. $staff = Staff::info();
  724. $wheres['owner_staff_id'] = $staff->id;
  725. break;
  726. case 4:
  727. $start = date('Y-m-d 00:00:00');
  728. $end = date('Y-m-d 23:59:59');
  729. $record = collection(Record::where(array('relation_type'=>3,'next_time'=>array(array('egt',$start),array('elt',$end))))->field("id,relation_id")->select())->toArray();
  730. $relationId = [];
  731. foreach($record as $k=>$v){
  732. $whereRe['id'] = array('gt',$v['id']);
  733. $whereRe['relation_id'] = $v['relation_id'];
  734. $recordData = Record::where($whereRe)->count();
  735. if($recordData >=1){
  736. $relationId[] = $v['relation_id'];
  737. }
  738. }
  739. $wheres['id'] = array('in',$relationId);
  740. $staff = Staff::info();
  741. $wheres['owner_staff_id'] = $staff->id;
  742. break;
  743. case 5:
  744. $record = collection(Record::where(array('relation_type'=>3,'next_time'=>array('neq','')))->column('relation_id'))->toArray();
  745. $wheres['id'] = array('not in',$record);
  746. $staff = Staff::info();
  747. $wheres['owner_staff_id'] = $staff->id;
  748. break;
  749. default:
  750. $wheres['owner_staff_id'] = array('in',Staff::getMyStaffIds());
  751. break;
  752. }
  753. $list = $this->model->with([
  754. 'customer',
  755. 'orderStaff',
  756. 'contacts',
  757. 'ownerStaff','contractOther',
  758. ])->where($where)->where($wheres)->order($sort, $order)->select();
  759. $list = collection($list)->toArray();
  760. if (!$list) {
  761. $this->error('无导出数据');
  762. }
  763. $title = [
  764. '序号',
  765. '客户名称',
  766. '客户签约人',
  767. '公司签约人',
  768. '归属人',
  769. '创建时间',
  770. ];
  771. $dataValue = Form::getDataValue(Form::CONTRACT_TYPE);
  772. foreach ($dataValue as $val) {
  773. $title[] = $val['config']['label'];
  774. }
  775. foreach ($list as $k => $v) {
  776. if($v['contract_other']){//其他客户
  777. $other=$v['contract_other']['otherdata'];
  778. $other=json_decode($other,true);
  779. $v = array_merge($v, $other);
  780. }
  781. $field = array(
  782. $v['id'],
  783. $v['customer']['name'],
  784. $v['contacts']['name']??'',
  785. $v['order_staff']['name']??'',
  786. $v['owner_staff']['name']??'',
  787. $v['createtime'],
  788. );
  789. foreach ($dataValue as $val) {
  790. if ($val['component'] == 'uploadImage' || $val['component'] == 'uploadFile') {
  791. $field[] = $v[$val['id'] . '_str'] ?? '';
  792. } else {
  793. $field[] = ($v[$val['id']] ?? '');
  794. }
  795. }
  796. $data[] = $field;
  797. }
  798. $file = export_excel($title, $data, '合同');
  799. if ($file['filePath']) {
  800. $this->success('导出成功', '', $file);
  801. }
  802. $this->error('导出失败');
  803. }
  804. /**
  805. * 导入产品明细
  806. * @return string|void
  807. */
  808. public function import_product()
  809. {
  810. set_time_limit(0);
  811. if ($this->request->isPost()) {
  812. $file = $this->request->request('file');
  813. if (!$file) {
  814. $this->error(__('Parameter %s can not be empty', 'file'));
  815. }
  816. $filePath = ROOT_PATH . 'public' . $file;
  817. if (!is_file($filePath)) {
  818. $this->error(__('No results were found'));
  819. }
  820. //实例化reader
  821. $ext = pathinfo($filePath, PATHINFO_EXTENSION);
  822. if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
  823. $this->error(__('Unknown data format'));
  824. }
  825. if ($ext === 'csv') {
  826. $file = fopen($filePath, 'r');
  827. $filePath = tempnam(sys_get_temp_dir(), 'import_csv');
  828. $fp = fopen($filePath, "w");
  829. $n = 0;
  830. while ($line = fgets($file)) {
  831. $line = rtrim($line, "\n\r\0");
  832. $encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
  833. if ($encoding != 'utf-8') {
  834. $line = mb_convert_encoding($line, 'utf-8', $encoding);
  835. }
  836. if ($n == 0 || preg_match('/^".*"$/', $line)) {
  837. fwrite($fp, $line . "\n");
  838. } else {
  839. fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
  840. }
  841. $n++;
  842. }
  843. fclose($file) || fclose($fp);
  844. $reader = new Csv();
  845. } elseif ($ext === 'xls') {
  846. $reader = new Xls();
  847. } else {
  848. $reader = new Xlsx();
  849. }
  850. if (!$PHPExcel = $reader->load($filePath)) {
  851. $this->error(__('Unknown data format'));
  852. }
  853. $currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
  854. $allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
  855. $allRow = $currentSheet->getHighestRow(); //取得一共有多少行
  856. $maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
  857. //开始读取数据
  858. $fields = [];
  859. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  860. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  861. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  862. $fields[$currentRow][] = $val;
  863. if ($val instanceof RichText) {//富文本转换字符串
  864. $val = $val->__toString();
  865. }
  866. $values[] = is_null($val) ? '' : trim($val);
  867. }
  868. }
  869. if (!isset($fields[1])) {
  870. $this->error('导入文件第一行没有数据');
  871. }
  872. $lastid = ContractProduct::order('id desc')->value('id');
  873. $lastid = $lastid + 5;//防止重复
  874. $contractProductRow = [];
  875. $errorInfo = [];
  876. $contractNum=$this->model::where([])->column('id,name','num');
  877. $productName=Product::where([])->column('id,price','name');
  878. $fn = [];
  879. for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
  880. $values = [];
  881. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  882. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  883. $values[] = is_null($val) ? '' : $val;
  884. }
  885. }
  886. for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
  887. $values = [];
  888. for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
  889. $val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
  890. if ($val instanceof RichText) {//富文本转换字符串
  891. $val = $val->__toString();
  892. }
  893. $values[] = is_null($val) ? NULL : trim($val);
  894. }
  895. $lastid++;
  896. $addContractProduct = ['id' => $lastid];
  897. $contract = isset($contractNum[$values[0]]) ? $contractNum[$values[0]] : 0;
  898. if (empty($contract)) {
  899. $errorInfo[] = "第{$currentRow}行,合同编号不存在;";
  900. continue;
  901. }
  902. $product = isset($productName[$values[1]]) ? $productName[$values[1]] : 0;
  903. if (empty($product)) {
  904. $errorInfo[] = "第{$currentRow}行,产品名称不存在;";
  905. continue;
  906. }
  907. if (empty($values[2])) {
  908. $errorInfo[] = "第{$currentRow}行,产品数量不能为空;";
  909. continue;
  910. }
  911. if (empty($values[3])) {
  912. $errorInfo[] = "第{$currentRow}行,产品售价不能为空;";
  913. continue;
  914. }
  915. $addContractProduct['contract_id'] = $contract['id'];
  916. $addContractProduct['product_id'] = $product['id'];
  917. $addContractProduct['number'] = $values[2];
  918. $addContractProduct['price'] = $values[3];
  919. $contractProductRow[]=$addContractProduct;
  920. }
  921. if (!empty($errorInfo)) {
  922. $this->error(implode(',', $errorInfo));
  923. }
  924. Db::startTrans();
  925. try {
  926. ContractProduct::importProduct($contractProductRow);
  927. Db::commit();
  928. } catch (Exception $e) {
  929. Db::rollback();
  930. $this->error($e->getMessage());
  931. }
  932. $this->success('导入成功');
  933. }
  934. $this->assign('staffs', Staff::getList());
  935. return $this->view->fetch();
  936. }
  937. /**
  938. * 模板
  939. */
  940. public function template_product()
  941. {
  942. $title = [
  943. '合同编号',
  944. '商品名称',
  945. '数量',
  946. '售价',
  947. ];
  948. $file = export_excel($title, [], '产品明细');
  949. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  950. header('Content-Disposition: attachment;filename=' . $file['fileName']);
  951. header('Cache-Control: max-age=0');
  952. $obj = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
  953. // 以下内容是excel文件的信息描述信息
  954. $obj->getProperties()->setTitle('导出文件'); //设置标题
  955. $obj->setActiveSheetIndex(0);
  956. $obj->getActiveSheet()->setTitle('导出文件');
  957. /* 循环读取每个单元格的数据 */
  958. $a = 'A';
  959. $currentSheet = $obj->getActiveSheet();
  960. foreach ($title as $key => $value) {
  961. //读取工作表1
  962. // 设置第一行加粗
  963. $obj->getActiveSheet()->getStyle($a . '1')->getFont()->setBold(true);
  964. //这里是设置单元格的内容
  965. $currentSheet->getCell($a . '1')->setValue($value);
  966. $a++;
  967. }
  968. $PHPWriter = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($obj);
  969. $PHPWriter->save('php://output');
  970. }
  971. /**
  972. * 导出信息
  973. */
  974. public function export_product()
  975. {
  976. $ids = input('ids');
  977. $type = input('type');
  978. $wheres = array();
  979. //导出其中几条
  980. if (isset($ids)) {
  981. $wheres['contract_id'] = array('in', $ids);
  982. }
  983. //导出全部
  984. if (isset($type)) {
  985. if ($type == 3) {
  986. unset($wheres['contract_id']);
  987. }
  988. }
  989. $list=ContractProduct::where($wheres)->with(['contract','productinfo'])->select();
  990. $list = collection($list)->toArray();
  991. if (!$list) {
  992. $this->error('无导出数据');
  993. }
  994. $title = [
  995. '序号',
  996. '合同编号',
  997. '合同名称',
  998. '商品名称',
  999. '售价',
  1000. '批发价',
  1001. '产品',
  1002. '规格',
  1003. '数量',
  1004. ];
  1005. $data=[];
  1006. foreach ($list as $k => $v) {
  1007. $field = array(
  1008. $v['id'],
  1009. $v['contract']['num'],
  1010. $v['contract']['name'],
  1011. $v['productinfo']['name']??'',
  1012. $v['price']??'',
  1013. $v['productinfo']['cost_price']??'',
  1014. $v['productinfo']['goods']['name']??'',
  1015. $v['productinfo']['unit']??'',
  1016. $v['number']??'',
  1017. );
  1018. $data[] = $field;
  1019. }
  1020. $file = export_excel($title, $data, '产品明细');
  1021. if ($file['filePath']) {
  1022. $this->success('导出成功', '', $file);
  1023. }
  1024. $this->error('导出失败');
  1025. }
  1026. /**
  1027. * 导出word
  1028. */
  1029. public function words($ids = null)
  1030. {
  1031. if ($this->request->isPost()) {
  1032. $file = input('file', '');
  1033. $is_template=input('is_template',0);
  1034. $template_name=input('template_name','');
  1035. if (empty($file)) {
  1036. $this->error('导出模板');
  1037. }
  1038. if($is_template == 1){
  1039. if(empty($template_name)){
  1040. $this->error('模板名称不能为空');
  1041. }
  1042. $create=[
  1043. 'type'=>'contract',
  1044. 'name'=>$template_name,
  1045. 'url'=>$file
  1046. ];
  1047. $wordTemplateModel = new WordTemplate();
  1048. $wordTemplateModel->save($create);
  1049. }
  1050. $tmp = new TemplateProcessor('.' . $file);
  1051. Settings::setCompatibility(true);
  1052. Settings::setOutputEscapingEnabled(true);
  1053. $row = $this->model->where(['id'=>$ids])->with(['customer','contacts','business','orderStaff'])->find();
  1054. $row = $row->toArray();
  1055. $row = ContractOther::getOther($row);
  1056. $form = Form::getDataValue(Form::CONTRACT_TYPE);
  1057. $imgNames=[];
  1058. foreach($form as $k=>$v){
  1059. if($v['component'] == 'uploadImage'){
  1060. $imgNames[]=$v['id'];
  1061. }
  1062. }
  1063. foreach ($row as $key => $item) {
  1064. if(in_array($key,$imgNames) && $item ){
  1065. if(is_array($item)){
  1066. foreach ($item as $it){
  1067. $tmp->setImageValue($key,ltrim(parse_url($it['file_path'])['path'],'/'));
  1068. }
  1069. }else{
  1070. $fileinfo = File::where(['id'=>['in',$item]])->field('id,name,file_path,save_name')->select();
  1071. foreach ($fileinfo as $it){
  1072. $tmp->setImageValue($key,ltrim(parse_url($it['file_path'])['path'],'/'));
  1073. }
  1074. }
  1075. }else{
  1076. if(is_array($item)){
  1077. $tmp->setValue($key , '');//
  1078. continue;
  1079. }
  1080. $tmp->setValue($key , $item);//
  1081. }
  1082. }
  1083. $contractProduct=ContractProduct::where(['contract_id'=>$ids])
  1084. ->with(['productinfo'])->select();
  1085. $contractProduct=collection($contractProduct)->toArray();
  1086. $c = count($contractProduct);//总行数
  1087. // $tmp->cloneRow('product_name', $c);//复制行
  1088. // for ($i = 0; $i < $c; $i++) {
  1089. // $p=$contractProduct[$i];
  1090. // $tmp->setValue("product_name#" . ($i + 1), $p['productinfo']['name'] ?? '');//名称
  1091. // $tmp->setValue("product_unit#" . ($i + 1), $p['productinfo']['unit'] ?? '');//单位
  1092. // $tmp->setValue("product_num#" . ($i + 1), $p['productinfo']['num'] ?? '');//编码
  1093. // $tmp->setValue("product_type#" . ($i + 1), $p['productinfo']['type'] ?? '');//规格
  1094. // $tmp->setValue("product_number#" . ($i + 1), $p['number']);//数量
  1095. // $tmp->setValue("product_price#" . ($i + 1), $p['price']);//总价格
  1096. // $tmp->setValue("product_total#" . ($i + 1), $p['price'] * $p['number']);//总价格
  1097. // }
  1098. $tmp->setValue('money_big', convertAmountToCn($row['money']));
  1099. $tmp->setValue('customer_name', $row['customer']['name'] ?? '');
  1100. $tmp->setValue('contacts_name', $row['contacts']['name'] ?? '');
  1101. $tmp->setValue('business_name', $row['business']['name'] ?? '');
  1102. $tmp->setValue('order_staff_name', $row['order_staff']['name'] ?? '');
  1103. //end 配置
  1104. $filename = $row['name'];
  1105. $filepath = $filename . '.docx';
  1106. $fileurl = './uploads/' . date('Ymd') . '/';
  1107. if (!file_exists($fileurl)) {
  1108. mkdir($fileurl);
  1109. }
  1110. $tmp->saveAs($fileurl . $filepath);//另存为
  1111. $model = new File();
  1112. $data = [
  1113. 'types' => 'file',
  1114. 'name' => $filepath,
  1115. 'save_name' => $fileurl . $filepath,
  1116. 'size' => filesize($fileurl . $filepath),
  1117. 'file_path' => trim($fileurl, '.') . $filepath,
  1118. ];
  1119. $model->save($data);
  1120. $lastid = $model->id;
  1121. $file = cdnurl($model::getUrl($lastid), true);
  1122. $this->success('成功', '', ['file' => $file, 'id' => $lastid, 'filename' => $filepath]);
  1123. }
  1124. $templates=WordTemplate::where(['type'=>'contract'])->select();
  1125. $contract = Form::getDataValue(Form::CONTRACT_TYPE);
  1126. $columns = array();
  1127. $columns[] = ['key' => 'customer_name', 'name' => '客户名称'];
  1128. $columns[] = ['key' => 'contacts_name', 'name' => '联系人名称'];
  1129. $columns[] = ['key' => 'business_name', 'name' => '商机名称'];
  1130. $columns[] = ['key' => 'order_staff_name', 'name' => '公司签约人名称'];
  1131. $columns[] = ['key' => 'money_big', 'name' => '合同金额人民币大写'];
  1132. foreach ($contract as $k => $v) {
  1133. $columns[] = array(
  1134. 'key' => $v['id'],
  1135. 'name' => $v['config']['label'],
  1136. );
  1137. }
  1138. $columns[] = ['key' => 'product_name', 'name' => '产品名称'];
  1139. $columns[] = ['key' => 'product_unit', 'name' => '产品单位'];
  1140. $columns[] = ['key' => 'product_num', 'name' => '产品编码'];
  1141. $columns[] = ['key' => 'product_type', 'name' => '产品规格'];
  1142. $columns[] = ['key' => 'product_number', 'name' => '产品数量'];
  1143. $columns[] = ['key' => 'product_price', 'name' => '产品单价'];
  1144. $columns[] = ['key' => 'product_total', 'name' => '产品合计'];
  1145. $this->assign('column', $columns);
  1146. $this->assign('templates', $templates);
  1147. $this->assign('ids', $ids);
  1148. return $this->view->fetch();
  1149. }
  1150. }