Fill.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\bbc\controller;
  4. use app\admin\model\BargainOrder;
  5. use app\admin\model\ConsultBids;
  6. use app\admin\model\ConsultInfo;
  7. use app\admin\model\GoodNake;
  8. use app\admin\model\GoodPlatform;
  9. use app\admin\model\GoodZixun;
  10. use app\admin\model\OrderAddr;
  11. use app\admin\model\OrderOut;
  12. use app\admin\model\OrderOutChild;
  13. use app\admin\model\Sale;
  14. use app\bbc\model\BbcFill;
  15. use app\model\Headquarters;
  16. use app\model\Supplier;
  17. use think\App;
  18. use think\facade\Validate;
  19. use think\Request;
  20. class Fill extends Base
  21. {
  22. protected $model=null;
  23. public function __construct(App $app) {
  24. parent::__construct($app);
  25. $this->model=new BbcFill();
  26. }
  27. /**
  28. * 显示资源列表
  29. *
  30. * @return \think\Response
  31. */
  32. public function list()
  33. {
  34. $param=$this->request->param(["cat_id"=>"","start"=>"",'end'=>'',"fillCode"=>"","status"=>"","good_name"=>"",
  35. "spuCode"=>"","companyNo"=>"","customerCode"=>"","is_compliance"=>"","page"=>1,"size"=>15],"post","trim");
  36. $where=[];
  37. $param['companyNo']==""?:$where[]=["companyNo","like","%{$param['companyNo']}%"];
  38. $param['customerCode']==""?:$where[]=["customerCode","like","%{$param['customerCode']}%"];
  39. $param['fillCode']==""?:$where[]=["fillCode","like","%{$param['fillCode']}%"];
  40. $param['good_name']==""?:$where[]=["good_name","like","%{$param['good_name']}%"];
  41. $param['spuCode']==""?:$where[]=["spuCode","like","%{$param['spuCode']}%"];
  42. $param['is_compliance']===""?:$where[]=["is_compliance","=",$param['is_compliance']];
  43. $param['cat_id']===""?:$where[]=["cat_id","=",$param['cat_id']];
  44. $param['status']===""?:$where[]=["status","=",$param['status']];
  45. $list=$this->model->with(["unitT","cat","brand","platform"])
  46. ->where($where)
  47. ->order("id desc")
  48. ->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
  49. $this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
  50. }
  51. /**
  52. * 显示创建资源表单页.
  53. *
  54. * @return \think\Response
  55. */
  56. public function create()
  57. {
  58. $param = $this->request->param([
  59. "companyNo"=>"",
  60. "customerCode"=>"",
  61. "platform_id"=>"",
  62. "good_num"=>"",
  63. "good_price"=>"",
  64. "skuCode"=>"",
  65. "manager"=>"",
  66. "managerid"=>"",
  67. "fill_remark"=>""
  68. ],"post","trim");
  69. $valid=Validate::rule([
  70. "companyNo|业务公司"=>"require|max:255",
  71. "customerCode|客户公司"=>'require|max:255',
  72. "platform_id|平台"=>'require|number',
  73. "good_num|商品数量"=>'require|number|gt:0',
  74. "good_price|商品单价"=>'require|float|gt:0',
  75. "skuCode|商品编号"=>'require|max:255',
  76. 'manager|业务经理'=>'require',
  77. 'managerid|业务经理id'=>'require',
  78. 'fill_remark|订单备注'=>'require'
  79. ]);
  80. if($valid->check($param)==false) $this->error($valid->getError());
  81. $head=new Headquarters();
  82. $company = $head->where(["code"=>[$param['companyNo'],$param['customerCode']]])->column("name","code");
  83. if(empty($company))$this->error("未找到相关业务公司/客户名称信息");
  84. $goodinfo = (new GoodPlatform())->alias("a")->leftJoin("good b","a.spuCode=b.spuCode")
  85. ->where("skuCode",$param['skuCode'])
  86. ->field("skuCode,b.spuCode,platform_code platform_id,plat_code,good_name,
  87. cat_id,exam_status,brand_id,good_unit unit_id,supplierNo,supplierName,if(is_stock=1,1,2) fill_type")
  88. ->findOrEmpty();
  89. if($goodinfo->isEmpty()) $this->error("商品信息未找到");
  90. if($goodinfo->exam_status!=3) $this->error("商品未上线");
  91. $origin_price=0;
  92. if($goodinfo->fill_type==2){
  93. $origin =(new GoodNake())->where([['spuCode', '=', $goodinfo->spuCode], ['min_num', '<=', $param['good_num']],
  94. ['is_del', '=', 0]])->order('min_num desc')->findOrEmpty();
  95. if ($origin->isEmpty()) $this->error('未找到商品相关阶梯成本价格');
  96. $origin_price = $origin->nake_total;
  97. }
  98. $data=[
  99. "fillCode"=>makeNo("BF"),
  100. "total_price"=>bcmul($param['good_num'],$param['good_price'],4),
  101. "origin_price"=>$origin_price,
  102. "apply_id"=>$this->uid,
  103. "apply_name"=>$this->uname,
  104. "status"=>1,
  105. "is_compliance"=>1,
  106. "companyName"=>$company[$param['companyNo']]?:"",
  107. "customerName"=>$company[$param['customerCode']]?:"",
  108. ];
  109. $create= array_merge($data,$param,$goodinfo->toArray());
  110. BbcFill::create($create);
  111. $this->success("业务报备信息创建成功");
  112. }
  113. /**
  114. * 是否合规审核
  115. *
  116. * @param \think\Request $request
  117. * @return \think\Response
  118. */
  119. public function compliance()
  120. {
  121. $param=$this->request->param(["id"=>"","is_compliance"=>"","plat_code"=>"","compliance_remark"=>""],"post","trim");
  122. $valid =Validate::rule([
  123. "id|主键id"=>"require|number|gt:0",
  124. "is_compliance|是否合规"=>"require|number|in:1,2",
  125. "compliance_remark|合规备注"=>"requireIf:is_compliance,2",
  126. "plat_code|BBC平台商品编号"=>"requireIf:is_compliance,1"
  127. ]);
  128. if($valid->check($param)==false) $this->error($valid->getError());
  129. $info= $this->model->findOrEmpty($param['id']);
  130. if($info->isEmpty())$this->error("未找到报备单数据");
  131. $info->is_compliance = $param['is_compliance'];
  132. $info->compliance_remark = $param['compliance_remark'];
  133. $info->plat_code = $param['plat_code'];
  134. $up =$info->save();
  135. $up?$this->success("报备单更新成功"):$this->error("报备单更新失败");
  136. }
  137. /**
  138. 报备转单
  139. */
  140. public function transfer()
  141. {
  142. $param = $this->request->only([
  143. 'id'=>"",
  144. 'addr_list'=>[],
  145. 'customerCode'=>'',
  146. "poCode"=>""
  147. ], 'post',"trim");
  148. $val = Validate::rule([
  149. 'id|报备的主键id' => 'require|number|gt:0',
  150. 'customerCode|客户编号'=>'require|max:255',
  151. 'addr_list|收货地址' => 'require|array|max:100',
  152. 'poCode|平台订单号' => 'require|max:255',
  153. ]);
  154. if ($val->check($param)==false)$this->error( $val->getError());
  155. $val2 = Validate::rule([
  156. 'receipt_quantity|收货数量' => 'require|number|gt:0|max:999999999',
  157. 'contactor|联系人' => 'require|max:255',
  158. 'mobile|联系电话' => 'require|mobile',
  159. 'addr_code|收货省市区编码' => 'array|length:3',
  160. 'addr|详细地址' => 'require|max:255',
  161. ]);
  162. $info = $this->model->findOrEmpty($param['id']);
  163. if($info->isEmpty()) $this->error("未找到报备单数据");
  164. if($info->status==3 ||$info->status==4 )$this->error('报备单数据'.BbcFill::$status_cn[$info->status]);
  165. $head=new Headquarters();
  166. $company = $head->where(['code'=>$param['customerCode']])->findOrEmpty();
  167. if($company->isEmpty())$this->error('未找到相关客户名称信息');
  168. if($info->fill_type!=3) $good =(new \app\admin\model\Good())->where(["spuCode"=>$info->spuCode])->findOrEmpty();
  169. else $good=(new ConsultBids())->where(['spuCode'=>$info->spuCode])->findOrEmpty();
  170. if($good->isEmpty())$this->error('未找到商品信息');
  171. $supplier = (new Supplier())->where(["code"=>$info->supplierNo])->findOrEmpty();
  172. if($supplier->isEmpty())$this->error('未找到供应商信息');
  173. $orderCode= makeNo("QR");
  174. $orderArr=[];
  175. $transNum=0;
  176. foreach ($param["addr_list"] as $item){
  177. if ($val2->check($item)==false)$this->error( $val2->getError());
  178. $temp=['orderCode' => $orderCode,
  179. 'addr' => $item['addr'],
  180. 'addr_code' =>empty( $item['addr_code'])?'': implode(',', $item['addr_code']),
  181. 'contactor' => $item['contactor'],
  182. 'mobile' => $item['mobile'],
  183. 'customer_code' => $param['customerCode'],
  184. 'post_fee' => 0,
  185. 'receipt_quantity' => $item['receipt_quantity'],
  186. 'is_del' => 0,
  187. 'addtime' => date("Y-m-d H:i:s"),
  188. 'updatetime' => date('Y-m-d H:i:s')
  189. ];
  190. $transNum+=$item['receipt_quantity'];
  191. $orderArr[]=$temp;
  192. }
  193. if($info->fill_type==1 && $good->usable_stock< $transNum) $this->error('商品可用库存不足');
  194. $orderInfo=[
  195. 'orderCode' => $orderCode,
  196. 'apply_id' => $this->uid,
  197. 'apply_name' => $this->uname,
  198. 'order_type' => $info->fill_type,//报备商品
  199. 'order_source' => 11,//业务报备转单
  200. 'platform_id' => $info->platform_id,
  201. 'good_code' => $info->spuCode,
  202. 'skuCode' => $info->skuCode,
  203. 'cat_id' => $info->cat_id,
  204. 'good_name' => $info->good_name,
  205. 'good_num' => $transNum,
  206. 'good_type' => 1,
  207. 'origin_price' => $info->origin_price,
  208. 'sale_price' => round($info->good_price,2),
  209. 'total_price' => round(bcmul($info->good_price, strval($transNum), 4), 2),
  210. 'post_fee' => 0,
  211. 'is_diff' => $good->is_diff,
  212. 'is_activity' => 0,
  213. 'activity_code' => '',
  214. 'is_stock' => 0,
  215. 'customer_code' => $param['customerCode'],
  216. 'customerName' => $company['name'],
  217. 'supplierNo' => $info->companyNo,
  218. 'supplierName' => $info->companyName,
  219. 'supNo' =>$info->supplierNo,
  220. 'supName' => $info->supplierName,
  221. 'zxNo' =>$good->bidNo?: '',
  222. 'platform_order' =>$param['poCode'],
  223. 'send_num' => 0,
  224. 'wsend_num' =>$transNum,
  225. 'th_num' => 0,
  226. 'th_fee' => 0,
  227. 'send_status' => 1,
  228. 'send_type' => 1,//直接发货
  229. 'remark' => '',
  230. 'status' => 0,
  231. 'is_del' => 0,
  232. 'proof_id' => 0,
  233. 'other_orderNo' => $info->fillCode,
  234. 'workNo' => '',
  235. 'poNo' => '',
  236. 'use_order' => 0,
  237. 'good_weight' => 0,
  238. 'gold_price' => 0,
  239. 'cost_price' => $good->cost_fee,
  240. 'diff_weight' => 0,
  241. 'diff_fee' => 0,
  242. 'returnCode' => '',
  243. 'addtime' => date("Y-m-d H:i:s"),
  244. 'updatetime' =>date('Y-m-d H:i:s'),
  245. 'cgderid' => $supplier->personid,
  246. 'cgder' => $supplier->person,
  247. 'good_createrid' => $good['createrid'],
  248. 'good_creater' =>$good['createrid'],
  249. 'manager'=>$info->manager,
  250. 'managerid'=>$info->managerid
  251. ];
  252. $this->model->startTrans();
  253. try{
  254. $ist =$this->model->lock(true)->findOrEmpty($param['id']);
  255. if($ist->wtrans_num< $transNum)throw new \Exception('报备单可转单数量不足!');
  256. $order=Sale::create($orderInfo);
  257. if($order->id==false) throw new \Exception("订单创建失败");
  258. $Addr=(new OrderAddr())->saveAll($orderArr);
  259. //库存品转单直接生成数据
  260. if($info->fill_type==1){
  261. $up = (new \app\admin\model\Good())->where(["spuCode"=>$info->spuCode])->lock(true)->findOrEmpty();
  262. if($up->isEmpty())throw new \Exception('未找到商品信息');
  263. if($up->usable_stock< $transNum)throw new \Exception('商品可用库存不足');
  264. $up->usable_stock= $up->usable_stock-$transNum;
  265. $up->updatetime=date('Y-m-d H:i:s');
  266. $goodUp=$up->save();
  267. if($goodUp==false)throw new \Exception('商品库存修改失败');
  268. }
  269. $i=0;
  270. foreach ($Addr as $item){
  271. $outCode = substr(makeNo('DF'), 0, -2) . str_pad(strval($i), 2, '0', STR_PAD_LEFT);
  272. $i++;
  273. $out=[
  274. 'orderCode' => $orderCode,
  275. 'outCode' => $outCode,
  276. 'apply_id' => $this->uid,
  277. 'apply_name' => $this->uname,
  278. 'addrid' => $item->id,
  279. 'post_name' => '',
  280. 'post_code' => '',
  281. 'post_fee' => 0,
  282. 'sendtime' => date('Y-m-d H:i:s'),
  283. 'send_num' => $item->receipt_quantity,
  284. 'check_num' => 0,
  285. 'error_num' => 0,
  286. 'wsm_code' => '',
  287. 'order_type' =>$info->fill_type,
  288. 'status' => 0,
  289. 'send_status' => $info->fill_type==1?1:0,
  290. 'addtime' => date('Y-m-d H:i:s'),
  291. 'updatetime' => date('Y-m-d H:i:s')
  292. ];
  293. $outinfo=OrderOut::create($out);
  294. if($outinfo->isEmpty())throw new \Exception('发货单创建失败');
  295. if($info->fill_type==1)OrderOutChild::makeChild($outCode);
  296. }
  297. $ist->transfer_num +=$transNum;
  298. $ist->status=$ist->transfer_num >= $ist->good_num?3:2;
  299. $upd=$ist->save();
  300. if($upd==false)throw new \Exception('报备单更新失败');
  301. $this->model->commit();
  302. //非库存数据需要生成采购单 异步监听事件处理 需要注意采购单生成失败无法回滚
  303. if($info->fill_type!==1){
  304. event("CgdCreate",$orderCode);
  305. }
  306. $event=[ 'order_type' => 'CKD',
  307. 'order_code' =>$outCode,//咨询单详情编号
  308. 'order_id' => $outinfo->id,
  309. 'order_status' => 2,
  310. 'action_process' =>1,
  311. 'action_status' => $info->fill_type!==1?0:1,
  312. 'action_uid' => $this->uid,
  313. 'action_name' => $this->uname,
  314. ];
  315. event('ProcessOrder',$event);
  316. $event=[ 'order_type' => 'XSQRD',
  317. 'order_code' =>$orderCode,//咨询单详情编号
  318. 'order_id' => $order->id,
  319. 'order_status' => 2,
  320. 'action_process' =>0,
  321. 'action_status' => 0,
  322. 'action_uid' => $this->uid,
  323. 'action_name' => $this->uname,
  324. ];
  325. event('ProcessOrder',$event);
  326. }catch (\Exception $exception){
  327. $this->model->rollback();
  328. $this->error($exception->getMessage());
  329. }
  330. $this->success("转单成功",["orderCode"=>$orderCode]);
  331. }
  332. /**
  333. * 咨询订单转业务报备
  334. */
  335. public function ZixunCreate()
  336. {
  337. $param=$this->request->param(["bidNo"=>"","sale_price"=>"","manager"=>"","managerid"=>"","good_num"=>"",
  338. "proof_type"=>"",'proof_url'=>'',"remark"=>""],"post","trim");
  339. $valid = Validate::rule([
  340. "bidNo|咨询竞价单号"=>"require",
  341. "sale_price|商品单价"=>"require|float|gt:0",
  342. "manager|业务经理"=>"require|max:255",
  343. "managerid|业务经理id"=>"require|number|gt:0",
  344. "good_num|商品数量"=>"require|number|gt:0",
  345. "proof_type|凭证类型"=>"require|number|in:0,1,2,3",
  346. "proof_url|凭证地址"=>"require"
  347. ]);
  348. if($valid->check($param)==false)$this->error($valid->getError());
  349. $bids=new ConsultBids();
  350. $info = $bids->where(["bidNo"=>$param["bidNo"],"is_del"=>0])->findOrEmpty();
  351. if($info->isEmpty()) $this->error("竞价单信息未找到");
  352. if( $param['sale_price'] < $info['sale_price']) $this->error('修改的销售单价不能低于原来的销售单价');
  353. $coninfo= new ConsultInfo();
  354. $this->model->startTrans();
  355. try{
  356. $zxinfo = $coninfo->with('consult_order')->where(['infoNo' => $info['infoNo'], 'is_del' => 0])->lock(true)->findOrEmpty();
  357. if($zxinfo->isEmpty()) throw new \Exception("未找到咨询单信息");
  358. if($zxinfo->is_project!=2) throw new \Exception("咨询单类型有误");
  359. $data=[
  360. 'fillCode'=>makeNo('BF'),
  361. 'fill_type'=>3,
  362. 'skuCode'=>'',
  363. 'spuCode'=>$info->spuCode,
  364. 'good_name'=>$info->good_name,
  365. 'unit_id'=>$info->unit_id,
  366. 'brand_id'=>$info->brand_id,
  367. 'cat_id'=>$info->cat_id,
  368. 'good_num'=>$param['good_num'],
  369. 'good_price'=>$param['sale_price'],
  370. 'platform_id'=>$zxinfo->platform_id,
  371. 'total_price'=>bcmul($param['good_num'],$param['sale_price'],4),
  372. 'origin_price'=>$info->total_fee,
  373. 'apply_id'=>$this->uid,
  374. 'apply_name'=>$this->uname,
  375. 'status'=>1,
  376. 'companyNo'=>$zxinfo->companyNo,
  377. 'companyName'=>$zxinfo->companyName,
  378. 'customerCode'=>$zxinfo->khNo,
  379. 'customerName'=>$zxinfo->khName,
  380. 'supplierNo'=>$info->supplierNo,
  381. 'supplierName'=>$info->supplierName,
  382. 'is_compliance'=>0,
  383. 'plat_code'=>'',
  384. 'fill_remark'=>$param['remark'],
  385. 'manager'=>$param['manager'],
  386. 'managerid'=>$param['managerid'],
  387. ];
  388. $bbcCre=BbcFill::create($data);
  389. if($bbcCre->id==false) throw new \Exception('报备单创建失败');
  390. BargainOrder::update(["status"=>4],['bidsNo' =>$param['bidNo'],'is_del'=>0,'status'=>0]);
  391. $info->status=6;
  392. $up =$info->save();
  393. if($up==false) throw new \Exception('竞价单状态更新失败');
  394. $zxinfo->status=5;
  395. $zxup=$zxinfo->save();
  396. if($zxup==false) throw new \Exception('咨询单状态更新失败');
  397. $limt = [
  398. 'spuCode' => $info['spuCode'],
  399. 'good_name' => $info['good_name'],
  400. 'brand_id' => $info['brand_id'],
  401. 'good_unit' => $info['unit_id'],
  402. 'cat_id' => $info['cat_id'],
  403. 'good_type' => 0,
  404. 'moq' => 1,
  405. 'customized' => $info['work_day'],
  406. 'tax' => $info['tax'],
  407. 'supplierNo' => $info['supplierNo'],
  408. 'supplierName' =>$info['supplierName'],
  409. 'is_auth' => 0,
  410. 'craft_desc' => $info['good_name'],
  411. 'good_remark' => '',
  412. 'platform_id' => $zxinfo['platform_id'],
  413. 'good_img' => $info['good_img'],
  414. 'good_thumb_img' => '',
  415. 'good_info_img' => '',
  416. 'specinfo' => $info['specinfo'],
  417. 'work_day' => $info['work_day'],
  418. 'noble_metal' => $info['metal_id'],
  419. 'is_gold_price' => $info['is_gold_price'],
  420. 'config' => $info['config'],
  421. 'other_config' => $info['other_config'],
  422. 'weight' => $info['weight'],
  423. 'good_weight' => $info['good_weight'],
  424. 'is_diff' => $info['is_diff'],
  425. 'supply_area' => $info['supply_area'],
  426. 'pay_way' => $info['pay_way'],
  427. 'send_way' => $info['send_way'],
  428. 'companyNo' => $zxinfo['companyNo'],
  429. 'companyName' =>$zxinfo['companyName'],
  430. 'status' => 1,
  431. 'is_del' => 0,
  432. 'order_type' => 3,
  433. 'order_source' => 11,
  434. 'createrid' => $zxinfo['createrid'],
  435. 'creater' => $zxinfo['creater'],
  436. 'order_createrid' => $this->uid,
  437. 'order_creater' => $this->uname,
  438. 'addtime' => date('Y-m-d H:i:s'),
  439. 'updatetime' => date('Y-m-d H:i:s'),
  440. 'proof_type' => $param['proof_type'],//凭证类型
  441. 'proof_url' => $param['proof_url'],//凭证文件
  442. ];
  443. GoodZixun::create($limt);
  444. $this->model->commit();
  445. }catch (\Exception $exception){
  446. $this->model->rollback();
  447. $this->error($exception->getMessage().$exception->getLine());
  448. }
  449. $this->success("报备单生成成功",["fillCode"=>$data['fillCode']]);
  450. }
  451. /**
  452. * 保存更新的资源
  453. *
  454. * @param \think\Request $request
  455. * @param int $id
  456. * @return \think\Response
  457. */
  458. public function info()
  459. {
  460. $id = $this->request->post("id");
  461. $info =$this->model->with(['unitT','cat','brand',"platform"])->findOrEmpty($id);
  462. if($info->isEmpty()) $this->error("未找到数据");
  463. $this->success("获取成功",$info);
  464. }
  465. }