Filing.php 56 KB

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