Filing.php 63 KB

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