Salezx.php 36 KB

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