Filing.php 49 KB

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