Salezx.php 42 KB

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