handleYzOrderData.php 35 KB

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