Filing.php 62 KB

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