123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- declare (strict_types = 1);
- namespace app\command;
- use app\admin\common\User;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Argument;
- use think\console\input\Option;
- use think\console\Output;
- use think\facade\Db;
- use think\facade\Cache;
- class InterMakeOrder extends Command
- {
- protected function configure()
- {
- // 指令配置
- $this->setName('intermakeorder')
- ->setDescription('the intermakeorder command');
- }
- protected function execute(Input $input, Output $output)
- {
- $date=date("Y-m-d H:i:s");
- $rs = Cache::store('redis')->get('intermakeorder');
- if ($rs) return true;
- Cache::store('redis')->set("intermakeorder", 1, 5);
- Db::startTrans();
- $interinfo =Db::name("inter_order")->where(["status"=>1,"is_del"=>0])->lock(True)->findOrEmpty();
- if(empty($interinfo)){ Db::rollback();return'';}
- try{
- $result=$this->makeOrder($interinfo);
- $dip=Db::name("inter_order")->where($interinfo )->update(["orderCode"=>$result["orderCode"],
- "cgdCode"=>$result["cgdCode"],"status"=>2,"remark"=>'转单完成',"updatetime"=>date("Y-m-d H:i:s")]);
- if($dip==false) throw new \Exception("录单更新失败");
- Db::commit();
- $output->writeln("[$date] 录单{$interinfo['interNo']} 转单成功");
- }catch (\Exception $exception){
- Db::rollback();
- Db::name("inter_order")->where($interinfo)->update(["status"=>3,"remark"=>$exception->getMessage(),"updatetime"=>date("Y-m-d H:i:s")]);
- $output->writeln("[$date] 录单{$interinfo['interNo']} 转单失败|".$exception->getMessage());
- }
-
- }
- /**
- * @param $param
- * @return array
- * @throws \Exception
- */
- private function makeOrder($param):array{
- $qrdcode = makeNo("QR");
- $cgddcode = makeNo("CG");
- $goodCode = makeNo("SKU");
- $userCommon = User::getIns();
- $payinfo = Db::name("platform")->where(["id"=> $param['platform_id'],"is_del"=>0])->findOrEmpty();
- if (empty($payinfo)) throw new \Exception("未找到平台信息");
- if ($payinfo['status'] != 1) throw new \Exception("平台信息已禁用");
- if($payinfo['is_select_pay_rate']==1 && channel_is_company($param['platform_id'],$param['companyNo'])){
- throw new \Exception("渠道还有供应商业务公司");
- }
- $supplierinfo = $userCommon->handle("hqInfo",["code"=>$param['supplierNo']]);
- if(!isset($supplierinfo['data'])|| empty($supplierinfo['data']))throw new \Exception("未找到供应商数据");
- $person =$supplierinfo['data']['child']??["person"=>'',"person_id"=>0];
- if($param['companyNo'] == $supplierinfo['data']['relation_code']) throw new \Exception("供应商和业务公司不能为同一家公司");
- $qrddata = [
- "orderCode" => $qrdcode,
- "apply_id" => $param['apply_id'],
- "apply_name" => $param['apply_name'],
- "order_type" => 3,
- "order_source" => 9,
- "platform_id" => $param['platform_id'],
- "good_code" => $goodCode,
- "skuCode" => '',
- "cat_id" => $param['cat_id'],
- "good_name" => $param['good_name'],
- "good_num" => $param['good_num'],
- "good_type" => 1,
- "origin_price" => $param['cgd_price'],
- "sale_price" => $param['sale_price'],
- "total_price" =>$param['sale_total'] ,
- "post_fee" => 0,
- "is_diff" => 0,
- "is_activity" => 0,
- "activity_code" => '',
- "is_stock" => 0,
- "arrive_time" => $param['sendtime'],
- "customer_code" => $param['customerNo'],
- "customerName" => $param['customerName'],
- "supplierNo" => $param['companyNo'],
- "supplierName" =>$param['companyName'],
- "supName" => $param['supplierName'],
- "supNo" => $param['supplierNo'],
- "platform_order" => $param['poCode'],
- "send_num" => $param['good_num'],
- "wsend_num" => 0,
- "send_status" => 3,
- "send_type" => 1,
- "status" => 2,
- "is_del" => 0,
- "pay_id" => 0,
- "workNo" => $param['workCode'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- "cgderid" => $person['personid'],
- "cgder" => $person['person'],
- "good_createrid" =>$param['apply_id'],
- "good_creater" => $param['apply_name'],
- 'manager'=>$param['manager'],
- 'managerid'=>$param['managerid'],
- ];
- $orderCgd = [
- "orderCode" => $qrdcode,
- "cgdNo" => $cgddcode,
- "spuCode" => $goodCode,
- "good_num" => $param['good_num'],
- "wsend_num" => 0,
- "send_num" => $param['good_num'],
- "wait_num" => 0
- ];
- $cgddata = [
- "cgdNo" => $cgddcode,
- "bkcode" => '',
- "wsm_code" => "",
- "cgder_id" => $person['personid'],
- 'cgder' => $person['person'],
- "spuCode" => $goodCode,
- "good_name" => $param['good_name'],
- "good_num" => $param['good_num'],
- "good_price" => $param['cgd_price'],
- "total_fee" => $param['cgd_total'] ,
- "origin_total" => $param['cgd_total'] ,
- "supplierNo" => $param['supplierNo'],
- "supplier_name" =>$param['supplierName'],
- "companyNo" => $param['companyNo'],
- "companyName" => $param['companyName'],
- "send_status" => 3,
- "send_num" => $param['good_num'],
- "wsend_num" => 0,
- "status" => 3,
- "lasttime" => date("Y-m-d H:i:s"),
- "order_type" => 3,
- "order_source" => 9,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- "good_createrid" =>$param['apply_id'],
- "good_creater" => $param['apply_name']
- ];
- $goodinfo = [
- "spuCode" => $goodCode,
- "good_name" => $param['good_name'],
- "brand_id" => 0,
- "cat_id" => $param['cat_id'],
- "good_unit" => $param['good_unit'],
- "good_type" => 1,
- "moq" => 1,
- "customized" => 0,
- "platform_id" => $param['platform_id'],
- "tax" => $param['good_tax'],
- "supplierNo" => $param['supplierNo'],
- "supplierName" =>$param['supplierName'],
- "is_auth" => 1,
- "craft_desc" => '',
- "good_remark" => '',
- "good_img" => '',
- "good_thumb_img" => '',
- "good_info_img" => '',
- "createrid" => $param['apply_id'],
- "creater" => $param['apply_name'],
- "specinfo" => '',
- "work_day" => 0,
- "noble_metal" => 0,
- "good_weight" => 0,
- "config" => "",
- "weight" => 0,
- "supply_area" => 0,
- "is_diff" => 0,
- "pay_way" => 0,
- "send_way" => 0,
- 'order_type' => 3,
- 'order_source' => 9,
- 'order_createrid' =>$param['apply_id'],
- 'order_creater' => $param['apply_name'],
- "companyNo" => $param['companyNo'],
- "companyName" =>$param['companyName'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- $orderAddr = [
- "orderCode" => $qrdcode,
- "addr" => $param['addr'],
- "addr_code" => '',
- "contactor" => $param['contactor'],
- "mobile" => $param['mobile'],
- "arrive_time" => $param['sendtime'],
- "customer_code" => $param['customerNo'],
- "receipt_quantity" => $param['good_num'],
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- $qrd = Db::name("sale")->insert($qrddata);
- if ($qrd == false) throw new \Exception("销售单生成失败");
- $qrd = Db::name("order_num")->insert($orderCgd);
- if ($qrd == false) throw new \Exception("销售单采购管联生成失败");
- $qrd = Db::name("purchease_order")->insert($cgddata);
- if ($qrd == false) throw new \Exception("采购单生成失败");
- $qrd = Db::name("good_zixun")->insert($goodinfo);
- if ($qrd == false) throw new \Exception("商品信息录入生成失败");
- $qrd = Db::name("order_addr")->insert($orderAddr);
- if ($qrd == false) throw new \Exception("销售单地址生成失败");
- return ["orderCode"=>$qrdcode,"cgdCode"=>$cgddcode];
- }
- }
|