InterMakeOrder.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use app\admin\common\User;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Argument;
  8. use think\console\input\Option;
  9. use think\console\Output;
  10. use think\facade\Db;
  11. use think\facade\Cache;
  12. class InterMakeOrder extends Command
  13. {
  14. protected function configure()
  15. {
  16. // 指令配置
  17. $this->setName('intermakeorder')
  18. ->setDescription('the intermakeorder command');
  19. }
  20. protected function execute(Input $input, Output $output)
  21. {
  22. $date=date("Y-m-d H:i:s");
  23. $rs = Cache::store('redis')->get('intermakeorder');
  24. if ($rs) return true;
  25. Cache::store('redis')->set("intermakeorder", 1, 5);
  26. Db::startTrans();
  27. $interinfo =Db::name("inter_order")->where(["status"=>1,"is_del"=>0])->lock(True)->findOrEmpty();
  28. if(empty($interinfo)){ Db::rollback();return'';}
  29. try{
  30. $result=$this->makeOrder($interinfo);
  31. $dip=Db::name("inter_order")->where($interinfo )->update(["orderCode"=>$result["orderCode"],
  32. "cgdCode"=>$result["cgdCode"],"status"=>2,"remark"=>'转单完成',"updatetime"=>date("Y-m-d H:i:s")]);
  33. if($dip==false) throw new \Exception("录单更新失败");
  34. Db::commit();
  35. $output->writeln("[$date] 录单{$interinfo['interNo']} 转单成功");
  36. }catch (\Exception $exception){
  37. Db::rollback();
  38. Db::name("inter_order")->where($interinfo)->update(["status"=>3,"remark"=>$exception->getMessage(),"updatetime"=>date("Y-m-d H:i:s")]);
  39. $output->writeln("[$date] 录单{$interinfo['interNo']} 转单失败|".$exception->getMessage());
  40. }
  41. }
  42. /**
  43. * @param $param
  44. * @return array
  45. * @throws \Exception
  46. */
  47. private function makeOrder($param):array{
  48. $qrdcode = makeNo("QR");
  49. $cgddcode = makeNo("CG");
  50. $goodCode = makeNo("SKU");
  51. $userCommon = User::getIns();
  52. $payinfo = Db::name("platform")->where(["id"=> $param['platform_id'],"is_del"=>0])->findOrEmpty();
  53. if (empty($payinfo)) throw new \Exception("未找到平台信息");
  54. if ($payinfo['status'] != 1) throw new \Exception("平台信息已禁用");
  55. if($payinfo['is_select_pay_rate']==1 && channel_is_company($param['platform_id'],$param['companyNo'])){
  56. throw new \Exception("渠道还有供应商业务公司");
  57. }
  58. $supplierinfo = $userCommon->handle("hqInfo",["code"=>$param['supplierNo']]);
  59. if(!isset($supplierinfo['data'])|| empty($supplierinfo['data']))throw new \Exception("未找到供应商数据");
  60. $person =$supplierinfo['data']['child']??["person"=>'',"person_id"=>0];
  61. if($param['companyNo'] == $supplierinfo['data']['relation_code']) throw new \Exception("供应商和业务公司不能为同一家公司");
  62. $qrddata = [
  63. "orderCode" => $qrdcode,
  64. "apply_id" => $param['apply_id'],
  65. "apply_name" => $param['apply_name'],
  66. "order_type" => 3,
  67. "order_source" => 9,
  68. "platform_id" => $param['platform_id'],
  69. "good_code" => $goodCode,
  70. "skuCode" => '',
  71. "cat_id" => $param['cat_id'],
  72. "good_name" => $param['good_name'],
  73. "good_num" => $param['good_num'],
  74. "good_type" => 1,
  75. "origin_price" => $param['cgd_price'],
  76. "sale_price" => $param['sale_price'],
  77. "total_price" =>$param['sale_total'] ,
  78. "post_fee" => 0,
  79. "is_diff" => 0,
  80. "is_activity" => 0,
  81. "activity_code" => '',
  82. "is_stock" => 0,
  83. "arrive_time" => $param['sendtime'],
  84. "customer_code" => $param['customerNo'],
  85. "customerName" => $param['customerName'],
  86. "supplierNo" => $param['companyNo'],
  87. "supplierName" =>$param['companyName'],
  88. "supName" => $param['supplierName'],
  89. "supNo" => $param['supplierNo'],
  90. "platform_order" => $param['poCode'],
  91. "send_num" => $param['good_num'],
  92. "wsend_num" => 0,
  93. "send_status" => 3,
  94. "send_type" => 1,
  95. "status" => 2,
  96. "is_del" => 0,
  97. "pay_id" => 0,
  98. "workNo" => $param['workCode'],
  99. "addtime" => date("Y-m-d H:i:s"),
  100. "updatetime" => date("Y-m-d H:i:s"),
  101. "cgderid" => $person['personid'],
  102. "cgder" => $person['person'],
  103. "good_createrid" =>$param['apply_id'],
  104. "good_creater" => $param['apply_name'],
  105. 'manager'=>$param['manager'],
  106. 'managerid'=>$param['managerid'],
  107. ];
  108. $orderCgd = [
  109. "orderCode" => $qrdcode,
  110. "cgdNo" => $cgddcode,
  111. "spuCode" => $goodCode,
  112. "good_num" => $param['good_num'],
  113. "wsend_num" => 0,
  114. "send_num" => $param['good_num'],
  115. "wait_num" => 0
  116. ];
  117. $cgddata = [
  118. "cgdNo" => $cgddcode,
  119. "bkcode" => '',
  120. "wsm_code" => "",
  121. "cgder_id" => $person['personid'],
  122. 'cgder' => $person['person'],
  123. "spuCode" => $goodCode,
  124. "good_name" => $param['good_name'],
  125. "good_num" => $param['good_num'],
  126. "good_price" => $param['cgd_price'],
  127. "total_fee" => $param['cgd_total'] ,
  128. "origin_total" => $param['cgd_total'] ,
  129. "supplierNo" => $param['supplierNo'],
  130. "supplier_name" =>$param['supplierName'],
  131. "companyNo" => $param['companyNo'],
  132. "companyName" => $param['companyName'],
  133. "send_status" => 3,
  134. "send_num" => $param['good_num'],
  135. "wsend_num" => 0,
  136. "status" => 3,
  137. "lasttime" => date("Y-m-d H:i:s"),
  138. "order_type" => 3,
  139. "order_source" => 9,
  140. "addtime" => date("Y-m-d H:i:s"),
  141. "updatetime" => date("Y-m-d H:i:s"),
  142. "good_createrid" =>$param['apply_id'],
  143. "good_creater" => $param['apply_name']
  144. ];
  145. $goodinfo = [
  146. "spuCode" => $goodCode,
  147. "good_name" => $param['good_name'],
  148. "brand_id" => 0,
  149. "cat_id" => $param['cat_id'],
  150. "good_unit" => $param['good_unit'],
  151. "good_type" => 1,
  152. "moq" => 1,
  153. "customized" => 0,
  154. "platform_id" => $param['platform_id'],
  155. "tax" => $param['good_tax'],
  156. "supplierNo" => $param['supplierNo'],
  157. "supplierName" =>$param['supplierName'],
  158. "is_auth" => 1,
  159. "craft_desc" => '',
  160. "good_remark" => '',
  161. "good_img" => '',
  162. "good_thumb_img" => '',
  163. "good_info_img" => '',
  164. "createrid" => $param['apply_id'],
  165. "creater" => $param['apply_name'],
  166. "specinfo" => '',
  167. "work_day" => 0,
  168. "noble_metal" => 0,
  169. "good_weight" => 0,
  170. "config" => "",
  171. "weight" => 0,
  172. "supply_area" => 0,
  173. "is_diff" => 0,
  174. "pay_way" => 0,
  175. "send_way" => 0,
  176. 'order_type' => 3,
  177. 'order_source' => 9,
  178. 'order_createrid' =>$param['apply_id'],
  179. 'order_creater' => $param['apply_name'],
  180. "companyNo" => $param['companyNo'],
  181. "companyName" =>$param['companyName'],
  182. "addtime" => date("Y-m-d H:i:s"),
  183. "updatetime" => date("Y-m-d H:i:s"),
  184. ];
  185. $orderAddr = [
  186. "orderCode" => $qrdcode,
  187. "addr" => $param['addr'],
  188. "addr_code" => '',
  189. "contactor" => $param['contactor'],
  190. "mobile" => $param['mobile'],
  191. "arrive_time" => $param['sendtime'],
  192. "customer_code" => $param['customerNo'],
  193. "receipt_quantity" => $param['good_num'],
  194. "addtime" => date("Y-m-d H:i:s"),
  195. "updatetime" => date("Y-m-d H:i:s"),
  196. ];
  197. $qrd = Db::name("sale")->insert($qrddata);
  198. if ($qrd == false) throw new \Exception("销售单生成失败");
  199. $qrd = Db::name("order_num")->insert($orderCgd);
  200. if ($qrd == false) throw new \Exception("销售单采购管联生成失败");
  201. $qrd = Db::name("purchease_order")->insert($cgddata);
  202. if ($qrd == false) throw new \Exception("采购单生成失败");
  203. $qrd = Db::name("good_zixun")->insert($goodinfo);
  204. if ($qrd == false) throw new \Exception("商品信息录入生成失败");
  205. $qrd = Db::name("order_addr")->insert($orderAddr);
  206. if ($qrd == false) throw new \Exception("销售单地址生成失败");
  207. return ["orderCode"=>$qrdcode,"cgdCode"=>$cgddcode];
  208. }
  209. }