handleYzOrderData.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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 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. "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
  204. "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
  205. "open_fee" => $ct['open_fee'],
  206. "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
  207. "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
  208. "demo_fee" => $ct['demo_fee'],
  209. "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
  210. "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
  211. "good_num" => $good_num,
  212. "good_type" => $goodtype,
  213. "order_type" => $order_type,
  214. "order_source" => $order_source,
  215. "createrid" =>$supplier_temp_info['personid']??'',
  216. "creater" =>$supplier_temp_info['person']??'',
  217. 'send_way' => 2,
  218. 'gold_price' => $ct['cgd_gold_price'],
  219. 'good_createrid' => $goodinfo['createrid'],
  220. 'good_creater' => $goodinfo['creater'],//商品创建人
  221. 'weight' => $ct['noble_weight'],//商品创建人
  222. ];
  223. //非库存品
  224. $bol = $this->createCgd($cgd, $rm, $ri, $standing_book_data);
  225. if ($bol == false) throw new Exception('订单创建失败');
  226. } else {
  227. $stockUp =[
  228. "usable_stock"=>$ct['usable_stock']-$good_num,
  229. "updatetime"=>date("Y-m-d H:i:s"),
  230. ];
  231. $update=Db::name("good")->where(["spuCode"=>$ct['spuCode'],"usable_stock"=>$ct['usable_stock']])->update($stockUp);
  232. if($update==false){
  233. throw new Exception('商品更新可用库存失败');
  234. }
  235. }
  236. if ($sendtype == 1) {
  237. // $p_c_a = get_address($c_data['delivery_province'] . $c_data['delivery_city'] . $c_data['delivery_district']);
  238. $province = Db::name('province')
  239. ->where('name', $c_data['delivery_province'])
  240. ->value('province_code', '');
  241. //地级市可能有重复的,例如'省直辖县'
  242. $city = Db::name('city')
  243. ->where('name', $c_data['delivery_city'])
  244. ->where('province_code', $province)
  245. ->value('city_code', '');
  246. //县区名称也有可能重复,例如'桥东区'
  247. $area = Db::name('area')
  248. ->where('name', $c_data['delivery_district'])
  249. ->where('city_code', $city)
  250. ->value('area_code', '');
  251. $addr_code = implode([$province, $city, $area], ',');
  252. $temp = [
  253. 'orderCode' => $orderCode,
  254. 'contactor' => $c_data['receiver_name'],
  255. 'mobile' => $c_data['receiver_tel'],
  256. 'addr' => $c_data['delivery_address'],
  257. 'addr_code' => $addr_code,
  258. 'customer_code' => $customer_code,
  259. 'receipt_quantity' => $c_data['num'],//收货数量,
  260. 'post_fee' => $c_data['post_fee'],
  261. 'is_del' => 0,
  262. 'addtime' => date("Y-m-d H:i:s"),
  263. 'updatetime' => date("Y-m-d H:i:s"),
  264. 'arrive_time' => $arrtime,
  265. ];
  266. $vmp = Db::name('order_addr')->insertGetId($temp);
  267. if ($vmp > 0) {
  268. $num = $c_data['num'];
  269. $outCode = makeNo("DF");
  270. if ($is_stock != 1) {
  271. $order = Db::name("order_num")
  272. ->where(["orderCode" => $orderCode, "status" => 1])
  273. ->find();
  274. if ($order == false) throw new Exception('未找到可以发货得采购单数据');
  275. $tep = [
  276. "cgdNo" => $order['cgdNo'],
  277. "outCode" => $outCode,
  278. "send_num" => $num,
  279. "status" => 1,
  280. "addtime" => date("Y-m-d H:i:s"),
  281. "updatetime" => date("Y-m-d H:i:s")
  282. ];
  283. $sen = Db::name("order_send")->save($tep);
  284. if ($sen == false) throw new Exception('发货地址添加创建失败');
  285. $cgdinfo = Db::name("purchease_order")->where(["cgdNo" => $order['cgdNo']])->find();
  286. if ($cgdinfo == false) throw new Exception('未匹配到采购数据');
  287. }
  288. $out = [
  289. "orderCode" => $orderCode,
  290. "outCode" => $outCode,
  291. "apply_id" => $rm,
  292. "apply_name" => $ri,
  293. "addrid" => $vmp,
  294. "post_name" => "",
  295. "post_code" => "",
  296. "post_fee" => 0,
  297. "sendtime" => date("Y-m-d H:i:s"),
  298. "send_num" => $num,
  299. "check_num" => 0,
  300. "error_num" => 0,
  301. "wsm_code" => $is_stock==1? '':$cgdinfo['wsm_code'],
  302. "order_type" => $order_type,
  303. "status" => $is_stock == 1 ? 1 : 0,
  304. "send_status" => $is_stock == 1 ? 1 : 0,
  305. "addtime" => date("Y-m-d H:i:s"),
  306. "updatetime" => date("Y-m-d H:i:s")
  307. ];
  308. $ou = Db::name("order_out")->insertGetId($out);
  309. if ($ou == false) throw new Exception('发货地址添加创建失败');
  310. else {
  311. if ($is_stock == 1) OrderOutChild::makeChild($outCode);
  312. //修改状态,添加待办
  313. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  314. "order_code" => $outCode,//出库单号
  315. "status" => 0,//这里的status是之前的值
  316. "action_remark" => '',//备注
  317. "action_type" => "create"//新建create,编辑edit,更改状态status
  318. ], "CKD", 0, $out);
  319. if ($out['status'] == 1) {
  320. if ($is_stock == 1) {
  321. //库存品,待办数据推给库管
  322. $uids = Db::name('user_role')
  323. ->where(['is_del' => 0, 'roleid' => config('app.wsm_cgder_role'), 'status' => 1])
  324. ->column('uid');
  325. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  326. "order_type" => 'CKD',
  327. "order_code" => $outCode,//出库单号
  328. "order_id" => $ou,
  329. "order_status" => $out['status'],
  330. "before_status" => 0,
  331. 'holder_id' => $data['apply_id'],
  332. 'handle_user_list' => implode(',', $uids),
  333. ]);
  334. } else {
  335. // //非库存品推给供应商负责人
  336. // $supp = Db::name('supplier')
  337. // ->field('person,personid')
  338. // ->where('code', $ct['supplierNo'])
  339. // ->findOrEmpty();
  340. $supp = $userCommon->handle('sInfo',['code'=>$ct['supplierNo']]);
  341. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  342. "order_type" => 'CKD',
  343. "order_code" => $outCode,//出库单号
  344. "order_id" => $ou,
  345. "order_status" => $out['status'],
  346. "before_status" => 0,
  347. 'holder_id' => $data['apply_id'],
  348. 'wait_id' => $supp['data']['personid'],
  349. 'wait_name' => $supp['data']['person'],
  350. ]);
  351. }
  352. }else ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  353. "order_type" => 'CKD',
  354. "order_code" => $outCode,//出库单号
  355. "order_id" => $ou,
  356. "order_status" => $out['status'],
  357. "before_status" => 0,
  358. 'holder_id'=>$data['apply_id']
  359. ]);
  360. // $standing_book_data['outCode'] = $outCode;
  361. }
  362. } else throw new Exception('发货地址添加失败');
  363. }
  364. }
  365. //复用sale::create()方法 -- end
  366. //处理完成
  367. // $order_import_from_c_db
  368. // ->where('id', $c_data['id'])
  369. // ->where('is_del', OIFCModel::$is_del_normal)
  370. // ->save([
  371. // 'status' => $order_import_from_c_db::$status_success,
  372. // 'updatetime' => date('Y-m-d H:i:s'),
  373. // 'remark' => '',
  374. // 'updateid' => 0,
  375. // 'updater' => 'system',
  376. // 'orderCode' => $orderCode
  377. // ]);
  378. //维护台账记录
  379. 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")]));
  380. //回调更新有赞订单数据
  381. $callback_rs = $this->callbackYz(['status' => 6, 'id' => $c_data['id'], 'orderCode' => $orderCode]);
  382. if ($callback_rs['code'] != 0) throw new \Exception($callback_rs['message']);
  383. //将采购单数据塞入到队列中
  384. if ($this->cgd_data) {
  385. $push_data = json_encode([
  386. 'supplierNo' => $this->cgd_data['supplierNo'],
  387. 'type' => 1,//1销售订单(采销的采购单),2上线结果
  388. 'data' => [
  389. 'cgdNo' => $this->cgd_data['cgdNo'],
  390. 'spuCode' => $this->cgd_data['spuCode'],
  391. 'good_name' => $this->cgd_data['good_name'],
  392. 'good_num' => $this->cgd_data['good_num'],
  393. 'good_price' => $this->cgd_data['good_price'],
  394. 'total_fee' => $this->cgd_data['total_fee'],
  395. 'weight' => $this->cgd_data['weight'],
  396. 'addtime' => $this->cgd_data['addtime'],
  397. ],
  398. ], JSON_UNESCAPED_UNICODE);
  399. // Cache::store("redis")->handler()->lPush(Config::get('app.abutment_queue'), $push_data);
  400. }
  401. Db::commit();
  402. Cache::store('redis')->set("YzTimeLimit",0);
  403. $output->writeln(date('Y-m-d H:i:s') . '|处理成功,orderCode:' . $orderCode);
  404. } catch (\Exception $exception) {
  405. Db::rollback();
  406. $message[] = $exception->getMessage();
  407. //回调更新有赞订单数据
  408. $callback_rs = $this->callbackYz(['status' => 8, 'id' => $c_data['id'], 'reason' => $exception->getMessage()]);
  409. if ($callback_rs['code'] != 0) $message[] = $callback_rs['message'];
  410. Cache::store('redis')->set("YzTimeLimit",0);
  411. $output->writeln(date('Y-m-d H:i:s') . '|处理失败,' . implode(',', $message));
  412. }
  413. }
  414. Cache::store('redis')->set("YzTimeLimit",0,60);
  415. //没有需要处理的数据
  416. }
  417. //创建采购单
  418. private function createCgd($data = [], $rm = '0', $ri = '', array &$standing_book_data = [])
  419. {
  420. $cgdCode = makeNo("CG");
  421. // $supplier = Db::name("supplier")->where(["code" => $data['supplierNo'], "is_del" => 0])->find();
  422. // if ($supplier == false) return false;
  423. $wsm = Db::name("warehouse_info")
  424. ->where(["supplierNo" => $data["supplierNo"], "companyNo" => $data['companyNo'], "is_del" => 0])
  425. ->find();
  426. if ($wsm == false) {
  427. $wsm_code = makeNo("WSM");
  428. $inwsm = [
  429. "wsm_code" => $wsm_code,
  430. "name" => $data['supplier_name'],
  431. "wsm_type" => 2,
  432. "supplierNo" => $data['supplierNo'],
  433. "addr" => "",
  434. "addrs_code" => "",
  435. "contactor" => 0,
  436. "contactor_name" => 0,
  437. "mobile" => "",
  438. "position" => "",
  439. "companyNo" => $data['companyNo'],
  440. "status" => 1,
  441. "is_del" => 0,
  442. "addtime" => date("Y-m-d H:i:s"),
  443. "updatetime" => date("Y-m-d H:i:s")
  444. ];
  445. $in = Db::name("warehouse_info")->insert($inwsm);
  446. if ($in == false) return false;
  447. } else {
  448. $wsm_code = $wsm['wsm_code'];
  449. }
  450. //判断该供应商是否开通了供应商账号
  451. $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
  452. $cg = [
  453. "cgdNo" => $cgdCode,
  454. "bkcode" => "",
  455. "wsm_code" => $wsm_code,
  456. "cgder" => $data['creater'],
  457. "cgder_id" => $data['createrid'],
  458. "spuCode" => $data['spuCode'],
  459. "skuCode" => $data['skuCode'],
  460. "good_name" => $data['good_name'],
  461. "good_num" => $data['good_num'],
  462. "good_price" => $data['sale_price'],
  463. "total_fee" => round($data['sale_price'] * $data['good_num'], 2),
  464. "pakge_fee" => $data['pakge_fee'],
  465. "cert_fee" => $data['cert_fee'],
  466. "open_fee" => $data['open_fee'],
  467. "teach_fee" => $data['cost_fee'],
  468. "mark_fee" => $data['mark_fee'],
  469. "demo_fee" => $data['demo_fee'],
  470. "nake_fee" => $data['nake_fee'],
  471. "delivery_fee" => $data['delivery_fee'],
  472. "weight"=>$data['weight'],
  473. "diff_weight" => "0",
  474. "diff_fee" => "0",
  475. "gold_price" => $data['gold_price'],
  476. "supplierNo" => $data['supplierNo'],
  477. "supplier_name" => $data['supplier_name'],
  478. "companyNo" => $data['companyNo'],
  479. "companyName" => $data['companyName'],
  480. "send_status" => 1,
  481. "send_num" => 0,
  482. "wsend_num" => $data['good_num'],
  483. "remark" => "",
  484. "status" => 0,//0初始化
  485. "lasttime" => date("Y-m-d H:i:s"),
  486. "is_del" => 0,
  487. "order_type" => $data['order_type'],
  488. "order_source" => $data['order_source'],
  489. "good_type" => $data['good_type'],
  490. "addtime" => date("Y-m-d H:i:s"),
  491. "updatetime" => date("Y-m-d H:i:s"),
  492. 'good_createrid' => $data['good_createrid'],
  493. 'good_creater' => $data['good_creater'],//商品创建人
  494. 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  495. ];
  496. $up = Db::name("purchease_order")->insert($cg, true);
  497. if ($up) {
  498. //修改状态,添加待办
  499. ActionLog::logAdd(['id' => $rm, 'nickname' => $ri], [
  500. "order_code" => $cg['cgdNo'],//销售单code
  501. "status" => 0,//这里的status是之前的值
  502. "action_remark" => '',//备注
  503. "action_type" => "create"//新建create,编辑edit,更改状态status
  504. ], "CGD", $cg['status'], $cg);
  505. //当采购单是节点0待与供应商确认,推给供应商负责人
  506. ProcessOrder::AddProcess(['id' => $rm, 'nickname' => $ri], [
  507. "order_type" => 'CGD',
  508. "order_code" => $cg['cgdNo'],//销售单code
  509. "order_id" => $up,
  510. "order_status" => $cg['status'],
  511. "before_status" => 0,
  512. 'holder_id'=>$data['createrid'],
  513. 'wait_id'=>$data['createrid'],
  514. 'wait_name'=>$data['creater'],
  515. ]);
  516. $standing_book_data['cgdNo'] = $cgdCode;
  517. $rela = [
  518. "orderCode" => $data['orderCode'],
  519. "cgdNo" => $cgdCode,
  520. "spuCode" => $data['spuCode'],
  521. "good_num" => $data['good_num'],
  522. "wsend_num" => $data['good_num'],
  523. "send_num" => 0,
  524. "wait_num" => 0,
  525. "status" => 1,
  526. "source" => 2
  527. ];
  528. $re = Db::name("order_num")->save($rela);
  529. if ($re == false) return false;
  530. else {
  531. $stokc = Db::name("good_stock")
  532. ->where(['spuCode' => $data['spuCode'], "wsm_code" => $wsm_code, "is_del" => 0])
  533. ->find();
  534. if ($stokc == false) {
  535. $stokc = [
  536. "spuCode" => $data['spuCode'],
  537. "wsm_code" => $wsm_code,
  538. "wait_in_stock" => $data['good_num'],
  539. "wait_out_stock" => 0,
  540. "usable_stock" => 0,
  541. "intra_stock" => 0,
  542. "total_stock" => 0,
  543. "status" => 1,
  544. "addtime" => date("Y-m-d H:i:s"),
  545. "updatetime" => date("Y-m-d H:i:s")
  546. ];
  547. } else {
  548. $stokc['wait_in_stock'] += $data['good_num'];
  549. $stokc['updatetime'] = date("Y-m-d H:i:s");
  550. }
  551. $stoc = Db::name("good_stock")->save($stokc);
  552. if ($stoc == false) return false;
  553. $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"];
  554. GoodLog::LogAdd(['id' => 0, 'nickname' => 'system'], $good_data, "CGD");
  555. $this->cgd_data = $cg;
  556. return true;
  557. }
  558. } else return false;
  559. }
  560. //创建.....
  561. // private function RelaCgd(array $outinfo = [], array &$standing_book_data = [])
  562. // {
  563. // //备库单
  564. // $cgd = Db::name("order_bk")
  565. // ->where([
  566. // ["spuCode", "=", $outinfo['spuCode']],
  567. // ["is_del", "=", 0],
  568. // ["balance_num", ">=", $outinfo['good_num']],
  569. // ['companyNo', "=", $outinfo['companyNo']]
  570. // ])
  571. // ->lock(true)
  572. // ->find();
  573. //
  574. // if ($cgd == false) return false;
  575. //
  576. // $cgdinfo = Db::name("purchease_order")->where(['cgdNo' => $cgd['cgdNo'], "is_del" => 0])->find();
  577. // if ($cgdinfo == false) return false;
  578. //
  579. // //判断该供应商是否开通了供应商账号
  580. // $from_tag=checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
  581. //
  582. // $QrdCgd = [
  583. // "cgdNo" => makeNo("CG"),
  584. // "bkcode" => $cgdinfo['bkcode'],
  585. // 'wsm_code' => $cgdinfo['wsm_code'],
  586. // "cgder_id" => $cgdinfo['cgder_id'],
  587. // "cgder" => $cgdinfo['cgder'],
  588. // "spuCode" => $cgdinfo['spuCode'],
  589. // "good_name" => $cgdinfo['good_name'],
  590. // "good_num" => $outinfo['good_num'],
  591. // "good_price" => $cgdinfo['good_price'],
  592. // "total_fee" => round($cgdinfo['good_price'] * $outinfo['good_num'], 2),
  593. // "pakge_fee" => $cgdinfo['pakge_fee'],
  594. // "cert_fee" => $cgdinfo['cert_fee'],
  595. // "open_fee" => $cgdinfo['open_fee'],
  596. // "delivery_fee" => $cgdinfo['delivery_fee'],
  597. // "mark_fee" => $cgdinfo['mark_fee'],
  598. // "teach_fee" => $cgdinfo['teach_fee'],
  599. // "nake_fee" => $cgdinfo['nake_fee'],
  600. // "demo_fee" => $cgdinfo['demo_fee'],
  601. // "weight" => $cgdinfo['weight'],
  602. // "diff_weight" => $cgdinfo['diff_weight'],
  603. // "diff_fee" => $cgdinfo['diff_fee'],
  604. // "gold_price" => $cgdinfo['gold_price'],
  605. // "supplierNo" => $cgdinfo['supplierNo'],
  606. // "supplier_name" => $cgdinfo['supplier_name'],
  607. // "companyNo" => $cgdinfo['companyNo'],
  608. // "send_status" => 3,
  609. // "send_num" => $outinfo['good_num'],
  610. // "wsend_num" => 0,
  611. // "remark" => $cgdinfo['remark'],
  612. // "status" => 3,//入库完成
  613. // "lasttime" => $cgdinfo['lasttime'],
  614. // "is_del" => 0,
  615. // "order_type" => $outinfo['order_type'],
  616. // "order_source" => $outinfo['order_source'],
  617. // "good_type" => $cgdinfo['good_type'],
  618. // "addtime" => date("Y-m-d H:i:s"),
  619. // "updatetime" => date("Y-m-d H:i:s"),
  620. // 'good_createrid' => $outinfo['good_createrid'],
  621. // 'good_creater' => $outinfo['good_creater'],//商品创建人
  622. // 'from_tag' => isset($from_tag[$cgdinfo['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  623. // ];
  624. // $insetrCgd = Db::name("purchease_order")->insert($QrdCgd);
  625. // if ($insetrCgd == false) return false;
  626. //
  627. // $standing_book_data = array_merge($standing_book_data, [
  628. // 'cgdNo' => $QrdCgd['cgdNo'],
  629. // 'bk_code' => $QrdCgd['bkcode'],
  630. // ]);
  631. //
  632. // $merge_num = Db::name("purchease_order")
  633. // ->where(["bkcode" => $cgdinfo['bkcode'], "order_type" => $outinfo['order_type'], "is_del" => 0])
  634. // ->where('order_source', '<>', 0)//0备库单不计算在内
  635. // ->field("sum(send_num)-sum(th_num) as num")
  636. // ->find();
  637. // $cgd['balance_num'] = $cgd['total_num'] - $merge_num['num'];
  638. // $cgd['merge_num'] = $merge_num['num'];
  639. // $cgd['updatetime'] = date("Y-m-d H:i:s");
  640. // $up = Db::name("order_bk")->save($cgd);
  641. // if ($up == false) return false;
  642. //
  643. // $data = [
  644. // "orderCode" => $outinfo['orderCode'],
  645. // "cgdNo" => $QrdCgd['cgdNo'],
  646. // "spuCode" => $outinfo['spuCode'],
  647. // "companyNo" => $outinfo['companyNo'],
  648. // "good_num" => $outinfo['good_num'],
  649. // "wsend_num" => $outinfo['good_num'],
  650. // "send_num" => 0,
  651. // "wait_num" => $outinfo['good_num'],
  652. // "status" => 1,
  653. // "source" => 1,
  654. // ];
  655. // $order = Db::name("order_num")->save($data);
  656. // if ($order == false) return false;
  657. //
  658. // $this->cgd_data = $QrdCgd;
  659. //
  660. // return true;
  661. // }
  662. //与有赞项目回调
  663. private function callbackYz(array $data = [])
  664. {
  665. $host = Config::get('app.yz_domain');
  666. $response = curl_request($host . 'api/callback_order_by_stock', $data);
  667. return json_decode($response, true);
  668. }
  669. }