Salezx.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\GoodLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use app\admin\model\ActionLog;
  8. class Salezx extends \app\BaseController
  9. {
  10. public $post="";
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->post=$this->request->post();
  15. }
  16. public function create(){
  17. $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  18. $orderCode=makeNo("QR");
  19. $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
  20. if($customer_code==""){
  21. return error_show(1002,"客户code不能为空");
  22. }
  23. $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :"";
  24. if($zxinfoNo==""){
  25. return error_show(1002,"参数zxinfoNo 不能为空");
  26. }
  27. $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
  28. if($customer==false){
  29. return error_show(1004,"未找到客户数据");
  30. }
  31. $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  32. if($supplierNo==""){
  33. return error_show(1002,"参数supplierNo不能为空");
  34. }
  35. $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find();
  36. if($supplier==false){
  37. return error_show(1004,"未找到平台供应商数据");
  38. }
  39. $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?trim($this->post['sendtype']):"";
  40. if($sendtype==''){
  41. return error_show(1004,"参数sendtype不能为空");
  42. }
  43. $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):"";
  44. if($platform_id==''){
  45. return error_show(1004,"参数platform_id不能为空");
  46. }
  47. $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
  48. if($platform_order==''){
  49. return error_show(1004,"参数platform_order不能为空");
  50. }
  51. $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
  52. if($good_code==''){
  53. return error_show(1004,"参数good_code不能为空");
  54. }
  55. $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
  56. if($good==false){
  57. return error_show(1004,"未找到商品数据");
  58. }
  59. $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$good['spuCode'],"is_del"=>0])->find();
  60. if($goodinfo==false){
  61. return error_show(1004,"未找到商品数据");
  62. }
  63. $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
  64. if($good_num===''){
  65. return error_show(1004,"参数good_num不能为空");
  66. }
  67. $good_num =isset($this->post['p']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
  68. if($good_num===''){
  69. return error_show(1004,"参数good_num不能为空");
  70. }
  71. // $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"";
  72. // if($goodtype===''){
  73. // return error_show(1004,"参数goodtype不能为空");
  74. // }
  75. $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  76. if($arrtime==""){
  77. return error_show(1004,"参数arrtime不能为空");
  78. }
  79. $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  80. if($sendtype==1){
  81. $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  82. if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  83. return error_show(1004,"参数addrlist不能为空");
  84. }
  85. }
  86. $apply_id =GetUserInfo($token);
  87. if(empty($apply_id)||$apply_id['code']!=0){
  88. return error_show(1002,"申请人数据不存在");
  89. }
  90. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  91. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  92. Db::startTrans();
  93. try {
  94. $data=[
  95. "orderCode"=>$orderCode,
  96. "good_code"=>$good_code,
  97. "customer_code"=>$customer_code,
  98. "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
  99. "good_num"=>$good_num,
  100. "cat_id"=>$goodinfo['cat_id'],
  101. "apply_id"=>$rm,
  102. "apply_name"=>$ri,
  103. "origin_price"=>$goodinfo['total_fee'],
  104. "sale_price"=>$goodinfo['sale_price'],
  105. "post_fee"=>0,
  106. "status"=>0,
  107. "send_num"=>0,
  108. "wsend_num"=>$good_num,
  109. "send_status"=>1,
  110. "good_type"=>1,
  111. "send_type"=>$sendtype,
  112. "supplierNo"=>$supplierNo,
  113. "is_del"=>0,
  114. "zxNo"=>$zxinfoNo,
  115. "platform_order"=>$platform_order,
  116. "platform_id"=>$platform_id,
  117. "remark"=>$remark,
  118. "order_type"=>2,
  119. "addtime"=>date("Y-m-d H:i:s"),
  120. "updatetime"=>date("Y-m-d H:i:s"),
  121. 'total_price'=>round($goodinfo['sale_price']*$good_num,2),
  122. ];
  123. $datainfo = Db::name('sale')->insert($data,true);
  124. $vat=[];
  125. if($datainfo>0){
  126. $standing_bood_data=[
  127. "orderCode"=>$orderCode,
  128. "customer_code"=>$customer_code,
  129. "supplierNo"=>$supplierNo,
  130. 'updatetime'=>date("Y-m-d H:i:s"),
  131. ];
  132. $bol= $this->createCgd($data,$good,$goodinfo,$standing_bood_data);
  133. if($bol==false){
  134. Db::rollback();
  135. return error_show(1002,"咨询订单创建失败");
  136. }
  137. if($sendtype!=2){
  138. foreach ($addrlist as $value){
  139. $temp=[];
  140. $addrs=[];
  141. if($value['addr_code']!==''&&is_array($value['addr_code'])){
  142. $addrs['provice_code'] = $value['addr_code'][0];
  143. $addrs['city_code'] = $value['addr_code'][1];
  144. $addrs['area_code'] = $value['addr_code'][2];
  145. $addr = json_encode($addrs);
  146. }else{
  147. $addr = isset($value['addr_code'])?$value['addr_code']:'';
  148. }
  149. $temp['orderCode']=$orderCode;
  150. $temp['contactor']=$value['contactor'];
  151. $temp['mobile'] = $value['mobile'];
  152. $temp['addr'] = $value['addr'];
  153. $temp['addr_code']=$addr;
  154. $temp['customer_code'] =$customer_code;
  155. $temp['receipt_quantity']=$value['receipt_quantity'];
  156. $temp['post_fee'] =0;
  157. $temp['is_del'] =0;
  158. $temp['addtime'] =date("Y-m-d H:i:s");
  159. $temp['updatetime'] =date("Y-m-d H:i:s");
  160. $temp['arrive_time']=$value['arrive_time'];
  161. $vmp = Db::name('order_addr')->insert($temp,true);
  162. if($vmp>0){
  163. $outCode=makeNo("DF");
  164. $out=[
  165. "orderCode"=>$orderCode,
  166. "outCode"=>$outCode,
  167. "apply_id"=>$rm,
  168. "apply_name"=>$ri,
  169. "addrid"=>$vmp,
  170. "post_name"=>"",
  171. "post_code"=>"",
  172. "post_fee"=>0,
  173. "sendtime"=>date("Y-m-d H:i:s"),
  174. "send_num"=>$value['receipt_quantity'],
  175. "check_num"=>0,
  176. "error_num"=>0,
  177. "wsm_code"=>"",
  178. "order_type"=>2,
  179. "status"=>0,
  180. "addtime"=>date("Y-m-d H:i:s"),
  181. "updatetime"=>date("Y-m-d H:i:s")
  182. ];
  183. $ou =Db::name("order_out")->insert($out);
  184. if($ou==false){
  185. Db::rollback();
  186. return error_show(1002,"咨询订单创建失败");
  187. }else{
  188. //修改状态,添加待办
  189. ActionLog::logAdd($this->post['token'], [
  190. "order_code" => $outCode,//出库单号
  191. "status" => $out['status'],//这里的status是之前的值
  192. "action_remark" => '',//备注
  193. "action_type" => "create"//新建create,编辑edit,更改状态status
  194. ], "CKD", $out['status'], $out);
  195. ProcessOrder::AddProcess($this->post['token'], [
  196. "order_type" => 'CKD',
  197. "order_code" => $outCode,//出库单号
  198. "order_id" => 0,
  199. "order_status" => $out['status']
  200. ]);
  201. }
  202. }else{
  203. Db::rollback();
  204. return error_show(1002,"咨询订单创建失败");
  205. }
  206. }
  207. }
  208. //修改状态,添加待办
  209. ActionLog::logAdd($this->post['token'], [
  210. "order_code" => $orderCode,//销售单code
  211. "status" => 0,//这里的status是之前的值
  212. "action_remark" => '',//备注
  213. "action_type" => "create"//新建create,编辑edit,更改状态status
  214. ], "XSQRD", 0, $data);
  215. ProcessOrder::AddProcess($this->post['token'], [
  216. "order_type" => 'XSQRD',
  217. "order_code" => $orderCode,//销售单code
  218. "order_id" => $datainfo,
  219. "order_status" => 0
  220. ]);
  221. //根据zxinfoNo查找infoNo,找到则更新台账,否则就新增台账
  222. $infoNo = Db::name('consult_bids')->where('bidNo', $zxinfoNo)->value('infoNo');
  223. if (empty($infoNo)) Db::name('standing_book')->insert(array_merge($standing_bood_data, ['addtime' => date('Y-m-d H:i:s')]));
  224. else Db::name('standing_book')->where('infoNo', $infoNo)->update($standing_bood_data);
  225. Db::commit();
  226. return error_show(0,"咨询订单创建成功");
  227. }
  228. Db::rollback();
  229. return error_show(1002,"咨询订单创建失败");
  230. }catch(\Exception $e){
  231. Db::rollback();
  232. return error_show(1005,$e->getMessage());
  233. }
  234. }
  235. public function createCgd($data,$good,$good_info,array &$standing_bood_data=[]){
  236. $cgdCode = makeNo("CG");
  237. $supplier=Db::name("supplier")->where(["code"=>$good['supplierNo'],"is_del"=>0])->find();
  238. if($supplier==false){
  239. return false;
  240. }
  241. $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$good["supplierNo"],"companyNo"=>$data['supplierNo'],"is_del"=>0])->find();
  242. if($wsm==false){
  243. $wsm_code = makeNo("WSM");
  244. $inwsm=[
  245. "wsm_code"=>$wsm_code,
  246. "name"=>$supplier['name'],
  247. "wsm_type"=>2,
  248. "supplierNo"=>$supplier['code'],
  249. "addr"=>"",
  250. "addrs_code"=>"",
  251. "contactor"=>0,
  252. "contactor_name"=>0,
  253. "mobile"=>"",
  254. "position"=>"",
  255. "companyNo"=>$data['supplierNo'],
  256. "status"=>1,
  257. "is_del"=>0,
  258. "addtime"=>date("Y-m-d H:i:s"),
  259. "updatetime"=>date("Y-m-d H:i:s")
  260. ];
  261. $in = Db::name("warehouse_info")->insert($inwsm);
  262. if($in==false){
  263. return false;
  264. }
  265. }else{
  266. $wsm_code =$wsm['wsm_code'];
  267. }
  268. $cg =["cgdNo"=>$cgdCode,
  269. "bkcode"=>"",
  270. "wsm_code"=>$wsm_code,
  271. "cgder"=>$supplier['person'],
  272. "cgder_id"=>$supplier['personid'],
  273. "good_code"=>$good['spuCode'],
  274. "good_name"=>$good['good_name'],
  275. "good_num"=>$data['good_num'],
  276. "good_price"=>$good_info['sale_price'],
  277. "total_fee"=>$good_info['total_fee'],
  278. "pakge_fee"=>$good_info['pakge_fee'],
  279. "cert_fee"=>$good_info['cert_fee'],
  280. "open_fee"=>$good_info['open_fee'],
  281. "delivery_fee"=>$good_info['delivery_fee'],
  282. "mark_fee"=>$good_info['mark_fee'],
  283. "demo_fee"=>$good_info['demo_fee'],
  284. #"weight"=>$data['weight'],
  285. "diff_weight"=>"0",
  286. "diff_fee"=>"0",
  287. "gold_price"=>"0",
  288. "supplierNo"=>$good['supplierNo'],
  289. "supplier_name"=>$supplier['name'],
  290. "send_status"=>1,
  291. "send_num"=>"0",
  292. "wsend_num"=>$data['good_num'],
  293. "remark"=>"",
  294. "status"=>0,
  295. "lasttime"=>date("Y-m-d H:i:s"),
  296. "is_del"=>0,
  297. "order_type"=>2,
  298. "good_type"=>$good['good_type'],
  299. "addtime"=>date("Y-m-d H:i:s"),
  300. "updatetime"=>date("Y-m-d H:i:s")
  301. ];
  302. $up =Db::name("purchease_order")->insert($cg,true);
  303. if($up){
  304. //修改状态,添加待办
  305. ActionLog::logAdd($this->post['token'], [
  306. "order_code" => $cg['cgdNo'],//销售单code
  307. "status" => 0,//这里的status是之前的值
  308. "action_remark" => '',//备注
  309. "action_type" => "create"//新建create,编辑edit,更改状态status
  310. ], "CGD", $cg['status'], $cg);
  311. ProcessOrder::AddProcess($this->post['token'], [
  312. "order_type" => 'CGD',
  313. "order_code" => $cg['cgdNo'],//销售单code
  314. "order_id" => $up,
  315. "order_status" => $cg['status']
  316. ]);
  317. $standing_bood_data['cgdNo']=$cgdCode;
  318. return true;
  319. }else{
  320. return false;
  321. }
  322. }
  323. // public function edit(){
  324. // $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
  325. //
  326. // $zxNo=isset($this->post['id']) && $this->post['id'] !=="" ?intval($this->post['id']):"";
  327. // if($zxNo==''){
  328. // return error_show(1004,"参数id不能为空");
  329. // }
  330. // $saleinfo = Db::name("sale")->where(["id"=>$zxNo,"is_del"=>0])->find();
  331. // if($saleinfo==false){
  332. // return error_show(1003,"未找到咨询单数据");
  333. // }
  334. // $zxinfo = Db::name("consult")->where(["zxNo"=>$saleinfo['zxNo'],"is_del"=>0])->find();
  335. // if($zxinfo==false){
  336. // return error_show(1004,"未找到咨询单数据");
  337. // }
  338. // $customer_code= $this->post['customer_code'] && $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
  339. // if($customer_code==""){
  340. // return error_show(1002,"客户code不能为空");
  341. // }
  342. // $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
  343. // if($customer==false){
  344. // return error_show(1004,"未找到客户数据");
  345. // }
  346. // $supplierNo= $this->post['supplierNo'] && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  347. // if($supplierNo==""){
  348. // return error_show(1002,"参数supplierNo不能为空");
  349. // }
  350. // $supplier=Db::name("supplier")->where(["code"=>$supplierNo])->find();
  351. // if($supplier==false){
  352. // return error_show(1004,"未找到平台供应商数据");
  353. // }
  354. // $wsm=Db::name("warehouse_info")->where(["supplierNo"=>$zxinfo['gysNo'],"wsm_type"=>2])->find();
  355. // if(empty($wsm)){
  356. // return error_show(1004,"未找到供应商仓库数据");
  357. // }
  358. // $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?trim($this->post['sendtype']):"";
  359. // if($sendtype==''){
  360. // return error_show(1004,"参数sendtype不能为空");
  361. // }
  362. // $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
  363. // if($good_num===''){
  364. // return error_show(1004,"参数good_num不能为空");
  365. // }
  366. // $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"";
  367. // if($goodtype===''){
  368. // return error_show(1004,"参数goodtype不能为空");
  369. // }
  370. // $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  371. // if($sendtype!=2){
  372. // $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  373. // if($addrlist=="" || empty($addrlist)){
  374. // return error_show(1004,"参数addrlist不能为空");
  375. // }
  376. // }
  377. // $apply_id =GetUserInfo($token);
  378. // if(empty($apply_id)||$apply_id['code']!=0){
  379. // return error_show(1002,"申请人数据不存在");
  380. // }
  381. // $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  382. // $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  383. // Db::startTrans();
  384. // try {
  385. // $data=[
  386. // "customer_code"=>$customer_code,
  387. // "good_num"=>$good_num,
  388. // "apply_id"=>$rm,
  389. // "apply_name"=>$ri,
  390. // "wsend_num"=>$good_num,
  391. // "good_type"=>$goodtype,
  392. // "send_type"=>$sendtype,
  393. // "supplierNo"=>$supplierNo,
  394. // "remark"=>$remark,
  395. // "updatetime"=>date("Y-m-d H:i:s"),
  396. // 'total_price'=>round($zxinfo['last_price']*$good_num,2),
  397. // ];
  398. // $datainfo = Db::name('sale')->where(["id"=>$zxNo])->save($data);
  399. // if($datainfo!=false){
  400. // $st = ["order_code"=>$saleinfo['orderCode'],"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  401. // ActionLog::logAdd($this->post['token'],$st,"ZXQRD",0,$data);
  402. // $order=["order_type"=>"ZXQRD","order_code"=>$saleinfo['orderCode'],"order_id"=>$saleinfo['id'],"order_status"=>$saleinfo['status']];
  403. // ProcessOrder::AddProcess($this->post['token'],$order);
  404. // $saleinfos=[
  405. // "wsm_code"=>$wsm['wsm_code'],
  406. // "num"=>$good_num,
  407. // "sale_price"=>$zxinfo['last_price'],
  408. // "total_price"=>round($zxinfo['last_price']*$good_num,2),
  409. // "updatetime"=>date("Y-m-d H:i:s"),
  410. // ];
  411. // $info = Db::name("sale_info")->where(["orderCode"=>$saleinfo['orderCode']])->save($saleinfos);
  412. // if($info==false){
  413. // Db::rollback();
  414. // return error_show(1002,"咨询订单创建失败");
  415. // }
  416. // if($sendtype!=2){
  417. // foreach ($addrlist as $value){
  418. // $temp=[];
  419. // $addrs=[];
  420. // if($value['addr_code']!==''&&is_array($value['addr_code'])){
  421. // $addrs['provice_code'] = $value['addr_code'][0];
  422. // $addrs['city_code'] = $value['addr_code'][1];
  423. // $addrs['area_code'] = $value['addr_code'][2];
  424. // $addr = json_encode($addrs);
  425. // }else{
  426. // $addr = isset($value['addr_code'])?$value['addr_code']:'';
  427. // }
  428. // isset($value["id"])&&$value["id"]!=""? $temp['id']=$value['id']:"";
  429. // $temp['contactor']=$value['contactor'];
  430. // $temp['mobile'] = $value['mobile'];
  431. // $temp['addr'] = $value['addr'];
  432. // $temp['addr_code']=$addr;
  433. // $temp['orderCode']=$saleinfo['orderCode'];
  434. // $temp['customer_code'] =$customer_code;
  435. // $temp['receipt_quantity']=$value['receipt_quantity'];
  436. // $temp['post_fee'] =0;
  437. // $temp['is_del'] =$value['is_del'];
  438. // $temp['updatetime'] =date("Y-m-d H:i:s");
  439. // isset($value["id"])&&$value["id"]!=""?"":$temp['addtime'] =date("Y-m-d H:i:s");
  440. // $temp['arrive_time']=$value['arrive_time'];
  441. // $vmp = Db::name('order_addr')->save($temp);
  442. // if(!$vmp){
  443. // Db::rollback();
  444. // return error_show(0,"咨询订单地址更新失败");
  445. // }
  446. // }
  447. // }else{
  448. // if($saleinfo['send_type']==1 && $sendtype==2){
  449. // $up=Db::name('order_addr')->where(["orderCode"=>$saleinfo['orderCode']])->save(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  450. // if(!$up){
  451. // Db::rollback();
  452. // return error_show(0,"咨询订单地址更新失败");
  453. // }
  454. // }
  455. // }
  456. // Db::commit();
  457. // return error_show(0,"咨询订单更新成功");
  458. // }
  459. // Db::rollback();
  460. // return error_show(1002,"咨询订单更新失败");
  461. // }catch(\Exception $e){
  462. // Db::rollback();
  463. // return error_show(1005,$e->getMessage());
  464. // }
  465. // }
  466. public function out(){
  467. $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  468. $outCode = isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode']) :"";
  469. if($outCode==""){
  470. return error_show(1002,"参数outCode不能为空");
  471. }
  472. $der = Db::name('order_out')->where(['outCode'=>$outCode])->find();
  473. if($der==""){
  474. return error_show(1002,"未找到出库单数据");
  475. }
  476. $order= Db::name('sale')->where(['orderCode'=>$der['orderCode']])->find();
  477. if(empty($order)){
  478. return error_show(1002,"未找到咨询订单信息");
  479. }
  480. $stock= Db::name("good_stock")->where(["spuCode"=>$order['good_code'],"wsm_code"=>$der['wsm_code']])
  481. ->find();
  482. if(empty($stock)){
  483. return error_show(1002,"未找到仓库库存信息");
  484. }
  485. if($der['send_num'] > $stock['wait_out_stock']){
  486. return error_show(1002,"仓库库存不足");
  487. }
  488. $post_name= isset($this->post['post_name']) && $this->post['post_name'] !=="" ? trim($this->post['post_name']) :"";
  489. if($post_name==""){
  490. return error_show(1002,"物流公司不能为空");
  491. }
  492. $post_code = isset($this->post['post_code']) && $this->post['post_code'] !=="" ? trim($this->post['post_code']) :"";
  493. if($post_code==""){
  494. return error_show(1002,"物流单号不能为空");
  495. }
  496. $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !=="" ? intval($this->post['post_fee']) :"";
  497. if($post_fee==""){
  498. return error_show(1002,"物流费不能为空");
  499. }
  500. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
  501. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
  502. Db::startTrans();
  503. try {
  504. $var = $der['status'];
  505. $der['post_name'] = $post_name;
  506. $der['post_code'] = $post_code;
  507. $der['post_fee'] = $post_fee;
  508. $der['sendtime'] = $sendtime;
  509. $der['status'] = 1;
  510. $der['updatetime'] = date("Y-m-d H:i:s");
  511. $datainfo = Db::name('order_out')->save($der);
  512. $st = ["order_code"=>$outCode,"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  513. ActionLog::logAdd($this->post['token'],$st,"resign_info",$der['status'] ,$st);
  514. if($datainfo) {
  515. $st = ["order_code"=>$der['outCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  516. ActionLog::logAdd($this->post['token'],$st,"CKD",1,$der);
  517. $ord=["order_type"=>"CKD","order_code"=>$der['outCode'],"order_id"=>$der['id'],
  518. "order_status"=>$der['status']];
  519. ProcessOrder::AddProcess($this->post['token'],$ord);
  520. // $send =Db::name("order_out")->where(["wsm_code"=>$der['wsm_code'],'orderCode'=>$der['orderCode']])->sum("send_num");
  521. // $order['send_num']+= $der['send_num'];
  522. // $order['wsend_num']-=$der['send_num'] ;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  523. // $order['send_status']=$order['send_num']==0 ? 1 :($order['wsend_num']==0?3:2);
  524. // $order['status']=$order['send_num']==0 ? 2 :($order['wsend_num']==0?4:3);
  525. // $order['updatetime'] = date("Y-m-d H:i:s");
  526. // $si = Db::name('sale')->save($order);
  527. // if($si==false){
  528. // Db::rollback();
  529. // return error_show(1003,"更新失败");
  530. // }
  531. $str = Db::name('good_stock')->where(['wsm_code' => $der['wsm_code'],'spuCode'=>$order['good_code']])
  532. ->find();
  533. if ($str == false) {
  534. Db::rollback();
  535. return error_show(1002, "商品数据未找到");
  536. }
  537. if ($der['send_num'] > $str['wait_out_stock']) {
  538. Db::rollback();
  539. return error_show(1002, "超出库存数量");
  540. }
  541. $str['wait_out_stock'] -= $der['send_num'];
  542. $str['intra_stock'] += $der['send_num'];
  543. $str['updatetime'] = date("Y-m-d H:i:s");
  544. $stre = Db::name('good_stock')->save($str);
  545. if ($stre == false) {
  546. Db::rollback();
  547. return error_show(1002, "状态更新失败");
  548. }
  549. //商品变动日志表,good_log_code字段存储销售订单编号
  550. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 1, 'stock' => $der['send_num'], "stock_name" => "intra_stock"];
  551. $good_data[] = ['good_log_code' => $outCode, "stock_id" => $str['id'], "type" => 2, 'stock' => $der['send_num'], "stock_name" => "wait_out_stock"];
  552. GoodLog::LogAdd($this->post['token'], $good_data, 'CKD');
  553. Db::commit();
  554. return error_show(0,"创建成功");
  555. }else{
  556. Db::rollback();
  557. return error_show(1003,"创建失败");
  558. }
  559. }catch (\Exception $e) {
  560. Db::rollback();
  561. return error_show(1005, $e->getMessage());
  562. }
  563. }
  564. public function outaddr(){
  565. $token= isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  566. $outCode=makeNo("DF");
  567. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
  568. if($orderCode==""){
  569. return error_show(1002,"参数orderCoder不能为空");
  570. }
  571. $der = Db::name('sale')->where(['orderCode'=>$orderCode])->find();
  572. if($der==""){
  573. return error_show(1002,"未找到出库订单单号");
  574. }
  575. if($der['order_type']!=2){
  576. return error_show(1002,"订单不是咨询单无法出库");
  577. }
  578. $wsm= Db::name('sale_info')->where(['orderCode'=>$der['orderCode']])->find();
  579. if(empty($wsm)){
  580. return error_show(1002,"未找到仓库信息");
  581. }
  582. $apply_id =GetUserInfo($token);
  583. if(empty($apply_id)||$apply_id['code']!=0){
  584. return error_show(1002,"申请人数据不存在");
  585. }
  586. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  587. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  588. if($der['send_type']==2){
  589. $contactor= isset($this->post['contactor']) && $this->post['contactor'] !=="" ? trim($this->post['contactor'])
  590. :"";
  591. if($contactor==""){
  592. return error_show(1002,"收货人不能为空");
  593. }
  594. $mobile = isset($this->post['mobile']) && $this->post['mobile'] !=="" ? trim($this->post['mobile'])
  595. :"";
  596. if($mobile==""){
  597. return error_show(1002,"收货人联系方式不能为空");
  598. }
  599. $addr = isset($this->post['addr']) && $this->post['addr'] !=="" ? trim($this->post['addr']) :"";
  600. if($addr==""){
  601. return error_show(1002,"参数addr不能为空");
  602. }
  603. $receipt_quantity= isset($this->post['receipt_quantity']) && $this->post['receipt_quantity'] !=="" ? intval
  604. ($this->post['receipt_quantity']) :"";
  605. if($receipt_quantity===""){
  606. return error_show(1002,"参数receipt_quantity不能为空");
  607. }
  608. $addrcode = isset($this->post['addr_code']) && $this->post['addr_code'] !=="" ? $this->post['addr_code'] :"";
  609. if($addrcode==""){
  610. return error_show(1002,"参数addr_code不能为空");
  611. }
  612. $addrs=[];
  613. if(is_array($addrcode)){
  614. $addrs['provice_code'] = $addrcode['addr_code'][0];
  615. $addrs['city_code'] = $addrcode['addr_code'][1];
  616. $addrs['area_code'] = $addrcode['addr_code'][2];
  617. $addrstr = json_encode($addrs);
  618. }else{
  619. $addrstr = $addrcode;
  620. }
  621. }else{
  622. $addrid = isset($this->post['addrid']) && $this->post['addrid'] !=="" ? intval($this->post['addrid']) :"";
  623. $dr = Db::name('order_addr')->where(['id'=>$addrid,"orderCode"=>$orderCode,'is_del'=>0])->find();
  624. if(empty($dr)){
  625. return error_show(1003,"收货人信息未找到");
  626. }
  627. $receipt_quantity = $dr['receipt_quantity'];
  628. }
  629. // if($send_num>$stock['usable_stock']){
  630. // return error_show(1002,"超出可发货数量");
  631. // }
  632. $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !=="" ? $this->post['sendtime']:date("Y-m-d H:i:s");
  633. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? $this->post['status'] :"1";
  634. Db::startTrans();
  635. try {
  636. if($der['send_type']==2){
  637. $addr=[
  638. "orderCode"=>$orderCode,
  639. "addr"=>$addr,
  640. "addr_code"=>$addrstr,
  641. "contactor"=>$contactor,
  642. "mobile"=>$mobile,
  643. "customer_code"=>$der['customer_code'],
  644. "post_fee"=>0,
  645. "is_del"=>0,
  646. "receipt_quantity"=>$receipt_quantity,
  647. "addtime"=>date("Y-m-d H:i:s"),
  648. "updatetime"=>date("Y-m-d H:i:s"),
  649. "arrive_time"=>date("Y-m-d H:i:s"),
  650. ];
  651. $addrid = Db::name('order_addr')->insert($addr,true);
  652. if($addrid<=0){
  653. $st = ["order_code"=>$orderCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  654. ActionLog::logAdd($this->post['token'],$st,"zxd",0,$st);
  655. Db::rollback();
  656. return error_show(1003,"创建失败");
  657. }
  658. }
  659. $data=[
  660. "wsm_code"=>$wsm['wsm_code'],
  661. "orderCode"=>$orderCode,
  662. "outCode"=>$outCode,
  663. "order_type"=>$der['order_type'],
  664. "apply_id"=>$rm,
  665. "apply_name"=>$ri,
  666. "addrid"=>$addrid,
  667. "post_name"=>'',
  668. "post_code"=>'',
  669. "post_fee"=>'',
  670. "sendtime"=>$sendtime,
  671. "send_num"=>$receipt_quantity,
  672. "check_num"=>0,
  673. "error_num"=>0,
  674. "status"=>0,
  675. "addtime"=>date("Y-m-d H:i:s"),
  676. "updatetime"=>date("Y-m-d H:i:s")
  677. ];
  678. $datainfo = Db::name('order_out')->insert($data,true);
  679. if($datainfo<=0){
  680. Db::rollback();
  681. return error_show(1003,"创建失败");
  682. }
  683. $sio = ["order_code"=>$outCode,"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  684. ActionLog::logAdd($this->post['token'],$sio,"CKD",0,$data);
  685. $order=["order_type"=>"CKD","order_code"=>$data['outCode'],"order_id"=>$datainfo,"order_status"=>$data['status']];
  686. ProcessOrder::AddProcess($this->post['token'],$order);
  687. $item = $der['status'];
  688. $der['send_num']+= $receipt_quantity;
  689. $der['wsend_num']-=$receipt_quantity;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
  690. $der['send_status']=$der['send_num']==0 ? 1 :($der['wsend_num']==0?3:2);
  691. $der['status']=$der['send_num']==0 ? 2 :($der['wsend_num']==0?4:3);
  692. $der['updatetime'] = date("Y-m-d H:i:s");
  693. $si = Db::name('sale')->save($der);
  694. if($si==false){
  695. Db::rollback();
  696. return error_show(1003,"创建失败");
  697. }else{
  698. //修改状态,添加待办
  699. ActionLog::logAdd($this->post['token'], [
  700. "order_code" => $der['orderCode'],//销售单code
  701. "status" => $item,//这里的status是之前的值
  702. "action_remark" => '',//备注
  703. "action_type" => "status"//新建create,编辑edit,更改状态status
  704. ], "XSQRD", $der['status'], $der);
  705. ProcessOrder::AddProcess($this->post['token'], [
  706. "order_type" => 'XSQRD',
  707. "order_code" => $der['orderCode'],//销售单code
  708. "order_id" => $der['id'],
  709. "order_status" => $der['status']
  710. ]);
  711. }
  712. $sio = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
  713. ActionLog::logAdd($this->post['token'],$sio,"zxd",$der['status'],$der);
  714. $order=["order_type"=>"CKD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$der['status']];
  715. ProcessOrder::AddProcess($this->post['token'],$order);
  716. Db::commit();
  717. return error_show(0,"创建成功");
  718. }catch (\Exception $e) {
  719. Db::rollback();
  720. return error_show(1005, $e->getMessage());
  721. }
  722. }
  723. }