Filing.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Exception;
  4. use think\facade\Db;
  5. use think\facade\Validate;
  6. //报备单
  7. class Filing extends Base
  8. {
  9. //列表
  10. public function getList()
  11. {
  12. $data = $this->request->only(['page' => 1, 'size' => 10, 'cat_id' => '', 'start_date' => '', 'end_date' => '', 'filingCode' => '', 'status' => '', 'good_name' => '', 'companyName' => '', 'companyCode' => '', 'orderCode' => '', 'supplierNo' => ''], 'post');
  13. $where = [['is_del', '=', '0']];
  14. if ($data['cat_id'] != '') $where[] = ['cat_id', '=', $data['cat_id']];
  15. if ($data['start_date'] != '' && $data['end_date'] != '') $where[] = ['addtime', 'between', [$data['start_date'] . ' 00:00:00', $data['end_date'] . ' 23:59:59']];
  16. if ($data['filingCode'] != '') $where[] = ['filingCode', 'like', '%' . $data['filingCode'] . '%'];
  17. if ($data['status'] != '') $where[] = ['status', '=', $data['status']];
  18. if ($data['good_name'] != '') $where[] = ['good_name', 'like', '%' . $data['good_name'] . '%'];
  19. if ($data['companyName'] != '') $where[] = ['companyName', 'like', '%' . $data['companyName'] . '%'];
  20. if ($data['companyCode'] != '') $where[] = ['companyCode', 'like', '%' . $data['companyCode'] . '%'];
  21. if ($data['orderCode'] != '') $where[] = ['orderCode', 'like', '%' . $data['orderCode'] . '%'];
  22. if ($data['supplierNo'] != '') $where[] = ['supplierNo', '=', $data['supplierNo']];
  23. $count = Db::name('filing')
  24. ->where($where)
  25. ->count('id');
  26. $list = Db::name('filing')
  27. ->field('id,filingCode,cat_id,good_name,num,good_img,price,expect_service,companyName,companyCode,status,addtime,"" catinfo,orderCode,cgd_charge')
  28. ->where($where)
  29. ->page($data['page'], $data['size'])
  30. ->order('id', 'desc')
  31. ->withAttr('good_img', function ($val) {
  32. return explode(',', $val);
  33. })
  34. ->select()
  35. ->toArray();
  36. $all_cat = [];
  37. foreach ($list as &$value) {
  38. if (!isset($all_cat[$value['cat_id']])) $all_cat[$value['cat_id']] = implode('/', array_column(made($value['cat_id']), 'name'));
  39. $value['catinfo'] = $all_cat[$value['cat_id']];
  40. }
  41. return json_show(0, '获取报备单列表成功', ['count' => $count, 'list' => $list]);
  42. // return FilingLogic::list($param);
  43. }
  44. //添加
  45. public function add()
  46. {
  47. $param = $this->request->only(['customerCode', 'supplierNo', 'companyName', 'num', 'is_determine_price', 'price' => 0, 'expect_service_proportion', 'expect_service', 'cgd_charge' => 0, 'brand_id', 'preservation_day', 'delivery_day', 'make_day', 'tax', 'unit_id', 'cat_id', 'spec_list' => [], 'good_name', 'origin_place', 'delivery_place', 'weight', 'supply_area', 'pay_way', 'gold_weight', 'noble_metal', 'config', 'other_config', 'remark', 'cost_desc', 'good_img'], 'post');
  48. $val = Validate::rule([
  49. 'customerCode|业务公司' => 'require|max:255',
  50. 'supplierNo|供应商' => 'require|max:255',
  51. 'companyName|客户名称' => 'require|max:255',
  52. 'num|销售数量' => 'require|number|gt:0|lt:999999999',
  53. 'is_determine_price|是否确定售价' => 'require|number|in:1,0',
  54. 'price|销售价' => 'requireIf:is_determine_price,1|float|max:99999999.99',
  55. 'expect_service_proportion|期望服务费比例' => 'require|float|between:0,100',
  56. 'expect_service|期望服务费' => 'require|float|max:99999999.99',
  57. 'cgd_charge|采购价' => 'requireIf:is_determine_price,0|float|max:99999999.99',
  58. 'brand_id|品牌' => 'require|number|gt:0',
  59. 'preservation_day|有效期' => 'require|number|max:999999999',
  60. 'delivery_day|物流时间' => 'require|number|max:999999999',
  61. 'make_day|生产工期' => 'require|number|max:999999999',
  62. 'tax|税点' => 'require|number|between:0,100',
  63. 'unit_id|单位' => 'require|number|gt:0',
  64. 'cat_id|分类' => 'require|number|gt:0',
  65. 'spec_list|规格类型' => 'array|max:100',
  66. 'good_name|商品名称' => 'require|max:255',
  67. 'origin_place|产地' => 'require|array|length:3',
  68. 'delivery_place|发货地' => 'require|array|length:3',
  69. 'weight|总重量' => 'require|float|max:99999999.99',
  70. 'supply_area|供货区域' => 'require|number|in:1,2',
  71. 'pay_way|付款方式' => 'require|number|in:0,1,2',
  72. 'remark|采购备注' => 'require|max:255',
  73. 'cost_desc|工艺说明' => 'max:255',
  74. 'good_img|商品图片' => 'require|array|max:10',
  75. ]);
  76. if (!$val->check($param)) return json_show(1004, $val->getError());
  77. //如果是贵金属的话,额外判断
  78. $cat = made($param['cat_id']);
  79. if (isset($cat[0]['id']) && $cat[0]['id'] == 6) {
  80. $val_gold = Validate::rule([
  81. 'gold_weight|贵金属重量' => 'require|float|max:99999999.99',
  82. 'noble_metal|贵金属类型' => 'require|number|in:1,2,3',
  83. 'config|配置要求' => 'require|max:255',
  84. 'other_config|其他配置要求' => 'require|max:255',
  85. ]);
  86. if (!$val_gold->check($param)) return json_show(1004, $val_gold->getError());
  87. }
  88. $val2 = Validate::rule([
  89. 'spec_id|规格id' => 'require|number|gt:0',
  90. 'spec_value_id|规格值id' => 'require|number|gt:0',
  91. ]);
  92. $all_spec = Db::name('specs')
  93. ->whereIn('id', array_column($param['spec_list'], 'spec_id'))
  94. ->column('spec_name', 'id');
  95. $all_spec_value = Db::name('spec_value')
  96. ->whereIn('id', array_column($param['spec_list'], 'spec_value_id'))
  97. ->column('spec_value', 'id');
  98. foreach ($param['spec_list'] as &$spec_list) {
  99. if (!$val2->check($spec_list)) return json_show(1004, $val2->getError());
  100. $spec_list['spec_name'] = $all_spec[$spec_list['spec_id']] ?? '';
  101. $spec_list['spec_value_name'] = $all_spec_value[$spec_list['spec_value_id']] ?? '';
  102. }
  103. if ($param['is_determine_price'] == 1) $param['cgd_charge'] = round(bcsub($param['price'], $param['expect_service'], 3), 2);//确定售价时,采购价=售价-服务费
  104. else $param['price'] = round(bcadd($param['cgd_charge'], $param['expect_service'], 3), 2);//不确定售价时,售价=采购价+服务费
  105. // $customerName = Db::name('business')
  106. // ->where(['companyNo' => $param['customerCode']])
  107. // ->value('company', '');
  108. // if ($customerName == '') return json_show(1004, '该业务公司不存在');
  109. $userCommon = new \app\admin\common\User();
  110. $names = $userCommon->handle('getCodeAndName', ['code' => [$param['customerCode'], $param['supplierNo']]]);
  111. if (!isset($names['data'][$param['customerCode']]) || $names['data'][$param['customerCode']] == '') return json_show(1004, '该业务公司不存在');
  112. if (!isset($names['data'][$param['supplierNo']]) || $names['data'][$param['supplierNo']] == '') return json_show(1004, '该供应商不存在');
  113. $rs = Db::name('filing')
  114. ->strict(false)
  115. ->insert(array_merge($param, [
  116. 'customerName' => $names['data'][$param['customerCode']],
  117. 'supplierName' => $names['data'][$param['supplierNo']],
  118. 'filingCode' => makeNo('BM'),
  119. 'service_proportion' => $param['expect_service_proportion'],//服务费比例与期望服务费比例一致
  120. 'service_charge' => $param['expect_service'],//服务费与期望服务费一致
  121. 'specinfo' => json_encode($param['spec_list']),
  122. 'send_way' => 2,
  123. 'cert_fee' => 0,
  124. 'pakge_fee' => 0,
  125. 'cost_fee' => 0,
  126. 'mark_fee' => 0,
  127. 'demo_fee' => 0,
  128. 'open_fee' => 0,
  129. 'delivery_fee' => 0,
  130. 'is_gold_price' => 0,
  131. 'is_diff' => 0,
  132. 'apply_id' => $this->uid,
  133. 'apply_name' => $this->uname,
  134. 'status' => 0,
  135. 'is_del' => 0,
  136. 'addtime' => date('Y-m-d H:i:s'),
  137. 'updatetime' => date('Y-m-d H:i:s'),
  138. 'gold_weight' => $param['gold_weight'] ?? 0,
  139. 'noble_metal' => $param['noble_metal'] ?? 0,
  140. 'config' => $param['config'] ?? '',
  141. 'other_config' => $param['other_config'] ?? '',
  142. 'good_img' => implode(',', $param['good_img']),
  143. 'origin_place' => implode(',', $param['origin_place']),
  144. 'delivery_place' => implode(',', $param['delivery_place']),
  145. ]));
  146. return $rs ? json_show(0, '创建报备单成功') : json_show(1004, '创建报备单失败');
  147. // $param['supplierNo']= $this->request->user['supplierNo'];
  148. // $param['supplierName']= $this->request->user['supplierName'];
  149. // return FilingLogic::add($param);
  150. }
  151. //详情
  152. public function detail()
  153. {
  154. $param = $this->request->only(['id' => 0], 'post', 'trim');
  155. $rs = Db::name('filing')
  156. ->alias('a')
  157. ->field('a.*,b.brand_name,d.unit unit_name,p.platform_name,"" cat_info')
  158. ->leftJoin('brand b', 'b.id=a.brand_id')
  159. ->leftJoin('unit d', 'd.id=a.unit_id')
  160. ->leftJoin('platform p', 'p.id=a.platform_id')
  161. ->where(['a.is_del' => 0, 'a.id' => $param['id']])
  162. ->withAttr('specinfo', function ($val) {
  163. return json_decode($val);
  164. })
  165. ->withAttr('good_img', function ($val) {
  166. return explode(',', $val);
  167. })->withAttr('origin_place', function ($val) {
  168. return explode(',', $val);
  169. })->withAttr('delivery_place', function ($val) {
  170. return explode(',', $val);
  171. })->withAttr('cat_info', function ($val, $da) {
  172. return made($da['cat_id']);
  173. })
  174. ->findOrEmpty();
  175. return json_show(0, '获取报备单详情成功', $rs);
  176. // return FilingLogic::detail($param);
  177. }
  178. //审核
  179. public function status()
  180. {
  181. if ($this->level != 2) return json_show(1004, '业务公司账号不能审核');
  182. $param = $this->request->only(['id', 'status', 'companyCode', 'plat_code' => '', 'service_charge', 'service_proportion', 'platform_id'], 'post');
  183. $val = Validate::rule([
  184. 'id' => 'require|number|gt:0',
  185. 'status|状态' => 'require|number|in:1,2',
  186. 'companyCode|客户' => 'require|length:18',
  187. 'service_charge|服务费' => 'require|float|egt:0|max:99999999.99',
  188. 'service_proportion|服务费比例' => 'require|float|egt:0',
  189. 'platform_id|平台id' => 'require|number|gt:0',
  190. ]);
  191. if (!$val->check($param)) return json_show(1004, $val->getError());
  192. $rs = Db::name('filing')
  193. ->field('id,status,is_determine_price,price,cgd_charge')
  194. ->where(['is_del' => 0, 'id' => $param['id']])
  195. ->whereIn('status', [0, 2])
  196. ->findOrEmpty();
  197. if (empty($rs)) return json_show(1005, '该报备单不存在或不允许审核');
  198. $userCommon = new \app\admin\common\User();
  199. $company = $userCommon->handle('cInfo', ['companyNo' => $param['companyCode']]);
  200. if (!isset($company['data'])) return json_show(1005, '该客户不存在');
  201. // $companyName = Db::name('customer_info')
  202. // ->where(['is_del' => 0, 'companyNo' => $param['companyCode']])
  203. // ->value('companyName', '');
  204. // if ($companyName == '') return json_show(1005, '该客户不存在');
  205. $tmp = Db::name('platform')
  206. ->where(['is_del' => 0, 'id' => $param['platform_id']])
  207. ->field('id')
  208. ->findOrEmpty();
  209. if (empty($tmp)) return json_show(1005, '该平台不存在');
  210. $update = array_merge($param, [
  211. 'companyName' => $company['data']['companyName'],
  212. 'updatetime' => date('Y-m-d H:i:s'),
  213. ]);
  214. if ($rs['is_determine_price'] == 1) $update['cgd_charge'] = round(bcsub($rs['price'], $param['service_charge'], 3), 2);//确定售价时,采购价=售价-服务费
  215. else $update['price'] = round(bcadd($rs['cgd_charge'], $param['service_charge'], 3), 2);//不确定售价时,售价=采购价+服务费
  216. $res = Db::name('filing')
  217. ->where(['is_del' => 0, 'id' => $param['id']])
  218. ->whereIn('status', [0, 2])
  219. ->update($update);
  220. return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
  221. // return FilingLogic::status($param);
  222. }
  223. //取消转单
  224. public function cancel()
  225. {
  226. if ($this->level == 1) return json_show(1004, '超管不允许操作');
  227. $param = $this->request->only(['id'], 'post');
  228. // $param['supplierNo'] = $this->request->user['supplierNo'];
  229. // return FilingLogic::cancel($param);
  230. $where = [
  231. ['is_del', '=', 0],
  232. ['id', '=', $param['id']],
  233. // ['supplierNo', '=', $param['supplierNo']],
  234. ['status', 'in', [0, 1, 2, 4]]
  235. ];
  236. $rs = Db::name('filing')
  237. ->field('id,status,supplierNo')
  238. ->where($where)
  239. ->findOrEmpty();
  240. if (empty($rs)) return json_show(1005, '该报备单不存在或不允许取消');
  241. //level3账号都可以操作
  242. //level2账号的话,只有供应商负责人能操作
  243. if ($this->level == 2) {
  244. $userCommon = new \app\admin\common\User();
  245. $supp = $userCommon->handle('sInfo', ['code' => $rs['supplierNo']]);
  246. if ($this->uid != $supp['data']['personid']) return json_show(1004, '只有供应商负责人才能操作');
  247. }
  248. $res = Db::name('filing')
  249. ->where($where)
  250. ->update(['status' => 5, 'updatetime' => date('Y-m-d H:i:s')]);
  251. return $res ? json_show(0, '操作成功') : json_show(1004, '操作失败');
  252. }
  253. //转单
  254. public function transfer()
  255. {
  256. if($this->level==1) return json_show(1004,'超管不允许操作');
  257. $param = $this->request->only(['id', 'addr_list'], 'post');
  258. $val = Validate::rule([
  259. 'id' => 'require|number|gt:0',
  260. 'addr_list|收货地址' => 'require|array|max:100',
  261. ]);
  262. if (!$val->check($param)) return json_show(1004, $val->getError());
  263. $val2 = Validate::rule([
  264. 'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
  265. 'contactor|联系人' => 'require|max:255',
  266. 'mobile|联系电话' => 'require|mobile',
  267. 'addr_code|收货省市区编码' => 'require|array|length:3',
  268. 'addr|详细地址' => 'require|max:255',
  269. ]);
  270. foreach ($param['addr_list'] as $addr_list) {
  271. if (!$val2->check($addr_list)) return json_show(1004, $val2->getError());
  272. }
  273. $filing = Db::name('filing')
  274. ->field(true)
  275. ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
  276. ->findOrEmpty();
  277. if (empty($filing)) return json_show(1005, '该报备单不存在或不允许转单');
  278. if (array_sum(array_column($param['addr_list'], 'receipt_quantity')) != $filing['num']) return json_show(1004, '收货地址的收货总数不符合');
  279. // $supplier = Db::name('supplier')
  280. // ->field('id,person,personid,name,code')
  281. // ->where(['code' => $filing['supplierNo']])
  282. // ->findOrEmpty();
  283. $userCommon = new \app\admin\common\User();
  284. $supplier = $userCommon->handle('sInfo', ['code' => $filing['supplierNo']]);
  285. //level3账号都可以操作
  286. //level2账号的话,只有供应商负责人能操作
  287. if (($this->level == 2) && ($this->uid != $supplier['data']['personid'])) return json_show(1004, '只有供应商负责人才能操作');
  288. $date = date('Y-m-d H:i:s');
  289. Db::startTrans();
  290. try {
  291. $order_type = 4;//报备商品
  292. $order_source = 7;//报备转单
  293. $spuCode = makeNo('SKU');
  294. //商品表
  295. Db::name('good_zixun')
  296. ->insert([
  297. 'spuCode' => $spuCode,
  298. 'good_name' => $filing['good_name'],
  299. 'brand_id' => $filing['brand_id'],
  300. 'cat_id' => $filing['cat_id'],
  301. 'good_unit' => $filing['unit_id'],
  302. 'good_type' => 0,
  303. 'moq' => 1,
  304. 'customized' => $filing['make_day'],
  305. 'tax' => $filing['tax'],
  306. 'platform_id' => $filing['platform_id'],
  307. 'supplierNo' => $filing['supplierNo'],
  308. 'is_auth' => 0,
  309. 'craft_desc' => $filing['good_name'],
  310. 'good_remark' => '',
  311. 'good_img' => $filing['good_img'],
  312. 'good_thumb_img' => '',
  313. 'good_info_img' => '',
  314. 'status' => 1,
  315. 'createrid' => $filing['apply_id'],
  316. 'creater' => $filing['apply_name'],
  317. 'is_del' => 0,
  318. 'addtime' => $date,
  319. 'updatetime' => $date,
  320. 'specinfo' => $filing['specinfo'],
  321. 'work_day' => $filing['make_day'],
  322. 'noble_metal' => $filing['noble_metal'],
  323. 'is_gold_price' => $filing['is_gold_price'],
  324. 'good_weight' => $filing['gold_weight'],
  325. 'config' => $filing['config'],
  326. 'other_config' => $filing['other_config'],
  327. 'weight' => $filing['weight'],
  328. 'supply_area' => $filing['supply_area'],
  329. 'is_diff' => $filing['is_diff'],
  330. 'pay_way' => $filing['pay_way'],
  331. 'send_way' => $filing['send_way'],
  332. 'companyNo' => $filing['customerCode'],
  333. 'proof_type' => '',
  334. 'proof_url' => '',
  335. 'order_type' => $order_type
  336. ]);
  337. $orderCode = makeNo('QR');
  338. //订单表
  339. //sale
  340. $sale_id = Db::name('sale')->insertGetId([
  341. 'orderCode' => $orderCode,
  342. 'apply_id' => $filing['apply_id'],
  343. 'apply_name' => $filing['apply_name'],
  344. 'order_type' => $order_type,//报备商品
  345. 'order_source' => $order_source,//报备转单
  346. 'platform_id' => $filing['platform_id'],
  347. 'good_code' => $spuCode,
  348. 'skuCode' => '',
  349. 'cat_id' => $filing['cat_id'],
  350. 'good_name' => $filing['good_name'],
  351. 'good_num' => $filing['num'],
  352. 'good_type' => 1,
  353. 'origin_price' => $filing['cgd_charge'],
  354. 'sale_price' => $filing['price'],
  355. 'total_price' => round(bcmul($filing['price'], $filing['num'], 3), 2),
  356. 'post_fee' => 0,
  357. 'is_diff' => $filing['is_diff'],
  358. 'is_activity' => 0,
  359. 'activity_code' => '',
  360. 'is_stock' => 0,
  361. 'customer_code' => $filing['companyCode'],
  362. 'supplierNo' => $filing['customerCode'],
  363. 'zxNo' => '',
  364. 'platform_order' => '',
  365. 'send_num' => 0,
  366. 'wsend_num' => $filing['num'],
  367. 'th_num' => 0,
  368. 'th_fee' => 0,
  369. 'send_status' => 1,
  370. 'send_type' => 1,//直接发货
  371. 'remark' => '',
  372. 'status' => 0,
  373. 'is_del' => 0,
  374. 'proof_id' => 0,
  375. 'other_orderNo' => '',
  376. 'workNo' => '',
  377. 'poNo' => '',
  378. 'use_order' => 0,
  379. 'good_weight' => 0,
  380. 'gold_price' => 0,
  381. 'cost_price' => $filing['cost_fee'],
  382. 'diff_weight' => 0,
  383. 'diff_fee' => 0,
  384. 'returnCode' => '',
  385. 'addtime' => $date,
  386. 'updatetime' => $date,
  387. 'cgderid' => $supplier['data']['personid'],
  388. 'cgder' => $supplier['data']['person'],
  389. 'good_createrid' => $filing['apply_id'],
  390. 'good_creater' => $filing['apply_name'],
  391. ]);
  392. //仓库
  393. $wsm = Db::name('warehouse_info')
  394. ->field('id,wsm_code')
  395. ->where(['supplierNo' => $filing['supplierNo'], 'companyNo' => $filing['customerCode'], 'is_del' => 0])
  396. ->findOrEmpty();
  397. if (empty($wsm)) {
  398. $wsm_code = makeNo('WSM');
  399. Db::name('warehouse_info')->insert([
  400. 'wsm_code' => $wsm_code,
  401. 'name' => $supplier['data']['name'],
  402. 'wsm_type' => 2,
  403. 'supplierNo' => $supplier['data']['code'],
  404. 'addr' => '',
  405. 'addrs_code' => '',
  406. 'contactor' => 0,
  407. 'contactor_name' => 0,
  408. 'mobile' => '',
  409. 'position' => '',
  410. 'companyNo' => $filing['supplierNo'],
  411. 'status' => 1,
  412. 'is_del' => 0,
  413. 'addtime' => $date,
  414. 'updatetime' => $date,
  415. ]);
  416. } else $wsm_code = $wsm['wsm_code'];
  417. //采购单
  418. $cgdCode = makeNo('CG');
  419. Db::name('purchease_order')->insert([
  420. 'cgdNo' => $cgdCode,
  421. 'bkcode' => '',
  422. 'wsm_code' => $wsm_code,
  423. 'cgder' => $supplier['data']['person'],
  424. 'cgder_id' => $supplier['data']['personid'],
  425. 'spuCode' => $spuCode,
  426. 'good_name' => $filing['good_name'],
  427. 'good_num' => $filing['num'],
  428. 'good_price' => $filing['cgd_charge'],
  429. 'total_fee' => round(bcmul($filing['cgd_charge'], $filing['num']), 2),
  430. 'pakge_fee' => $filing['pakge_fee'],
  431. 'cert_fee' => $filing['cert_fee'],
  432. 'open_fee' => $filing['open_fee'],
  433. 'delivery_fee' => $filing['delivery_fee'],
  434. 'mark_fee' => $filing['mark_fee'],
  435. 'demo_fee' => $filing['demo_fee'],
  436. 'diff_weight' => '0',
  437. 'diff_fee' => '0',
  438. 'gold_price' => '0',
  439. 'supplierNo' => $filing['supplierNo'],
  440. 'supplier_name' => $filing['supplierName'],
  441. 'companyNo' => $filing['customerCode'],
  442. 'send_status' => 1,
  443. 'send_num' => '0',
  444. 'wsend_num' => $filing['num'],
  445. 'remark' => '',
  446. 'status' => 0,
  447. 'lasttime' => $date,
  448. 'is_del' => 0,
  449. 'order_type' => $order_type,
  450. 'order_source' => $order_source,
  451. 'good_type' => 1,
  452. 'addtime' => $date,
  453. 'updatetime' => $date,
  454. 'good_createrid' => $filing['apply_id'],
  455. 'good_creater' => $filing['apply_name'],
  456. ]);
  457. //台账
  458. $standing_bood_data = [
  459. 'standBookNo' => makeNo('IO'),
  460. 'orderCode' => $orderCode,
  461. 'sale_id' => $sale_id,
  462. 'customer_code' => $filing['companyCode'],
  463. 'supplierNo' => $filing['supplierNo'],
  464. 'order_type' => $order_type,
  465. 'order_source' => $order_source,
  466. 'spuCode' => $spuCode,
  467. 'addtime' => $date,
  468. 'updatetime' => $date,
  469. 'cgdNo' => $cgdCode,
  470. ];
  471. $i = 0;
  472. $order_send_insert = [];
  473. foreach ($param['addr_list'] as $addr) {
  474. //地址addr
  475. $addrid = Db::name('order_addr')->insertGetId([
  476. 'orderCode' => $orderCode,
  477. 'addr' => $addr['addr'],
  478. 'addr_code' => implode(',', $addr['addr_code']),
  479. 'contactor' => $addr['contactor'],
  480. 'mobile' => $addr['mobile'],
  481. 'customer_code' => $filing['companyCode'],
  482. 'post_fee' => 0,
  483. 'receipt_quantity' => $addr['receipt_quantity'],
  484. 'is_del' => 0,
  485. 'addtime' => $date,
  486. 'updatetime' => $date,
  487. ]);
  488. //发货单
  489. $outCode = makeNo('DF');
  490. //改变编码规则,将原来的编码后两位换成序列号
  491. //str_pad字符串填充
  492. $outCode = substr($outCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  493. Db::name('order_out')->insert([
  494. 'orderCode' => $orderCode,
  495. 'outCode' => $outCode,
  496. 'apply_id' => $this->uid,
  497. 'apply_name' => $this->uname,
  498. 'addrid' => $addrid,
  499. 'post_name' => '',
  500. 'post_code' => '',
  501. 'post_fee' => 0,
  502. 'sendtime' => $date,
  503. 'send_num' => $addr['receipt_quantity'],
  504. 'check_num' => 0,
  505. 'error_num' => 0,
  506. 'wsm_code' => '',
  507. 'order_type' => $order_type,
  508. 'status' => 0,
  509. 'addtime' => $date,
  510. 'updatetime' => $date,
  511. ]);
  512. $standing_bood_data['outCode'][] = $outCode;
  513. $order_send_insert[] = [
  514. 'cgdNo' => $cgdCode,
  515. 'outCode' => $outCode,
  516. 'send_num' => $addr['receipt_quantity'],
  517. 'bnCode' => '',
  518. 'status' => 1,
  519. 'addtime' => $date,
  520. 'updatetime' => $date,
  521. ];
  522. $i++;
  523. }
  524. //更新报备单
  525. Db::name('filing')
  526. ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
  527. ->update(['status' => 3, 'updatetime' => $date, 'orderCode' => $orderCode, 'reason' => '']);
  528. //待办已办先不处理
  529. //关联表
  530. Db::name('order_num')
  531. ->insert([
  532. 'orderCode' => $orderCode,
  533. 'cgdNo' => $cgdCode,
  534. 'spuCode' => $spuCode,
  535. 'companyNo' => $filing['customerCode'],
  536. 'good_num' => $filing['num'],
  537. 'wsend_num' => $filing['num'],
  538. 'send_num' => 0,
  539. 'wait_num' => $filing['num'],
  540. ]);
  541. if ($order_send_insert) Db::name('order_send')->insertAll($order_send_insert);
  542. //处理台账
  543. if (isset($standing_bood_data['outCode']) && is_array($standing_bood_data['outCode'])) $standing_bood_data['outCode'] = implode(',', $standing_bood_data['outCode']);
  544. Db::name('standing_book')->insert($standing_bood_data);
  545. Db::commit();
  546. return json_show(0, '转单成功');
  547. } catch (Exception $exception) {
  548. Db::rollback();
  549. Db::name('filing')
  550. ->where(['is_del' => 0, 'id' => $param['id'], 'status' => 2])
  551. ->update(['status' => 4, 'updatetime' => $date, 'reason' => $exception->getMessage()]);
  552. return json_show(1005, '转单失败,' . $exception->getMessage());
  553. }
  554. // $param['supplierNo'] = $this->request->user['supplierNo'];
  555. // return FilingLogic::transfer($param);
  556. }
  557. //订单录入
  558. public function orderAdd()
  559. {
  560. $param = $this->request->param([
  561. "companyNo" => '',
  562. "poCode" => "",
  563. "workCode" => "",
  564. "khNo" => "",
  565. "qrdType" => 3,
  566. "goodName" => "",
  567. "tax" => "",
  568. "goodNum" => "",
  569. "goodPrice" => "",
  570. "goodUnit" => "",
  571. "mobile" => "",
  572. "addr" => "",
  573. "addr_code" => "",
  574. "contactor" => "",
  575. "buyerid" => "",
  576. "buyer_name" => "",
  577. "sendtime" => "",
  578. "cat_id" => '',
  579. "supplierNo" => "",
  580. "cgd_tax" => "",
  581. "platform_id" => "0",
  582. ], "post", "trim");
  583. $valid = Validate::rule([
  584. "companyNo|业务公司编号" => "require|max:255|min:1",
  585. "supplierNo|业务公司编号" => "require|max:255|min:1",
  586. "poCode|PO编号" => "require|max:255|min:1",
  587. "khNo|客户公司编号" => "require|max:255|min:1",
  588. "qrdType|订单类型" => "require|number|in:1,2,3",
  589. "goodName|商品名称" => "require|max:255|min:1",
  590. "goodUnit|商品单位" => "require|number|gt:0",
  591. "tax|税率" => "require|number|gt:0",
  592. "goodNum|商品数量" => "require|number|gt:0",
  593. "goodPrice|商品单价" => "require|float|gt:0",
  594. "mobile|联系人电话" => "require|number|mobile",
  595. "contactor|联系人" => "require|max:255|min:1",
  596. "addr|收货地址" => "require|max:255|min:1",
  597. "buyerid|采购员ID" => "require|number|gt:0",
  598. "buyer_name|采购员" => "require|max:255|min:1",
  599. "sendtime|发货时间" => "require|date",
  600. "cat_id|商品分类id" => "require|number|gt:0",
  601. "cgd_tax|采购毛利率" => "require|float|gt:0",
  602. "platform_id|平台" => "require|number"
  603. ]);
  604. if ($valid->check($param) == false) return error_show(1004, $valid->getError());
  605. $qrdcode = makeNo("QR");
  606. $cgddcode = makeNo("CG");
  607. $goodCode = makeNo("SKU");
  608. $userCommon = new \app\admin\common\User();
  609. $tmp = $userCommon->handle('getCodeAndName',['code'=>[$param['khNo'],$param['supplierNo'],$param['companyNo']]]);
  610. if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
  611. if(!isset($tmp['data'][$param['khNo']])) return json_show(1004, "未找到客户数据");
  612. if(!isset($tmp['data'][$param['supplierNo']])) return json_show(1004, "未找到平台供应商数据");
  613. if(!isset($tmp['data'][$param['companyNo']])) return json_show(1004, "未找到平台业务公司数据");
  614. if($tmp['data'][$param['supplierNo']] == $tmp['data'][$param['companyNo']]) return json_show(1004,'供应商和业务公司不能为同一家公司');
  615. // $customer = Db::name("customer_info")->where('companyNo', "=", $param['khNo'])->find();
  616. // if ($customer == false) return error_show(1004, "客户信息未找到");
  617. // $supplierName = Db::name("supplier")->where('code', "=", $param['supplierNo'])->value("name", "");
  618. // if ($supplierName == '') return error_show(1004, "供应商信息未找到");
  619. // $companyName = Db::name("supplier")->where('code', "=", $param['companyNo'])->value("name", "");
  620. // if ($companyName == '') return error_show(1004, "业务公司信息未找到");
  621. // if ($param['platform_id'] != 0) {
  622. $payinfo = Db::name("platform")->where(["id"=> $param['platform_id'],"is_del"=>0])->findOrEmpty();
  623. if (empty($payinfo)) return error_show(1004, "平台信息未找到");
  624. if ($payinfo['status'] != 1) return error_show(1004, "平台信息已禁用");
  625. if($payinfo['is_select_pay_rate']==1){
  626. $supplierArr = Db::name("platform_pay_rate")->where(["platform_id" => $param['platform_id'], "status" => 1, "is_del" => 0])->column("companyNo");
  627. if (in_array($param['companyNo'], $supplierArr)) return error_show(1004, "平台支付渠道含有该业务公司,平台无法使用!");
  628. }
  629. // }
  630. $param["cgd_tax"] = $param["cgd_tax"] / 100;
  631. $cgdPrice = round($param['goodPrice'] * (1 - $param['cgd_tax']), 2);
  632. $qrddata = [
  633. "orderCode" => $qrdcode,
  634. "apply_id" => $this->uid,
  635. "apply_name" => $this->uname,
  636. "order_type" => $param['qrdType'],
  637. "order_source" => 9,
  638. "platform_id" => $param['platform_id'],
  639. "good_code" => $goodCode,
  640. "skuCode" => '',
  641. "cat_id" => $param['cat_id'],
  642. "good_name" => $param['goodName'],
  643. "good_num" => $param['goodNum'],
  644. "good_type" => 1,
  645. "origin_price" => $cgdPrice,
  646. "sale_price" => $param['goodPrice'],
  647. "total_price" => round($param['goodPrice'] * $param['goodNum'], 2),
  648. "post_fee" => 0,
  649. "is_diff" => 0,
  650. "is_activity" => 0,
  651. "activity_code" => '',
  652. "is_stock" => 0,
  653. "arrive_time" => $param['sendtime'],
  654. "customer_code" => $param['khNo'],
  655. "supplierNo" => $param['companyNo'],
  656. "platform_order" => $param['poCode'],
  657. "send_num" => $param['goodNum'],
  658. "wsend_num" => 0,
  659. "send_status" => 3,
  660. "send_type" => 1,
  661. "status" => 2,
  662. "is_del" => 0,
  663. "pay_id" => 0,
  664. "workNo" => $param['workCode'],
  665. "addtime" => date("Y-m-d H:i:s"),
  666. "updatetime" => date("Y-m-d H:i:s"),
  667. "cgderid" => $param['buyerid'],
  668. "cgder" => $param['buyer_name'],
  669. "good_createrid" => $this->uid,
  670. "good_creater" => $this->uname
  671. ];
  672. $orderCgd = [
  673. "orderCode" => $qrdcode,
  674. "cgdNo" => $cgddcode,
  675. "spuCode" => $goodCode,
  676. "good_num" => $param['goodNum'],
  677. "wsend_num" => 0,
  678. "send_num" => $param['goodNum'],
  679. "wait_num" => 0
  680. ];
  681. $cgddata = [
  682. "cgdNo" => $cgddcode,
  683. "bkcode" => '',
  684. "wsm_code" => "",
  685. "cgder_id" => $param['buyerid'],
  686. 'cgder' => $param['buyer_name'],
  687. "spuCode" => $goodCode,
  688. "good_name" => $param['goodName'],
  689. "good_num" => $param['goodNum'],
  690. "good_price" => $cgdPrice,
  691. "total_fee" => round($cgdPrice * $param['goodNum'], 2),
  692. "supplierNo" => $param['supplierNo'],
  693. "supplier_name" =>$tmp['data'][$param['supplierNo']],
  694. "companyNo" => $param['companyNo'],
  695. "send_status" => 3,
  696. "send_num" => $param['goodNum'],
  697. "wsend_num" => 0,
  698. "status" => 3,
  699. "lasttime" => date("Y-m-d H:i:s"),
  700. "order_type" => $param['qrdType'],
  701. "order_source" => 9,
  702. "addtime" => date("Y-m-d H:i:s"),
  703. "updatetime" => date("Y-m-d H:i:s"),
  704. "good_createrid" => $this->uid,
  705. "good_creater" => $this->uname,
  706. ];
  707. $goodinfo = [
  708. "spuCode" => $goodCode,
  709. "good_name" => $param['goodName'],
  710. "brand_id" => 0,
  711. "cat_id" => $param['cat_id'],
  712. "good_unit" => $param['goodUnit'],
  713. "good_type" => 1,
  714. "moq" => 1,
  715. "customized" => 0,
  716. "platform_id" => $param['platform_id'],
  717. "tax" => $param['tax'],
  718. "supplierNo" => $param['supplierNo'],
  719. "is_auth" => 1,
  720. "craft_desc" => '',
  721. "good_remark" => '',
  722. "good_img" => '',
  723. "good_thumb_img" => '',
  724. "good_info_img" => '',
  725. "createrid" => $this->uid,
  726. "creater" => $this->uname,
  727. "specinfo" => '',
  728. "work_day" => 0,
  729. "noble_metal" => 0,
  730. "good_weight" => 0,
  731. "config" => "",
  732. "weight" => 0,
  733. "supply_area" => 0,
  734. "is_diff" => 0,
  735. "pay_way" => 0,
  736. "send_way" => 0,
  737. "companyNo" => $param['companyNo'],
  738. "addtime" => date("Y-m-d H:i:s"),
  739. "updatetime" => date("Y-m-d H:i:s"),
  740. ];
  741. $orderAddr = [
  742. "orderCode" => $qrdcode,
  743. "addr" => $param['addr'],
  744. "addr_code" => $param['addr_code'],
  745. "contactor" => $param['contactor'],
  746. "mobile" => $param['mobile'],
  747. "arrive_time" => $param['sendtime'],
  748. "customer_code" => $param['khNo'],
  749. "receipt_quantity" => $param['goodNum'],
  750. "addtime" => date("Y-m-d H:i:s"),
  751. "updatetime" => date("Y-m-d H:i:s"),
  752. ];
  753. Db::startTrans();
  754. try {
  755. $qrd = Db::name("sale")->insert($qrddata);
  756. if ($qrd == false) throw new Exception("销售单生成失败");
  757. $qrd = Db::name("order_num")->insert($orderCgd);
  758. if ($qrd == false) throw new Exception("销售单采购管联生成失败");
  759. $qrd = Db::name("purchease_order")->insert($cgddata);
  760. if ($qrd == false) throw new Exception("采购单生成失败");
  761. $qrd = Db::name("good_zixun")->insert($goodinfo);
  762. if ($qrd == false) throw new Exception("商品信息录入生成失败");
  763. $qrd = Db::name("order_addr")->insert($orderAddr);
  764. if ($qrd == false) throw new Exception("销售单地址生成失败");
  765. // if ($param['pay_id'] != 0) {
  766. // pay_log($param['pay_id'], $param['companyNo'], $qrdcode);
  767. // }
  768. Db::commit();
  769. return app_show(0, '订单生成成功');
  770. } catch (\Exception $exception) {
  771. Db::rollback();
  772. return error_show(1004, $exception->getMessage());
  773. }
  774. }
  775. public function orderInfo()
  776. {
  777. $param = $this->request->param(["orderCode"], "post", "trim");
  778. if ($param['orderCode'] == '') return error_show(1004, "订单编号不能为空");
  779. $saleinfo = Db::name("sale")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  780. if (empty($saleinfo)) return error_show(1004, "销售单不存在");
  781. if ($saleinfo['order_source'] != 9) return error_show(1004, "销售单来源不是网络录入");
  782. $cgd = Db::name("purchease_order")->alias("a")
  783. ->leftJoin("order_num b", "a.cgdNo=b.cgdNo")
  784. ->where(["b.orderCode" => $param['orderCode']])
  785. ->field("a.*")
  786. ->findOrEmpty();
  787. if (empty($cgd)) return error_show(1004, "采购单不存在");
  788. $goodinfo = Db::name("good_zixun")->where(["spuCode" => $saleinfo['good_code']])->findOrEmpty();
  789. if (empty($goodinfo)) return error_show(1004, "商品信息不存在");
  790. $addr = Db::name("order_addr")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  791. if (empty($addr)) return error_show(1004, "地址信息不存在");
  792. $addinfo = $addr['addr_code'] != '' ? json_decode($addr['addr_code'], true) ?? $addr['addr_code'] : '';
  793. if (is_string($addinfo) && $addinfo != '') {
  794. $addinfo = ["provice_code" => '', "city_code" => '', "area_code" => ''];
  795. list($addinfo['provice_code'], $addinfo['city_code'], $addinfo['area_code']) = explode(",", $addr['addr_code']);
  796. }
  797. $platform = Db::name("platform")->where(["id" => $saleinfo['platform_id']])->field("platform_name,pay_title")
  798. ->findOrEmpty();
  799. $userCommon = new \app\admin\common\User();
  800. $names = $userCommon->handle('getCodeAndName', ['code' => [$saleinfo['supplierNo'], $saleinfo['customer_code']]]);
  801. $data = [
  802. "orderCode" => $saleinfo['orderCode'],
  803. "companyNo" => $saleinfo['supplierNo'],
  804. "companyName" => $names['data'][$saleinfo['supplierNo']] ?? '',//Db::name("supplier")->where(["code" => $saleinfo['supplierNo']])->value("name", ''),
  805. "poCode" => $saleinfo['platform_order'],
  806. "workCode" => $saleinfo['workNo'],
  807. "platform_id" => $saleinfo['platform_id'],
  808. "platform_name" =>$platform['platform_name']??"",
  809. "khNo" => $saleinfo['customer_code'],
  810. "khName" => $names['data'][$saleinfo['customer_code']] ?? '',//Db::name("customer_info")->where(["companyNo" => $saleinfo['customer_code']])->value("companyName", ''),
  811. "qrdType" => $saleinfo['order_type'],
  812. "goodName" => $saleinfo['good_name'],
  813. "tax" => $goodinfo['tax'],
  814. "goodUnit" => $goodinfo['good_unit'],
  815. "unitName" => Db::name("unit")->where(["id" => $goodinfo['good_unit']])->value("unit", ""),
  816. "goodNum" => $saleinfo['good_num'],
  817. "goodPrice" => $saleinfo['sale_price'],
  818. "mobile" => $addr['mobile'],
  819. "addr" => $addr['addr'],
  820. "addr_cn" => GetAddr(json_encode($addinfo)),
  821. "addr_code" => $addr['addr_code'],
  822. "contactor" => $addr['contactor'],
  823. "buyerid" => $saleinfo['cgderid'],
  824. "buyer_name" => $saleinfo['cgder'],
  825. "sendtime" => $saleinfo['arrive_time'],
  826. "cat_id" => made($saleinfo['cat_id']),
  827. "cat_name" => Db::name("cat")->where(["id" => $saleinfo['cat_id']])->value("cat_name", ''),
  828. "supplierNo" => $cgd['supplierNo'],
  829. "supplierNanme" => $cgd['supplier_name'],
  830. "cgd_tax" => round(($saleinfo['sale_price'] - $saleinfo['origin_price']) / $saleinfo['sale_price'], 4) * 100,
  831. "pay_id" => $saleinfo['pay_id'],
  832. "pay_name" =>$platform['pay_title']??"",
  833. ];
  834. return app_show(0, "获取成功", $data);
  835. }
  836. public function orderEdit()
  837. {
  838. $param = $this->request->param([
  839. "orderCode" => "",
  840. // "companyNo" => '',
  841. "poCode" => "",
  842. "workCode" => "",
  843. // "khNo" => "",
  844. "tax" => "",
  845. "goodUnit" => "",
  846. "mobile" => "",
  847. "addr" => "",
  848. "addr_code" => "",
  849. "contactor" => "",
  850. "buyerid" => "",
  851. "buyer_name" => "",
  852. "sendtime" => "",
  853. "supplierNo" => "",
  854. "cgd_tax" => ""
  855. ], "post", "trim");
  856. $valid = Validate::rule([
  857. "orderCode|销售单号" => "require|max:255",
  858. // "companyNo|业务公司编号"=>"require|max:255|min:1",
  859. "supplierNo|供应商公司编号" => "require|max:255|min:1",
  860. "poCode|PO编号" => "require|max:255|min:1",
  861. // "workCode|业务编号"=>"require|max:255|min:1",
  862. // "khNo|客户公司编号"=>"require|max:255|min:1",
  863. "mobile|联系人电话" => "require|number|mobile",
  864. "goodUnit|商品单位" => "require|number|gt:0",
  865. "contactor|联系人" => "require|max:255|min:1",
  866. "addr|收货地址" => "require|max:255|min:1",
  867. "addr_code|收货省市区" => "require|max:255|min:1",
  868. "buyerid|采购员ID" => "require|number|gt:0",
  869. "buyer_name|采购员" => "require|max:255|min:1",
  870. "sendtime|发货时间" => "require|date",
  871. "tax|商品利率" => "require|number",
  872. "cgd_tax|采购毛利率" => "require|float|gt:0",
  873. ]);
  874. if ($valid->check($param) == false) return error_show(1004, $valid->getError());
  875. $param["cgd_tax"] = $param["cgd_tax"] / 100;
  876. $saleinfo = Db::name("sale")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  877. if (empty($saleinfo)) return error_show(1004, "销售单不存在");
  878. if ($saleinfo['order_source'] != 9) return error_show(1004, "销售单来源不是网络录入");
  879. $cgd = Db::name("purchease_order")->alias("a")
  880. ->leftJoin("order_num b", "a.cgdNo=b.cgdNo")
  881. ->where(["b.orderCode" => $param['orderCode']])
  882. ->field("a.*")
  883. ->findOrEmpty();
  884. if (empty($cgd)) return error_show(1004, "采购单不存在");
  885. $userCommon = new \app\admin\common\User();
  886. $tmp = $userCommon->handle('getCodeAndName',['code'=>[$param['supplierNo'],$cgd['companyNo']]]);
  887. if(!isset($tmp['code']) || $tmp['code']!=0) return json_show($tmp['code'],$tmp['message'],$tmp['data']);
  888. // if(!isset($tmp['data'][$param['khNo']])) return json_show(1004, "未找到客户数据");
  889. if(!isset($tmp['data'][$param['supplierNo']])) return json_show(1004, "未找到平台供应商数据");
  890. // if(!isset($tmp['data'][$param['companyNo']])) return json_show(1004, "未找到平台业务公司数据");
  891. if ($tmp['data'][$param['supplierNo']] == $tmp['data'][$param['companyNo']]) return json_show(1004, '供应商和业务公司不能为同一家公司');
  892. $good = Db::name("good_zixun")->where(["spuCode" => $saleinfo['good_code']])->findOrEmpty();
  893. if (empty($good)) return error_show(1004, "商品信息不存在");
  894. $addr = Db::name("order_addr")->where(["orderCode" => $param['orderCode']])->findOrEmpty();
  895. if (empty($addr)) return error_show(1004, "地址信息不存在");
  896. $cgdPrice = round($saleinfo['sale_price'] * (1 - $param['cgd_tax']), 2);
  897. // if ($saleinfo['platform_id'] != 0) {
  898. // $supplierArr = Db::name("platform_pay_rate")->where(["platform_id" => $param['platform_id'], "status" => 1, "is_del" => 0])->column("companyNo");
  899. // if (in_array($param['companyNo'], $supplierArr)) return error_show(1004, "平台支付渠道含有该业务公司,平台无法使用!");
  900. // }
  901. $qrddata = [
  902. "origin_price" => $cgdPrice,
  903. "arrive_time" => $param['sendtime'],
  904. // "customer_code"=>$param['khNo'],
  905. // "supplierNo"=>$param['companyNo'],
  906. "platform_order" => $param['poCode'],
  907. "workNo" => $param['workCode'],
  908. "updatetime" => date("Y-m-d H:i:s"),
  909. "cgderid" => $param['buyerid'],
  910. "cgder" => $param['buyer_name']
  911. ];
  912. $cgddata = [
  913. "cgder_id" => $param['buyerid'],
  914. 'cgder' => $param['buyerid'],
  915. "good_price" => $cgdPrice,
  916. "total_fee" => round($cgdPrice * $saleinfo['good_num'], 2),
  917. "supplierNo" => $param['supplierNo'],
  918. "supplier_name" => $tmp['data'][$param['supplierNo']],
  919. // "companyNo"=>$param['companyNo'],
  920. "updatetime" => date("Y-m-d H:i:s"),
  921. ];
  922. $goodinfo = [
  923. "good_unit" => $param['goodUnit'],
  924. "tax" => $param['tax'],
  925. "supplierNo" => $param['supplierNo'],
  926. // "companyNo" => $param['companyNo'],
  927. "updatetime" => date("Y-m-d H:i:s"),
  928. ];
  929. $orderAddr = [
  930. "addr" => $param['addr'],
  931. "addr_code" => $param['addr_code'],
  932. "contactor" => $param['contactor'],
  933. "mobile" => $param['mobile'],
  934. "arrive_time" => $param['sendtime'],
  935. // "customer_code" => $param['khNo'],
  936. "updatetime" => date("Y-m-d H:i:s"),
  937. ];
  938. Db::startTrans();
  939. try {
  940. $qrd = Db::name("sale")->where($saleinfo)->update($qrddata);
  941. if ($qrd == false) throw new Exception("销售单更新失败");
  942. $qrd = Db::name("purchease_order")->where($cgd)->update($cgddata);
  943. if ($qrd == false) throw new Exception("采购单更新失败");
  944. $qrd = Db::name("good_zixun")->where($good)->update($goodinfo);
  945. if ($qrd == false) throw new Exception("商品信息更新失败");
  946. $qrd = Db::name("order_addr")->where($addr)->update($orderAddr);
  947. if ($qrd == false) throw new Exception("销售单地址更新失败");
  948. Db::commit();
  949. return app_show(0, '订单更新成功');
  950. } catch (\Exception $exception) {
  951. Db::rollback();
  952. return error_show(1004, $exception->getMessage());
  953. }
  954. }
  955. }