Salezx.php 38 KB

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