After.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. class After extends \app\BaseController
  8. {
  9. public $post=[];
  10. public function __construct(App $app)
  11. {
  12. parent::__construct($app);
  13. $this->post =$this->request->post();
  14. }
  15. public function create(){
  16. $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  17. if($outCode==''){
  18. return error_show(1004,"参数outCode 不能为空");
  19. }
  20. $orderout= Db::name("order_out")->where(["outCode"=>$outCode])->find();
  21. if(empty($orderout)){
  22. return error_show(1005,"未找到订单数据");
  23. }
  24. $oder= Db::name("sale")->where(["orderCode"=>$orderout['orderCode'],"is_del"=>0])->find();
  25. if(empty($oder)){
  26. return error_show(1005,"未找到订单数据");
  27. }
  28. $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  29. if($outCode==''){
  30. return error_show(1004,"参数errorCode 不能为空");
  31. }
  32. $error =Db::name('result_info')->where(["result_code"=>$errorCode,"is_del"=>0])->find();
  33. if(empty($error)){
  34. return error_show(1005,"未找到退货原因数据");
  35. }
  36. $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  37. $is_receive =isset($this->post['is_receive']) &&$this->post['is_receive']!==''?intval($this->post['is_receive'])
  38. :"";
  39. if($is_receive===""){
  40. return error_show(1004,"参数 is_receive 不能为空");
  41. }
  42. if($is_receive==0){
  43. $num=$orderout['send_num'];
  44. }else{
  45. $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  46. if($num==""){
  47. return error_show(1004,"参数 num 不能为空或零");
  48. }
  49. }
  50. $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  51. $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  52. $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  53. if($token==''){
  54. return error_show(105,"参数token不能为空");
  55. }
  56. $user =GetUserInfo($token);
  57. if(empty($user)||$user['code']!=0){
  58. return error_show(102,"申请人数据不存在");
  59. }
  60. $rm= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  61. $ri= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  62. $returnCode=makeNo("RXS");
  63. Db::startTrans();
  64. try{
  65. $in = [
  66. "returnCode"=>$returnCode,
  67. "outCode"=>$outCode,
  68. "orderCode"=> $oder['orderCode'],
  69. "good_code"=>$oder['good_code'],
  70. "good_name"=>$oder['good_name'],
  71. "customer_code"=>$oder['customer_code'],
  72. "apply_id"=>$rm,
  73. "apply_name"=>$ri,
  74. 'total_num'=>$orderout['send_num'],
  75. "error_code"=>$errorCode,
  76. "error_num"=>$num,
  77. "error_img"=>$img,
  78. "error_msg"=>$error['result'],
  79. "error_remark"=>$remark,
  80. "is_receive"=>$is_receive,
  81. "remark"=>'',
  82. "except_code"=>$except_code,
  83. "order_type"=>$orderout['order_type'],
  84. "status"=>0,
  85. "is_del"=>0,
  86. "addtime"=>date("Y-m-d H:i:s"),
  87. "updatetime"=>date("Y-m-d H:i:s")
  88. ];
  89. $create = Db::name("order_return")->insert($in,true);
  90. $orde = ["order_code"=>$returnCode,"status"=>$in['status'],"action_remark"=>'',"action_type"=>"create"];
  91. ActionLog::logAdd($this->post['token'],$orde,$orderout['order_type']==1?'SHD':"ZXSHD",0,$orde);
  92. if($create>0){
  93. $process=["order_code"=>$returnCode,"order_id"=>$create,"order_status"=>0,"order_type"=>'SHD'];
  94. ProcessOrder::AddProcess($token,$process);
  95. Db::commit();
  96. return app_show(0,"售后申请单新建成功",["returnCode"=>$returnCode]);
  97. }
  98. Db::rollback();
  99. return error_show(1005,"售后申请单新建失败");
  100. }catch (\Exception $e){
  101. Db::rollback();
  102. return error_show(1005,$e->getMessage());
  103. }
  104. }
  105. public function list(){
  106. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  107. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  108. $where =[['a.is_del',"=",0]];
  109. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  110. if($bkcode!=""){
  111. $where[]=['a.returnCode',"like", "%{$bkcode}%"];
  112. }
  113. $out = isset($this->post['outCode']) && $this->post['outCode']!="" ? trim($this->post['outCode']):"";
  114. if($out!=""){
  115. $where[]=['a.outCode',"like", "%{$out}%"];
  116. }
  117. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  118. if($status!==""){
  119. $where[]=['a.status',"=", $status];
  120. }
  121. $order_type = isset($this->post['order_type']) && $this->post['order_type']!=="" ? intval($this->post['order_type']):"";
  122. if($order_type!==""){
  123. $where[]=['a.order_type',"=", $order_type];
  124. }
  125. $orderCode = isset($this->post['orderCode']) && $this->post['orderCode']!="" ? trim($this->post['orderCode'])
  126. :"";
  127. if($orderCode!=""){
  128. $where[]=['a.orderCode',"like", "%{$orderCode}%"];
  129. }
  130. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  131. :"";
  132. if($good_code!=""){
  133. $where[]=['a.good_code',"like", "%{$good_code}%"];
  134. }
  135. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name'])
  136. :"";
  137. if($good_name!=""){
  138. $where[]=['a.good_name',"like", "%{$good_name}%"];
  139. }
  140. $customer_code = isset($this->post['customer_code']) && $this->post['customer_code']!="" ? trim($this->post['customer_code'])
  141. :"";
  142. if($customer_code!=""){
  143. $where[]=['a.customer_code',"like", "%{$customer_code}%"];
  144. }
  145. $except_code = isset($this->post['except_code']) && $this->post['except_code']!="" ? trim($this->post['except_code']):"";
  146. if($except_code!=""){
  147. $where[]=['a.except_code',"=", $except_code];
  148. }
  149. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name'])
  150. :"";
  151. if($apply_name!=""){
  152. $where[]=['a.apply_name',"like", "%{$apply_name}%"];
  153. }
  154. $start =isset($this->post['start'])&&$this->post['start']!='' ? $this->post['start']:"";
  155. if($start!==""){
  156. $where[]=['a.addtime',">=", $start];
  157. }
  158. $end =isset($this->post['end'])&&$this->post['end']!='' ? $this->post['end']:"";
  159. if($end!==""){
  160. $where[]=['a.addtime',"<=", $end];
  161. }
  162. $count=Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where
  163. ($where)->count();
  164. $total = ceil($count/$size);
  165. $page = $total>=$page ? $page :$total;
  166. $list =Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")->where($where)
  167. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")->page($page,$size)
  168. ->order("addtime desc")->select();
  169. $data=[];
  170. foreach ($list as $value){
  171. $customer = Db::name("customer_info")->where(["companyNo"=>$value['customer_code']])->find();
  172. $value['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  173. $data[]=$value;
  174. }
  175. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  176. }
  177. /**
  178. * @return \think\response\Json|void
  179. * @throws \think\db\exception\DataNotFoundException
  180. * @throws \think\db\exception\DbException
  181. * @throws \think\db\exception\ModelNotFoundException
  182. */
  183. public function info(){
  184. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  185. if($bkcode==""){
  186. return error_show(1005,"参数returnCode 不能为空");
  187. }
  188. $info = Db::name("order_return")->alias("a")->leftJoin("order_returninfo b","a.returnCode=b.returnCode")
  189. ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark")
  190. ->where(['a.returnCode'=>$bkcode])->find();
  191. if(empty($info)){
  192. return error_show(1005,"未找到售后数据");
  193. }
  194. $orderinfo = Db::name("sale")->where(["orderCode"=>$info["orderCode"]])->find();
  195. $info['origin_price']=$orderinfo['origin_price'];
  196. $info['order_type']=$orderinfo['order_type'];
  197. $info['sale_price']=$orderinfo['sale_price'];
  198. $info['total_price']=sprintf("%1\$.2f",$orderinfo['sale_price']*$info['error_num']);
  199. if($orderinfo['order_type']==3|| $orderinfo['order_type']==4){
  200. $goon = Db::name("good_zixun")->where(["spuCode"=>$orderinfo['good_code'],"is_del"=>0])->find();
  201. }else {
  202. $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
  203. ->where(['a.skuCode' => $orderinfo['skuCode']])->find();
  204. }
  205. if (empty($goon)) {
  206. return error_show(1003, "未找到商品数据");
  207. }
  208. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  209. $info["addr_cn"]=GetAddr($info['addr_code']);
  210. $info["addr_code"]=json_decode($info['addr_code'],true);
  211. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  212. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  213. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  214. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  215. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code,a.wsm_code")->find();
  216. $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
  217. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  218. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  219. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  220. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  221. $info['can']=$int;
  222. return app_show(0,"获取成功",$info);
  223. }
  224. public function status(){
  225. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  226. if($bkcode==""){
  227. return error_show(1005,"参数returnCode 不能为空");
  228. }
  229. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  230. if(empty($info)){
  231. return error_show(1005,"未找到售后数据");
  232. }
  233. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  234. :"";
  235. if($status===""){
  236. return error_show(1005,"参数status 不能为空");
  237. }
  238. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  239. if($orde==false){
  240. return error_show(1005,"未找到出库单数据");
  241. }
  242. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  243. if($remark!=''){
  244. $info['remark'] =$remark;
  245. }
  246. if($status==3 && $info['is_receive']==1){
  247. $post =isset($this->post['is_post'])&&$this->post['is_post']!==""? intval($this->post['is_post']):"";
  248. if($post===""){
  249. return error_show(1005,"参数is_post不能为空");
  250. }
  251. $info['is_post']=$post;
  252. }
  253. // $status = $info['order_status']==1&&$info['order_type']==1 && $status==1?4:$status;
  254. Db::startTrans();
  255. try{
  256. $var=$info['status'];
  257. $info['status']=$status;
  258. $info['updatetime']=date("Y-m-d H:i:s");
  259. $up =Db::name("order_return")->save($info);
  260. if($up){
  261. // if($info['order_status']==1&&$info['order_type']==1 && $status==4){
  262. // $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  263. // $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  264. // ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  265. // $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,"order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  266. // ProcessOrder::AddProcess($this->post['token'],$process);
  267. // if($orderout){
  268. // Db::commit();
  269. // return app_show(0,"更新成功");
  270. // }else{
  271. // Db::rollback();
  272. // return error_show(1004,"更新失败");
  273. // }
  274. // }
  275. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  276. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", $info['status'],$this->post);
  277. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  278. ProcessOrder::AddProcess($this->post['token'],$process);
  279. Db::commit();
  280. return app_show(0,"更新成功");
  281. }else{
  282. Db::rollback();
  283. return error_show(1004,"更新失败");
  284. }
  285. }catch (\Exception $e){
  286. Db::rollback();
  287. return error_show(1004,$e->getMessage());
  288. }
  289. }
  290. public function setWsm(){
  291. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  292. if($bkcode==""){
  293. return error_show(1005,"参数returnCode 不能为空");
  294. }
  295. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  296. if(empty($info)){
  297. return error_show(1005,"未找到售后数据");
  298. }
  299. if($info['status']!=3){
  300. return error_show(1005,"采购主管未审核无法设置退回仓库");
  301. }
  302. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code'])
  303. :"";
  304. if($wsm_code==""){
  305. return error_show(1005,"参数wsm_code 不能为空");
  306. }
  307. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  308. if($addrcode==""){
  309. return error_show(1005,"参数 addr_code 不能为空");
  310. }
  311. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  312. if($addr==""){
  313. return error_show(1005,"参数 addr 不能为空");
  314. }
  315. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  316. if($mobile==""){
  317. return error_show(1005,"参数 mobile 不能为空");
  318. }
  319. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  320. if($contactor==""){
  321. return error_show(1005,"参数 contactor 不能为空");
  322. }
  323. $returninfo=[
  324. "returnCode"=>$bkcode,
  325. "return_wsm"=>$wsm_code,
  326. "contactor"=>$contactor,
  327. "mobile"=>$mobile ,
  328. "addr"=>$addr,
  329. "addr_code"=>$addrcode,
  330. "addtime"=>date("Y-m-d H:i:s")
  331. ];
  332. Db::startTrans();
  333. try {
  334. $in=Db::name("order_returninfo")->insert($returninfo);
  335. if($in){
  336. $info['status']=4;
  337. $info["updatetime"]=date("Y-m-d H:i:s");
  338. $up =Db::name("order_return")->save($info);
  339. if($up){
  340. Db::commit();
  341. return app_show(0,"退货仓库设置成功");
  342. }
  343. }
  344. Db::rollback();
  345. return error_show(1004,"设置失败");
  346. }catch (\Exception $e){
  347. Db::rollback();
  348. return error_show(1004,$e->getMessage());
  349. }
  350. }
  351. /**
  352. * @return \think\response\Json|void
  353. * @throws \think\db\exception\DataNotFoundException
  354. * @throws \think\db\exception\DbException
  355. * @throws \think\db\exception\ModelNotFoundException
  356. */
  357. public function postfeed(){
  358. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  359. if($bkcode==""){
  360. return error_show(1005,"参数returnCode 不能为空");
  361. }
  362. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  363. if(empty($info)){
  364. return error_show(1005,"未找到售后数据");
  365. }
  366. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  367. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  368. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  369. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  370. $this->post['addr_code']:"";
  371. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  372. if($wsm_code==""){
  373. return error_show(1005,"参数 wsm_code不能为空");
  374. }
  375. if($info['is_th']==0&&$info['order_type']==1) {
  376. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  377. if (empty($wsm)) {
  378. return error_show(1005, "未找到仓库数据");
  379. }
  380. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  381. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  382. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  383. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  384. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  385. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  386. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  387. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  388. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  389. }
  390. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  391. if($info['is_th']==1 && $info['order_type']==1){
  392. if($contactor==''){
  393. return error_show(1005,"参数 contactor 不能为空");
  394. }
  395. if($mobile==''){
  396. return error_show(1005,"参数 mobile 不能为空");
  397. }
  398. if($addr==''){
  399. return error_show(1005,"参数 addr 不能为空");
  400. }
  401. if($addr_code==''){
  402. return error_show(1005,"参数 addr_code 不能为空");
  403. }
  404. if($addr_code!==''&&is_array($addr_code)){
  405. $addrs=[];
  406. $addrs['provice_code'] = $addr_code[0];
  407. $addrs['city_code'] = $addr_code[1];
  408. $addrs['area_code'] = $addr_code[2];
  409. $addr_code = json_encode($addrs);
  410. }
  411. }
  412. Db::startTrans();
  413. try{
  414. $var=$info['status'];
  415. $info['status']=$info['order_type']==1?3:4;
  416. $info['remark']=$remark;
  417. $info['updatetime']=date("Y-m-d H:i:s");
  418. $up =Db::name("order_return")->save($info);
  419. if($up){
  420. // var_dump($contactor);
  421. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  422. if(empty($returninfo)){
  423. $returninfo=[
  424. "returnCode"=>$bkcode,
  425. "return_wsm"=>$wsm_code,
  426. "contactor"=>$contactor,
  427. "mobile"=>$mobile ,
  428. "addr"=>$addr,
  429. "addr_code"=>$addr_code,
  430. "addtime"=>date("Y-m-d H:i:s")
  431. ];
  432. }else{
  433. $returninfo['return_wsm'] = $wsm_code;
  434. //if($info['is_th']==1 && $info['order_type']==1) {
  435. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  436. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  437. $addr!==""? $returninfo['addr'] = $addr:"";
  438. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  439. // }
  440. }
  441. // var_dump($contactor);
  442. // var_dump($returninfo);
  443. $in=Db::name("order_returninfo")->save($returninfo);
  444. if($in){
  445. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  446. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  447. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  448. ProcessOrder::AddProcess($this->post['token'],$process);
  449. Db::commit();
  450. return app_show(0,"更新成功");
  451. }
  452. }
  453. Db::rollback();
  454. return error_show(1004,"更新失败");
  455. }catch (\Exception $e){
  456. Db::rollback();
  457. return error_show(1004,$e->getMessage());
  458. }
  459. }
  460. /**
  461. * @return \think\response\Json|void
  462. * @throws \think\db\exception\DataNotFoundException
  463. * @throws \think\db\exception\DbException
  464. * @throws \think\db\exception\ModelNotFoundException
  465. */
  466. public function addpost(){
  467. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  468. if($bkcode==""){
  469. return error_show(1005,"参数returnCode 不能为空");
  470. }
  471. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  472. if(empty($info)){
  473. return error_show(1005,"未找到售后数据");
  474. }
  475. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  476. if(empty($return_info)){
  477. $return_info=[
  478. "returnCode"=>$bkcode,
  479. "return_wsm"=>'',
  480. "contactor"=>'',
  481. "mobile"=>'',
  482. "addr"=>'',
  483. "addr_code"=>'',
  484. "addtime"=>date("Y-m-d H:i:s"),
  485. "post_company"=>'',
  486. "post_code"=>'',
  487. "post_fee"=>'',
  488. ];
  489. }
  490. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  491. if($post_own==''){
  492. return error_show(1005,"参数own不能为空");
  493. }
  494. $info['post_own'] = $post_own;
  495. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  496. if($post_company==''){
  497. return error_show(1005,"参数company不能为空");
  498. }
  499. $return_info['post_company'] = $post_company;
  500. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  501. if($post_code==''){
  502. return error_show(1005,"参数post_code不能为空");
  503. }
  504. $return_info['post_code'] = $post_code;
  505. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  506. if($fee===''){
  507. return error_show(1005,"参数post_fee不能为空");
  508. }
  509. $return_info['post_fee'] = $fee;
  510. Db::startTrans();
  511. try{
  512. $str=$info['status'];
  513. $info['status']=$info['order_type']==1?4:5;
  514. $info['updatetime']=date("Y-m-d H:i:s");
  515. $up =Db::name("order_return")->save($info);
  516. if($up){
  517. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  518. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  519. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  520. ProcessOrder::AddProcess($this->post['token'],$process);
  521. $in=Db::name("order_returninfo")->save($return_info);
  522. if($in){
  523. $data=[
  524. 'thNo'=>makeNo("TH"),
  525. "orderCode"=>$info['orderCode'],
  526. "order_type"=>$info['order_type'],
  527. "outCode"=>$info['outCode'],
  528. "returnCode"=>$info['returnCode'],
  529. "good_code"=>$info['good_code'],
  530. "good_name"=>$info['good_name'],
  531. "return_wsm"=>$return_info['return_wsm'],
  532. "return_num"=>$info['error_num'],
  533. "contactor"=>$return_info['contactor'],
  534. "mobile"=>$return_info['mobile'],
  535. "addr"=>$return_info['addr'],
  536. "addr_code"=>$return_info['addr_code'],
  537. "return_code"=>$info['error_code'],
  538. "return_msg"=>$info['error_msg'],
  539. "post_fee"=>$return_info['post_fee'],
  540. "post_code"=>$return_info['post_code'],
  541. "post_company"=>$return_info['post_company'],
  542. "customer_code"=>$info['customer_code'],
  543. "addtime"=>date("Y-m-d H:i:s"),
  544. "updatetime"=>date("Y-m-d H:i:s")
  545. ];
  546. $back =Db::name("order_back")->insert($data,true);
  547. if($back>0){
  548. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  549. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", 0,$data);
  550. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  551. ProcessOrder::AddProcess($this->post['token'],$process);
  552. Db::commit();
  553. return app_show(0,"更新成功");
  554. }
  555. }
  556. }
  557. Db::rollback();
  558. return error_show(1004,"更新失败");
  559. }catch (\Exception $e){
  560. Db::rollback();
  561. return error_show(1004,$e->getMessage());
  562. }
  563. }
  564. /**
  565. * @return \think\response\Json|void
  566. * @throws \think\db\exception\DataNotFoundException
  567. * @throws \think\db\exception\DbException
  568. * @throws \think\db\exception\ModelNotFoundException
  569. */
  570. public function GysFeed(){
  571. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  572. if($bkcode==""){
  573. return error_show(1005,"参数returnCode 不能为空");
  574. }
  575. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  576. if(empty($info)){
  577. return error_show(1005,"未找到售后数据");
  578. }
  579. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  580. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  581. :"";
  582. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  583. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  584. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  585. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  586. if($isth==1){
  587. if($contactor==''){
  588. return error_show(1005,"参数 contactor 不能为空");
  589. }
  590. if($mobile==''){
  591. return error_show(1005,"参数 mobile 不能为空");
  592. }
  593. if($addr==''){
  594. return error_show(1005,"参数 addr 不能为空");
  595. }
  596. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  597. if($addr_code==''){
  598. return error_show(1005,"参数 addr_code 不能为空");
  599. }
  600. if(is_array($addr_code)){
  601. $addrs=[];
  602. $addrs['provice_code'] = $addr_code[0];
  603. $addrs['city_code'] = $addr_code[1];
  604. $addrs['area_code'] = $addr_code[2];
  605. $addr_code = json_encode($addrs);
  606. }
  607. }
  608. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  609. if(empty($orde)){
  610. return error_show(1005,"未找到出库单数据");
  611. }
  612. Db::startTrans();
  613. try{
  614. $stat=$info['status'];
  615. $info['status']=$info['order_status']==1?5:3;
  616. $info['is_th']=$isth;
  617. $info['updatetime']=date("Y-m-d H:i:s");
  618. $up =Db::name("order_return")->save($info);
  619. if($up){
  620. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  621. if(empty($returninfo)){
  622. $returninfo=[
  623. "returnCode"=>$bkcode,
  624. "return_wsm"=>'',
  625. "contactor"=>$contactor,
  626. "mobile"=>$mobile ,
  627. "addr"=>$addr,
  628. "addr_code"=>$addr_code,
  629. "gys_remark"=>$remark,
  630. "addtime"=>date("Y-m-d H:i:s")
  631. ];
  632. }else{
  633. $returninfo['return_wsm'] = '';
  634. $returninfo['contactor'] = $contactor;
  635. $returninfo['mobile'] = $mobile;
  636. $returninfo['addr'] = $addr;
  637. $returninfo['gys_remark'] = $remark;
  638. $returninfo['addr_code'] = $addr_code;
  639. }
  640. $in=Db::name("order_returninfo")->save($returninfo);
  641. if($in){
  642. if( $info['order_status']==1&&$info['order_type']==2){
  643. $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  644. $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  645. ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,
  646. ['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  647. $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,
  648. "order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  649. ProcessOrder::AddProcess($this->post['token'],$process);
  650. if($orderout){
  651. Db::commit();
  652. return app_show(0,"更新成功");
  653. }else{
  654. Db::rollback();
  655. return error_show(1004,"更新失败");
  656. }
  657. }
  658. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  659. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'CKTHD':"ZXCKTHD",3,$order);
  660. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  661. ProcessOrder::AddProcess($this->post['token'],$process);
  662. Db::commit();
  663. return app_show(0,"更新成功");
  664. }
  665. }
  666. Db::rollback();
  667. return error_show(1004,"更新失败");
  668. }catch (\Exception $e){
  669. Db::rollback();
  670. return error_show(1004,$e->getMessage());
  671. }
  672. }
  673. public function GetWsm(){
  674. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  675. if($bkcode==""){
  676. return error_show(1005,"参数returnCode 不能为空");
  677. }
  678. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  679. if(empty($info)){
  680. return error_show(1005,"未找到售后数据");
  681. }
  682. $list=[];
  683. if($info['is_th']==1){
  684. if($info["order_type"]==1){
  685. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  686. if(empty($out)){
  687. return error_show(1005,"未找到出库单数据");
  688. }
  689. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  690. ->where(["a.status"=>1,"wsm_type"=>1,"a.is_del"=>0,"a.supplierNo"=>$out['wsm_code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  691. if(empty($ware)){
  692. return error_show(1005,"未找到仓库数据");
  693. }
  694. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  695. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  696. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  697. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  698. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  699. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  700. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  701. $list[]=$temp;
  702. }else {
  703. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  704. if (empty($returninfo)) {
  705. return error_show(1005, "未找到供应商仓库数据");
  706. }
  707. $data = [];
  708. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  709. $data['wsm_name'] = '供应商仓';
  710. $data['supplier_name'] = '供应商';
  711. $data['contactor'] = $returninfo['contactor'];
  712. $data['mobile'] = $returninfo['mobile'];
  713. $data['addr'] = $returninfo['addr'];
  714. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  715. $data['addr_code'] = $returninfo['addr_code'];
  716. $list[] = $data;
  717. }
  718. }
  719. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  720. if(empty($supplier)){
  721. return error_show(1005,"未找到供应商仓库数据");
  722. }
  723. foreach ($supplier as $value){
  724. $temp=[];
  725. $ware = Db::name("warehouse_info")->alias("a")->leftJoin("warehouse_addr b","a.wsm_code=b.wsm_code and b.status=1 and b.is_del=0")
  726. ->where(["a.wsm_type"=>1,"a.status"=>1,"a.is_del"=>0,"a.supplierNo"=>$value['code']])->field("a.wsm_code,a.name,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")->find();
  727. if(empty($ware)){
  728. continue;
  729. }
  730. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  731. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  732. $temp['supplier_name']=$value['name'];
  733. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  734. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  735. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  736. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  737. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  738. $list[]=$temp;
  739. }
  740. return app_show(0,"获取成功",$list);
  741. }
  742. public function setdelivery(){
  743. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  744. if($bkcode==""){
  745. return error_show(1005,"参数returnCode 不能为空");
  746. }
  747. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  748. if(empty($info)){
  749. return error_show(1005,"未找到售后数据");
  750. }
  751. if(($info['is_receive']==0&&$info['status']!=3)||($info['is_receive']==1&&$info['status']!=4) ){
  752. return error_show(1005,"售后单流程状态有误");
  753. }
  754. $out=Db::name("order_out")->where(["outCode"=>$info["outCode"]])->find();
  755. $is_th = isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
  756. if($is_th===""){
  757. return error_show(1005,"参数is_th不能为空");
  758. }
  759. $company=isset($this->post['company'])&&$this->post['company']!=""?trim($this->post['company']):"";
  760. $post_code=isset($this->post['post_code'])&&$this->post['post_code']!=""?trim($this->post['post_code']):"";
  761. $post_fee=isset($this->post['post_fee'])&&$this->post['post_fee']!==""?floatval($this->post['post_fee']):"";
  762. if($is_th==1){
  763. if($company==""){
  764. return error_show(1005,"参数company不能为空");
  765. }
  766. if($post_code==""){
  767. return error_show(1005,"参数post_code不能为空");
  768. }
  769. if($post_fee==""){
  770. return error_show(1005,"参数post_fee不能为空");
  771. }
  772. }
  773. try {
  774. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  775. if($returninfo==false){
  776. $returninfo=[
  777. "returnCode"=>$bkcode,
  778. "return_wsm"=>"",
  779. "contactor"=>"",
  780. "mobile"=>"",
  781. "addr"=>"",
  782. "addr_code"=>"",
  783. "post_code"=>$post_code,
  784. "post_company"=>$company,
  785. "post_fee"=>$post_fee,
  786. "gys_remark"=>"",
  787. "addtime"=>date("Y-m-d H:i:s")
  788. ];
  789. }else{
  790. $returninfo['post_fee']=$post_fee;
  791. $returninfo['post_company']=$company;
  792. $returninfo['post_code']=$post_code;
  793. }
  794. $up =Db::name("order_returninfo")->save($returninfo);
  795. if($up){
  796. $info['status']=5;
  797. $info['updatetime']=date("y-m-d H:i:s");
  798. $ro =Db::name("order_return")->save($info);
  799. if($ro){
  800. $thNo =makeNo("TH");
  801. $thdata=[
  802. "thNo"=>$thNo,
  803. "orderCode"=>$out["orderCode"],
  804. "outCode"=>$out["outCode"],
  805. "order_type"=>$info["order_type"],
  806. "returnCode"=>$info["returnCode"],
  807. "good_code"=>$info["good_code"],
  808. "good_name"=>$info["good_name"],
  809. "return_wsm"=>$returninfo["return_wsm"],
  810. "defective_wsm"=>'',
  811. "return_msg"=>$out["error_msg"],
  812. "return_num"=>$info["total_num"],
  813. "normal_num"=>0,
  814. "received_num"=>0,
  815. "defective_num"=>0,
  816. "loss_num"=>0,
  817. "contactor"=>$returninfo["contactor"],
  818. "mobile"=>$returninfo["mobile"],
  819. "addr"=>$returninfo["addr"],
  820. "addr_code"=>$returninfo["addr_code"],
  821. "return_code"=>$info["error_code"],
  822. "post_fee"=>$returninfo["post_fee"],
  823. "post_code"=>$returninfo["post_code"],
  824. "post_company"=>$returninfo["post_company"],
  825. "customer_code"=>$returninfo["customer_code"],
  826. "status"=>1,
  827. "addtime"=>date("Y-m-d H:i:s"),
  828. "updatetime"=>date("Y-m-d H:i:s")
  829. ];
  830. $sav= Db::name("order_back")->insert($thdata);
  831. if($sav){
  832. Db::commit();
  833. return app_show(0,"退货单新建成功",["thNo"=>$thNo]);
  834. }
  835. }
  836. }
  837. Db::rollback();
  838. return error_show(1004,'退货失败');
  839. }catch (\Exception $e){
  840. Db::rollback();
  841. return error_show(1004,$e->getMessage());
  842. }
  843. }
  844. }