ImportOrderFromCHandleData.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\command;
  4. use app\admin\model\ActionLog;
  5. use app\admin\model\GoodLog;
  6. use app\admin\model\GoodStockInfo;use app\admin\model\OrderImportFromC as OIFCModel;
  7. use app\admin\model\OrderOutChild;use app\admin\model\ProcessOrder;
  8. use app\admin\model\Test1;
  9. use think\console\Command;
  10. use think\console\Input;
  11. use think\console\input\Argument;
  12. use think\console\input\Option;
  13. use think\console\Output;
  14. use think\Exception;
  15. use think\facade\Cache;
  16. use think\facade\Config;
  17. use think\facade\Db;
  18. //C端订单导入-处理
  19. class ImportOrderFromCHandleData extends Command
  20. {
  21. private $cgd_data = [];//存储采购单的数据,目前是为了做供应商api推送而准备的
  22. protected function configure()
  23. {
  24. // 指令配置
  25. $this->setName('handleData')
  26. ->setDescription('批量处理C端导入的订单数据');
  27. }
  28. //【脚本2】批量处理C端导入的订单数据
  29. protected function execute(Input $input, Output $output)
  30. {
  31. $key = 'import_order_from_c_key';
  32. $c_data_id = Cache::store('redis')->handler()->rpop($key);
  33. if (!$c_data_id) $output->writeln('没有符合条件的记录');
  34. else {
  35. $order_import_from_c_db = new OIFCModel();
  36. $c_data = $order_import_from_c_db
  37. ->where(['is_del' => OIFCModel::$is_del_normal, 'status' => OIFCModel::$status_wait_relation, 'id' => $c_data_id])
  38. // ->lock(true)
  39. ->field('id,createrid,creater')
  40. ->find();
  41. if (empty($c_data)) $output->writeln('未查询到该记录');
  42. else {
  43. Db::startTrans();
  44. try {
  45. $standing_book_data = [];
  46. //先找用户确认信息
  47. $extend_data = Db::name('order_import_from_c_extend')
  48. ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 2])
  49. ->find();
  50. if (empty($extend_data)) {
  51. $extend_data = Db::name('order_import_from_c_extend')
  52. ->where(['order_import_from_c_id' => $c_data['id'], 'is_del' => 0, 'type' => 1])
  53. ->find();
  54. }
  55. if (empty($extend_data)) throw new Exception('没有对应的解析数据');
  56. //复用sale::create()方法 -- start
  57. $orderCode = makeNo("QR");
  58. $customer_code = $extend_data['customer_code'];
  59. $customer = Db::connect('mysql_sys')
  60. ->name("customer_info")
  61. ->where(["companyNo" => $customer_code])
  62. ->find();
  63. if ($customer == false) throw new Exception('未找到客户数据');
  64. $supplierNo = $extend_data['companyNo'];
  65. $supplier = Db::connect('mysql_sys')
  66. ->name("business")
  67. ->where(["companyNo" => $supplierNo])
  68. ->find();
  69. if ($supplier == false) throw new Exception('未找到平台供应商数据');
  70. $goodtype = 1;//1正常商品
  71. $sendtype = 1;//直接发货
  72. $platform_id = $extend_data['platform_id'];
  73. $platform_order = $extend_data['platform_code'];
  74. $good_num = $extend_data['num'];
  75. $arrtime = $extend_data['platform_time'];
  76. $paytime = $extend_data['addtime'];
  77. $workNo = $extend_data['po_code'];
  78. $ct = Db::name('good_platform')
  79. ->alias('a')
  80. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  81. ->where(['a.skuCode' => $extend_data['skuCode'], 'a.exam_status' => 6])//exam_status==6已上线
  82. ->field("b.*,a.skuCode,a.spuCode,a.platform_code,a.plat_code")
  83. ->find();
  84. if ($ct == false) throw new Exception('未找到商品数据');
  85. $goodinfo = $ct;
  86. $is_stock = $ct['is_stock'];
  87. $order_type = $is_stock == 1 ? 1 : 2;//1备库(库存品)2非库存品
  88. $order_source = 4;//4平台
  89. $spuCode = $ct['spuCode'];
  90. $skuCode = $ct['skuCode'];
  91. $is_activity = empty($extend_data['activity_name']) ? 0 : 1;
  92. if ($goodinfo['is_stock'] == 1) {
  93. // $stock = Db::name("good_stock")
  94. // ->alias("a")
  95. // ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  96. // ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, 'b.wsm_type' => 5, "b.companyNo" => $supplierNo])
  97. // ->field("a.id,a.usable_stock,a.wait_out_stock,a.wsm_code")
  98. // ->find();
  99. //
  100. // if ($stock == false || $stock['usable_stock'] < $good_num) throw new Exception('库存数量不足');
  101. // $stock_num =Db::name("good_stock_info")->where(["stockid"=>$stock['id']])->sum('balance_num');
  102. // if($stock_num < $good_num){
  103. // throw new Exception('bn库存数量不足');
  104. // }
  105. // $stock_num = Db::name("good_stock")->alias("a")
  106. // ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  107. // ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
  108. // ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
  109. // ->sum('balance_num');
  110. if($ct['usable_stock'] < $good_num){
  111. throw new Exception('商品库存数量不足');
  112. }
  113. $origin_price = 0;
  114. } else {
  115. $origin = Db::name("good_nake")
  116. ->where([["spuCode", "=", $spuCode], ["min_num", "<=", $good_num], ["is_del", "=", 0]])
  117. ->order("min_num desc")
  118. ->find();
  119. if ($origin == false) throw new Exception('未找到相关成本价格');
  120. $origin_price = $origin['nake_total'];
  121. }
  122. $sale_price = $extend_data['price'];
  123. if ($goodtype == 1) {
  124. $good = Db::name("good_ladder")
  125. ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
  126. ->where([["min_num", "<=", $good_num]])
  127. ->order("min_num desc")
  128. ->find();
  129. if ($good == false) throw new Exception('未找到相关阶梯价格');
  130. //$sale_price = $good['sale_price']; //不改动售价
  131. //理论上不会出现实时金价的订单
  132. if ($ct['is_gold_price'] == 1 && $is_stock != 1) {
  133. $gold = Db::name("gold_price1")
  134. ->field('id,price')
  135. ->where(["type" => $ct['noble_metal'], "is_del" => 0, "status" => 1])
  136. ->order("addtime desc")
  137. ->find();
  138. //$saleprice(最终售价) = (打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价+物流费)/(1-成本售价/100);
  139. $gold_sale_price = $ct['demo_fee'] / $good_num + $ct['open_fee'] / $good_num + $ct['noble_weight'] * $gold["price"] + $good['cost_fee'] * $ct['noble_weight'] + $origin['package_fee'] + $origin['mark_fee'] + $origin['cert_fee'] + $origin['nake_fee'] + $origin['delivery_fee'];
  140. if ($sale_price < $gold_sale_price) throw new Exception('价格不符合根据实时金价计算出的最终售价');
  141. $ct['cgd_gold_price'] = $gold['price'];
  142. // $order_rate = Db::name("cat")->where(["id" => $ct['cat_id']])->value('order_rate');
  143. // $budget = isset($order_rate) ? $order_rate / 100 : 0;
  144. // $saleprice = $total_fee / (1 - $budget);
  145. }
  146. if ($is_activity == 1) {
  147. $act = Db::name("activity_info")
  148. ->alias("a")
  149. ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  150. ->where(["a.skuCode" => $skuCode, "a.activity_code" => $extend_data['activity_code'], "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
  151. ->find();
  152. if ($act == false) throw new Exception('未找到相关活动价');
  153. if ($act['moq_num'] > $good_num) throw new Exception('商品不满足活动价起订量' . $act['moq_num']);
  154. if ($act['activity_stock'] < $good_num) throw new Exception('商品活动库存剩余' . $act['activity_stock']);
  155. //$sale_price = $act['activity_price'];//不能改动价格
  156. }
  157. }
  158. $supplier_temp_info = Db::connect('mysql_sys')
  159. ->name('supplier')
  160. ->field('id,name,person,personid')
  161. ->where('code', $ct['supplierNo'])
  162. ->findOrEmpty();
  163. $cgd = [
  164. "supplierNo" => $ct['supplierNo'],
  165. "supplier_name" =>$supplier_temp_info['name'] ,
  166. "companyNo" => $supplierNo,
  167. "companyName" =>$supplier['company'] ,
  168. "orderCode" => $orderCode,
  169. "spuCode" => $ct['spuCode'],
  170. "skuCode" => $ct['skuCode'],
  171. "good_name" => $ct['good_name'],
  172. "sale_price" => $origin_price,
  173. "total_fee" => $origin_price * $good_num,
  174. "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
  175. "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
  176. "open_fee" => $ct['open_fee'],
  177. "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
  178. "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
  179. "demo_fee" => $ct['demo_fee'],
  180. "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
  181. "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
  182. "good_num" => $good_num,
  183. "good_type" => $goodtype,
  184. "order_type" => $order_type,
  185. "order_source" => $order_source,
  186. "createrid" =>$supplier_temp_info['personid'],
  187. "creater" =>$supplier_temp_info['person'],
  188. 'send_way' => 2,
  189. 'gold_price' => $ct['cgd_gold_price'],
  190. 'good_createrid' => $goodinfo['createrid'],
  191. 'good_creater' => $goodinfo['creater'],//商品创建人
  192. "weight"=>$ct['noble_weight']
  193. ];
  194. $send_num = $extend_data['num'];
  195. $remark = $extend_data['order_remark'];
  196. $rm = $c_data['createrid'];
  197. $ri = $c_data['creater'];
  198. $data = [
  199. "orderCode" => $orderCode,
  200. "good_code" => $spuCode,
  201. "skuCode" => $skuCode,
  202. "customer_code" => $customer_code,
  203. "good_name" => isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '' ? $goodinfo['good_name'] : '',
  204. "good_num" => $good_num,
  205. "cat_id" => $goodinfo['cat_id'],
  206. "apply_id" => $rm,
  207. "apply_name" => $ri,
  208. "origin_price" => $origin_price,
  209. "sale_price" => $sale_price,
  210. "post_fee" => 0,
  211. "status" => 0,
  212. "send_num" => 0,
  213. "wsend_num" => $good_num,
  214. "send_status" => 1,
  215. "good_type" => $goodtype,
  216. "send_type" => $sendtype,
  217. "supplierNo" => $extend_data['companyNo'],
  218. "is_del" => 0,
  219. "zxNo" => "",
  220. "platform_order" => $platform_order,
  221. "platform_id" => $platform_id,
  222. "remark" => $remark,
  223. "is_stock" => $is_stock,
  224. "is_activity" => $is_activity === "" ? 0 : $is_activity,
  225. 'activity_code' => $extend_data['activity_code'],
  226. "order_type" => $order_type,
  227. "order_source" => $order_source,
  228. // "poNo"=>$poNo,
  229. 'good_weight' => $ct['weight'],
  230. 'gold_price' => $ct['cgd_gold_price'],
  231. 'cost_price' => $ct['cost_fee'],
  232. 'diff_weight' => 0,
  233. 'diff_fee' => 0,
  234. "workNo" => $workNo,
  235. "addtime" => date("Y-m-d H:i:s"),
  236. "updatetime" => date("Y-m-d H:i:s"),
  237. 'total_price' => round($sale_price * $good_num, 2),
  238. 'cgderid' => $supplier_temp_info['personid'],
  239. 'cgder' => $supplier_temp_info['person'],//采购员(供应商负责人)
  240. 'good_createrid' => $goodinfo['createrid'],
  241. 'good_creater' => $goodinfo['creater'],//商品创建人
  242. ];
  243. $paytime == "" ? "" : $data['paytime'] = $paytime;
  244. $datainfo = Db::name('sale')->insert($data, true);
  245. if ($datainfo > 0) {
  246. if ($is_activity == 1) {
  247. $actup = [
  248. "activity_stock" => $act['activity_stock'] - $good_num,
  249. "updatetime" => date("Y-m-d H:i:s")
  250. ];
  251. $actupp = Db::name("activity_info")
  252. ->where(["skuCode" => $skuCode, "activity_code" => $extend_data['activity_code'], "is_del" => 0, "status" => 1])
  253. ->save($actup);
  254. if ($actupp == false) throw new Exception('活动库存修改失败');
  255. }
  256. //补充台账数据
  257. $standing_book_data = array_merge($standing_book_data, [
  258. 'orderCode' => $orderCode,
  259. 'spuCode' => $data['good_code'],
  260. 'skuCode' => $data['skuCode'],
  261. 'order_type' => $data['order_type'],
  262. 'order_source' => $data['order_source'],
  263. 'supplierNo' => $extend_data['supplierNo'],
  264. 'companyNo' => $extend_data['companyNo'],
  265. 'customer_code' => $data['customer_code'],
  266. ]);
  267. if ($is_stock == 0) {
  268. //非库存品
  269. $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
  270. if ($bol == false) throw new Exception('订单创建失败');
  271. } else {
  272. //库存品
  273. $stockUp =[
  274. "usable_stock"=>$ct['usable_stock']-$good_num,
  275. "updatetime"=>date("Y-m-d H:i:s"),
  276. ];
  277. $update=Db::name("good")->where(["spuCode"=>$ct['spuCode'],"usable_stock"=>$ct['usable_stock']])->update($stockUp);
  278. if($update==false){
  279. throw new Exception('商品更新可用库存失败');
  280. }
  281. }
  282. if ($sendtype == 1) {
  283. $temp = [
  284. 'orderCode' => $orderCode,
  285. 'contactor' => $extend_data['contactor'],
  286. 'mobile' => $extend_data['mobile'],
  287. 'addr' => $extend_data['addr'],
  288. 'addr_code' => $extend_data['addr_code'],
  289. 'customer_code' => $customer_code,
  290. 'receipt_quantity' => $extend_data['num'],//收货数量,
  291. 'post_fee' => 0,
  292. 'is_del' => 0,
  293. 'addtime' => date("Y-m-d H:i:s"),
  294. 'updatetime' => date("Y-m-d H:i:s"),
  295. 'arrive_time' => $arrtime,
  296. ];
  297. $vmp = Db::name('order_addr')->insert($temp, true);
  298. if ($vmp > 0) {
  299. $num = $extend_data['num'];
  300. $outCode = makeNo("DF");
  301. if($is_stock!=1){
  302. $order = Db::name("order_num")
  303. ->where(["orderCode" => $orderCode, "status" => 1])
  304. ->find();
  305. if ($order == false) throw new Exception('未找到可以发货得采购单数据');
  306. $tep = [
  307. "cgdNo" => $order['cgdNo'],
  308. "outCode" => $outCode,
  309. "send_num" => $num,
  310. "status" => 1,
  311. "addtime" => date("Y-m-d H:i:s"),
  312. "updatetime" => date("Y-m-d H:i:s")
  313. ];
  314. $sen = Db::name("order_send")->save($tep);
  315. if ($sen == false) throw new Exception('发货地址添加创建失败');
  316. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  317. if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
  318. }
  319. $out = [
  320. "orderCode" => $orderCode,
  321. "outCode" => $outCode,
  322. "apply_id" => $rm,
  323. "apply_name" => $ri,
  324. "addrid" => $vmp,
  325. "post_name" => "",
  326. "post_code" => "",
  327. "post_fee" => 0,
  328. "sendtime" => date("Y-m-d H:i:s"),
  329. "send_num" => $num,
  330. "check_num" => 0,
  331. "error_num" => 0,
  332. "wsm_code" =>$is_stock==1?'': $cgdinfo['wsm_code'],
  333. "order_type" => $order_type,
  334. "status" => $is_stock == 1 ? 1 : 0,
  335. "addtime" => date("Y-m-d H:i:s"),
  336. "updatetime" => date("Y-m-d H:i:s")
  337. ];
  338. $ou = Db::name("order_out")->insertGetId($out);
  339. if ($ou == false) throw new Exception('发货地址添加创建失败');
  340. else {
  341. OrderOutChild::makeChild($outCode);
  342. //修改状态,添加待办
  343. if ($is_stock==1){
  344. $roleid = Config('app.wsm_cgder_role');
  345. $uids = Db::name('user_role')
  346. ->where('is_del', 0)
  347. ->whereIn('roleid', $roleid)
  348. ->column('uid');
  349. $handle_user_list=implode(',', $uids);
  350. }
  351. //修改状态,添加待办
  352. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  353. "order_code" => $outCode,//出库单号
  354. "status" => 0,//这里的status是之前的值
  355. "action_remark" => '',//备注
  356. "action_type" => "create"//新建create,编辑edit,更改状态status
  357. ], "CKD", 0, $out);
  358. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  359. "order_type" => 'CKD',
  360. "order_code" => $outCode,//出库单号
  361. "order_id" => $ou,
  362. "order_status" => $is_stock == 1 ? 1 : 0,
  363. "before_status" => 0,
  364. 'holder_id' => $rm,
  365. 'handle_user_list' =>$handle_user_list??""
  366. ]);
  367. $standing_book_data['outCode'] = $outCode;
  368. }
  369. } else throw new Exception('发货地址添加失败');
  370. }
  371. }
  372. //复用sale::create()方法 -- end
  373. //处理完成
  374. $order_import_from_c_db
  375. ->where('id', $c_data['id'])
  376. ->where('is_del', OIFCModel::$is_del_normal)
  377. ->save([
  378. 'status' => $order_import_from_c_db::$status_success,
  379. 'updatetime' => date('Y-m-d H:i:s'),
  380. 'remark' => '',
  381. 'updateid' => 0,
  382. 'updater' => 'system',
  383. 'orderCode' => $orderCode
  384. ]);
  385. //维护台账记录
  386. Db::name('standing_book')->insert(array_merge($standing_book_data, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo("IO")]));
  387. //将采购单数据塞入到队列中
  388. if ($this->cgd_data) {
  389. $push_data = json_encode([
  390. 'supplierNo' => $this->cgd_data['supplierNo'],
  391. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  392. 'data' => [
  393. 'cgdNo' => $this->cgd_data['cgdNo'],
  394. 'spuCode' => $this->cgd_data['spuCode'],
  395. 'good_name' => $this->cgd_data['good_name'],
  396. 'good_num' => $this->cgd_data['good_num'],
  397. 'good_price' => $this->cgd_data['good_price'],
  398. 'total_fee' => $this->cgd_data['total_fee'],
  399. 'weight' => $this->cgd_data['weight'],
  400. 'addtime' => $this->cgd_data['addtime'],
  401. ],
  402. ], JSON_UNESCAPED_UNICODE);
  403. // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  404. }
  405. Db::commit();
  406. $output->writeln(date('Y-m-d H:i:s') . '|处理成功');
  407. } catch (\think\Exception $exception) {
  408. Db::rollback();
  409. $order_import_from_c_db
  410. ->where(['id' => $c_data['id'], 'status' => OIFCModel::$status_wait_relation])
  411. ->save([
  412. 'status' => $order_import_from_c_db::$status_stock_not_enough,
  413. 'updatetime' => date('Y-m-d H:i:s'),
  414. 'remark' => $exception->getMessage(),
  415. 'updateid' => 0,
  416. 'updater' => 'system'
  417. ]);
  418. // 指令输出
  419. $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
  420. }
  421. }
  422. }
  423. }
  424. //创建采购单
  425. private function createCgd($data = [], $rm = '0', $ri = '', array &$standing_book_data = [])
  426. {
  427. $cgdCode = makeNo("CG");
  428. // $supplier = Db::name("supplier")->where(["code" => $data['supplierNo'], "is_del" => 0])->find();
  429. // if ($supplier == false) return false;
  430. $wsm = Db::name("warehouse_info")
  431. ->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "is_del" => 0])
  432. ->find();
  433. if ($wsm == false) {
  434. $wsm_code = makeNo("WSM");
  435. $inwsm = [
  436. "wsm_code" => $wsm_code,
  437. "name" => $data['supplier_name'],
  438. "wsm_type" => 2,
  439. "supplierNo" => $data['supplierNo'],
  440. "addr" => "",
  441. "addrs_code" => "",
  442. "contactor" => 0,
  443. "contactor_name" => 0,
  444. "mobile" => "",
  445. "position" => "",
  446. "companyNo" => $data['companyNo'],
  447. "status" => 1,
  448. "is_del" => 0,
  449. "addtime" => date("Y-m-d H:i:s"),
  450. "updatetime" => date("Y-m-d H:i:s")
  451. ];
  452. $in = Db::name("warehouse_info")->insert($inwsm);
  453. if ($in == false) return false;
  454. } else {
  455. $wsm_code = $wsm['wsm_code'];
  456. }
  457. //判断该供应商是否开通了供应商账号
  458. $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
  459. $cg = [
  460. "cgdNo" => $cgdCode,
  461. "bkcode" => "",
  462. "wsm_code" => $wsm_code,
  463. "cgder" => $data['creater'],
  464. "cgder_id" => $data['createrid'],
  465. "spuCode" => $data['spuCode'],
  466. "skuCode" => $data['skuCode'],
  467. "good_name" => $data['good_name'],
  468. "good_num" => $data['good_num'],
  469. "good_price" => $data['sale_price'],
  470. "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
  471. "pakge_fee" => $data['pakge_fee'],
  472. "cert_fee" => $data['cert_fee'],
  473. "open_fee" => $data['open_fee'],
  474. "teach_fee" => $data['cost_fee'],
  475. "mark_fee" => $data['mark_fee'],
  476. "demo_fee" => $data['demo_fee'],
  477. "nake_fee" => $data['nake_fee'],
  478. "delivery_fee" => $data['delivery_fee'],
  479. "weight"=>$data['weight'],
  480. "diff_weight" => "0",
  481. "diff_fee" => "0",
  482. "gold_price" => $data['gold_price'],
  483. "supplierNo" => $data['supplierNo'],
  484. "supplier_name" => $data['supplier_name'],
  485. "companyNo" => $data['companyNo'],
  486. "companyName" => $data['companyName'],
  487. "send_status" => 1,
  488. "send_num" => 0,
  489. "wsend_num" => $data['good_num'],
  490. "remark" => "",
  491. "status" => 0,//0初始化
  492. "lasttime" => date("Y-m-d H:i:s"),
  493. "is_del" => 0,
  494. "order_type" => $data['order_type'],
  495. "order_source" => $data['order_source'],
  496. "good_type" => $data['good_type'],
  497. "addtime" => date("Y-m-d H:i:s"),
  498. "updatetime" => date("Y-m-d H:i:s"),
  499. 'good_createrid' => $data['good_createrid'],
  500. 'good_creater' => $data['good_createrid'],//商品创建人
  501. 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  502. ];
  503. $up = Db::name("purchease_order")->insert($cg, true);
  504. if ($up) {
  505. //修改状态,添加待办
  506. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  507. "order_code" => $cg['cgdNo'],//销售单code
  508. "status" => 0,//这里的status是之前的值
  509. "action_remark" => '',//备注
  510. "action_type" => "create"//新建create,编辑edit,更改状态status
  511. ], "CGD", $cg['status'], $cg);
  512. //当采购单是节点0待与供应商确认,推给供应商负责人
  513. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  514. "order_type" => 'CGD',
  515. "order_code" => $cg['cgdNo'],//销售单code
  516. "order_id" => $up,
  517. "order_status" => $cg['status'],
  518. "before_status" => 0,
  519. 'holder_id' => $data['createrid'],
  520. 'wait_id'=>$data['createrid'],
  521. 'wait_name'=>$data['creater'],
  522. ]);
  523. $standing_book_data['cgdNo'] = $cgdCode;
  524. $rela = [
  525. "orderCode" => $data['orderCode'],
  526. "cgdNo" => $cgdCode,
  527. "spuCode" => $data['spuCode'],
  528. "good_num" => $data['good_num'],
  529. "wsend_num" => $data['good_num'],
  530. "send_num" => 0,
  531. "wait_num" => 0,
  532. "status" => 1,
  533. "source" => 2
  534. ];
  535. $re = Db::name("order_num")->save($rela);
  536. if ($re == false) return false;
  537. else {
  538. $stokc = Db::name("good_stock")
  539. ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
  540. ->find();
  541. if ($stokc == false) {
  542. $stokc = [
  543. "spuCode" => $data['spuCode'],
  544. "wsm_code" => $wsm_code,
  545. "wait_in_stock" => $data['good_num'],
  546. "wait_out_stock" => 0,
  547. "usable_stock" => 0,
  548. "intra_stock" => 0,
  549. "total_stock" => 0,
  550. "status" => 1,
  551. "addtime" => date("Y-m-d H:i:s"),
  552. "updatetime" => date("Y-m-d H:i:s")
  553. ];
  554. } else {
  555. $stokc['wait_in_stock'] += $data['good_num'];
  556. $stokc['updatetime'] = date("Y-m-d H:i:s");
  557. }
  558. $stoc = Db::name("good_stock")->save($stokc);
  559. if ($stoc == false) {
  560. return false;
  561. }
  562. $good_data[] = ['good_log_code' => $cgdCode, "stock_id" => isset($stoc['id']) ? $stoc['id'] : Db::name("good_stock")->getLastInsID(), "type" => 1, 'stock' => $data['good_num'], "stock_name" => "wait_in_stock"];
  563. GoodLog::LogAdd(['id' => 0, 'nickname' => 'system'], $good_data, "CGD");
  564. $this->cgd_data = $cg;
  565. return true;
  566. }
  567. } else return false;
  568. }
  569. //创建.....
  570. // private function RelaCgd(array $outinfo = [], array &$standing_book_data = [])
  571. // {
  572. // //备库单
  573. // $cgd = Db::name("order_bk")
  574. // ->where([
  575. // ["spuCode", "=", $outinfo['spuCode']],
  576. // ["is_del", "=", 0],
  577. // ["balance_num", ">=", $outinfo['good_num']],
  578. // ['companyNo', "=", $outinfo['companyNo']]
  579. // ])
  580. //// ->lock(true)
  581. // ->find();
  582. //
  583. // if ($cgd == false) return false;
  584. //
  585. // $cgdinfo = Db::name("purchease_order")
  586. // ->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])
  587. // ->find();
  588. // if ($cgdinfo == false) return false;
  589. //
  590. // //判断该供应商是否开通了供应商账号
  591. // $from_tag=checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
  592. //
  593. // $QrdCgd = [
  594. // "cgdNo" => makeNo("CG"),
  595. // "bkcode" => $cgdinfo['bkcode'],
  596. // 'wsm_code' => $cgdinfo['wsm_code'],
  597. // "cgder_id" => $cgdinfo['cgder_id'],
  598. // "cgder" => $cgdinfo['cgder'],
  599. // "spuCode" => $cgdinfo['spuCode'],
  600. // "good_name" => $cgdinfo['good_name'],
  601. // "good_num" => $outinfo['good_num'],
  602. // "good_price" => $cgdinfo['good_price'],
  603. // "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  604. // "pakge_fee" => $cgdinfo['pakge_fee'],
  605. // "cert_fee" => $cgdinfo['cert_fee'],
  606. // "open_fee" => $cgdinfo['open_fee'],
  607. // "delivery_fee" => $cgdinfo['delivery_fee'],
  608. // "mark_fee" => $cgdinfo['mark_fee'],
  609. // "teach_fee" => $cgdinfo['teach_fee'],
  610. // "nake_fee" => $cgdinfo['nake_fee'],
  611. // "demo_fee" => $cgdinfo['demo_fee'],
  612. // "weight" => $cgdinfo['weight'],
  613. // "diff_weight" => $cgdinfo['diff_weight'],
  614. // "diff_fee" => $cgdinfo['diff_fee'],
  615. // "gold_price" => $cgdinfo['gold_price'],
  616. // "supplierNo" => $cgdinfo['supplierNo'],
  617. // "supplier_name" => $cgdinfo['supplier_name'],
  618. // "companyNo" => $cgdinfo['companyNo'],
  619. // "companyName" => ,
  620. // "send_status" => 3,
  621. // "send_num" => $outinfo['good_num'],
  622. // "wsend_num" => 0,
  623. // "remark" => $cgdinfo['remark'],
  624. // "status" => 3,//入库完成
  625. // "lasttime" => $cgdinfo['lasttime'],
  626. // "is_del" => 0,
  627. // "order_type" => $outinfo['order_type'],
  628. // "order_source" => $outinfo['order_source'],
  629. // "good_type" => $cgdinfo['good_type'],
  630. // "addtime" => date("Y-m-d H:i:s"),
  631. // "updatetime" => date("Y-m-d H:i:s"),
  632. // 'good_createrid' => $outinfo['good_createrid'],
  633. // 'good_creater' => $outinfo['good_creater'],//商品创建人
  634. // 'from_tag' => isset($from_tag[$cgdinfo['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  635. // ];
  636. // $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  637. // if ($insetrCgd == false) return false;
  638. //
  639. // $standing_book_data = array_merge($standing_book_data, [
  640. // 'cgdNo' => $QrdCgd['cgdNo'],
  641. // 'bk_code' => $QrdCgd['bkcode'],
  642. // ]);
  643. //
  644. // $merge_num = Db::name("purchease_order")
  645. // ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => $outinfo['order_type'], "is_del" => 0])
  646. // ->where('order_source', '<>', 0)//0备库单不计算在内
  647. // ->field("sum(send_num)-sum(th_num) as num")
  648. // ->find();
  649. // $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  650. // $cgd['merge_num'] = $merge_num['num'];
  651. // $cgd['updatetime'] = date("Y-m-d H:i:s");
  652. // $up = Db::name("order_bk")->save($cgd);
  653. // if ($up == false) return false;
  654. //
  655. // $data = [
  656. // "orderCode" => $outinfo['orderCode'],
  657. // "cgdNo" => $QrdCgd['cgdNo'],
  658. // "spuCode" => $outinfo['spuCode'],
  659. // "companyNo" => $outinfo['companyNo'],
  660. // "good_num" => $outinfo['good_num'],
  661. // "wsend_num" => $outinfo['good_num'],
  662. // "send_num" => 0,
  663. // "wait_num" => $outinfo['good_num'],
  664. // "status" => 1,
  665. // "source" => 1,
  666. // ];
  667. // $order = Db::name("order_num")->save($data);
  668. // if ($order == false) return false;
  669. //
  670. // $this->cgd_data = $QrdCgd;
  671. // return true;
  672. // }
  673. }