After.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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"=>$orderout['order_type']==1?'SHD':"ZXSHD"];
  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['sale_price']=$orderinfo['sale_price'];
  197. $info['total_price']=sprintf("%1\$.2f",$orderinfo['sale_price']*$info['error_num']);
  198. $goon = Db::name('good')->alias('b')->join("good_type a", "a.good_code=b.good_code", "left")
  199. ->where(['a.type_code' => $info['good_code']])->find();
  200. if (empty($goon)) {
  201. return error_show(1003, "未找到商品数据");
  202. }
  203. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  204. $info["addr_cn"]=GetAddr($info['addr_code']);
  205. $info["addr_code"]=json_decode($info['addr_code'],true);
  206. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  207. $info['out_num'] = isset($out['send_num'])?$out['send_num']:'';
  208. $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  209. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")
  210. ->where(["a.wsm_code"=>$info['return_wsm']])->field("a.name as wsm_name,b.name,b.code,a.wsm_code")->find();
  211. $info['wsm_code'] =isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code']:"";
  212. $info['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  213. $info['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  214. $info['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  215. $info['customer_name'] = isset($customer['companyName']) ?trim($customer['companyName']):'';
  216. $info['can']=$int;
  217. return app_show(0,"获取成功",$info);
  218. }
  219. public function status(){
  220. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  221. if($bkcode==""){
  222. return error_show(1005,"参数returnCode 不能为空");
  223. }
  224. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  225. if(empty($info)){
  226. return error_show(1005,"未找到售后数据");
  227. }
  228. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status'])
  229. :"";
  230. if($status===""){
  231. return error_show(1005,"参数status 不能为空");
  232. }
  233. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  234. if(empty($orde)){
  235. return error_show(1005,"未找到出库单数据");
  236. }
  237. $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
  238. if($remark!=''){
  239. $info['remark'] =$remark;
  240. }
  241. if($status==3 && $info['is_receive']==1){
  242. $post =isset($this->post['is_post'])&&$this->post['is_post']!==""? intval($this->post['is_post']):"";
  243. if($post===""){
  244. return error_show(1005,"参数is_post不能为空");
  245. }
  246. $info['is_post']=$post;
  247. }
  248. // $status = $info['order_status']==1&&$info['order_type']==1 && $status==1?4:$status;
  249. Db::startTrans();
  250. try{
  251. $var=$info['status'];
  252. $info['status']=$status;
  253. $info['updatetime']=date("Y-m-d H:i:s");
  254. $up =Db::name("order_return")->save($info);
  255. if($up){
  256. // if($info['order_status']==1&&$info['order_type']==1 && $status==4){
  257. // $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  258. // $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  259. // ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  260. // $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,"order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  261. // ProcessOrder::AddProcess($this->post['token'],$process);
  262. // if($orderout){
  263. // Db::commit();
  264. // return app_show(0,"更新成功");
  265. // }else{
  266. // Db::rollback();
  267. // return error_show(1004,"更新失败");
  268. // }
  269. // }
  270. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  271. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", $info['status'],$this->post);
  272. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$status,"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  273. ProcessOrder::AddProcess($this->post['token'],$process);
  274. Db::commit();
  275. return app_show(0,"更新成功");
  276. }else{
  277. Db::rollback();
  278. return error_show(1004,"更新失败");
  279. }
  280. }catch (\Exception $e){
  281. Db::rollback();
  282. return error_show(1004,$e->getMessage());
  283. }
  284. }
  285. public function setWsm(){
  286. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  287. if($bkcode==""){
  288. return error_show(1005,"参数returnCode 不能为空");
  289. }
  290. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  291. if(empty($info)){
  292. return error_show(1005,"未找到售后数据");
  293. }
  294. if($info['status']!=3){
  295. return error_show(1005,"采购主管未审核无法设置退回仓库");
  296. }
  297. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code'])
  298. :"";
  299. if($wsm_code==""){
  300. return error_show(1005,"参数wsm_code 不能为空");
  301. }
  302. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  303. if($addrcode==""){
  304. return error_show(1005,"参数 addr_code 不能为空");
  305. }
  306. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  307. if($addr==""){
  308. return error_show(1005,"参数 addr 不能为空");
  309. }
  310. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  311. if($mobile==""){
  312. return error_show(1005,"参数 mobile 不能为空");
  313. }
  314. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  315. if($contactor==""){
  316. return error_show(1005,"参数 contactor 不能为空");
  317. }
  318. $returninfo=[
  319. "returnCode"=>$bkcode,
  320. "return_wsm"=>$wsm_code,
  321. "contactor"=>$contactor,
  322. "mobile"=>$mobile ,
  323. "addr"=>$addr,
  324. "addr_code"=>$addrcode,
  325. "addtime"=>date("Y-m-d H:i:s")
  326. ];
  327. Db::startTrans();
  328. try {
  329. $in=Db::name("order_returninfo")->insert($returninfo);
  330. if($in){
  331. $info['status']=4;
  332. $info["updatetime"]=date("Y-m-d H:i:s");
  333. $up =Db::name("order_return")->save($info);
  334. if($up){
  335. Db::commit();
  336. return app_show(0,"退货仓库设置成功");
  337. }
  338. }
  339. Db::rollback();
  340. return error_show(1004,"设置失败");
  341. }catch (\Exception $e){
  342. Db::rollback();
  343. return error_show(1004,$e->getMessage());
  344. }
  345. }
  346. /**
  347. * @return \think\response\Json|void
  348. * @throws \think\db\exception\DataNotFoundException
  349. * @throws \think\db\exception\DbException
  350. * @throws \think\db\exception\ModelNotFoundException
  351. */
  352. public function postfeed(){
  353. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  354. if($bkcode==""){
  355. return error_show(1005,"参数returnCode 不能为空");
  356. }
  357. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  358. if(empty($info)){
  359. return error_show(1005,"未找到售后数据");
  360. }
  361. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  362. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  363. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  364. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  365. $this->post['addr_code']:"";
  366. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  367. if($wsm_code==""){
  368. return error_show(1005,"参数 wsm_code不能为空");
  369. }
  370. if($info['is_th']==0&&$info['order_type']==1) {
  371. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  372. if (empty($wsm)) {
  373. return error_show(1005, "未找到仓库数据");
  374. }
  375. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  376. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  377. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  378. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  379. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  380. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  381. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  382. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  383. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  384. }
  385. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  386. if($info['is_th']==1 && $info['order_type']==1){
  387. if($contactor==''){
  388. return error_show(1005,"参数 contactor 不能为空");
  389. }
  390. if($mobile==''){
  391. return error_show(1005,"参数 mobile 不能为空");
  392. }
  393. if($addr==''){
  394. return error_show(1005,"参数 addr 不能为空");
  395. }
  396. if($addr_code==''){
  397. return error_show(1005,"参数 addr_code 不能为空");
  398. }
  399. if($addr_code!==''&&is_array($addr_code)){
  400. $addrs=[];
  401. $addrs['provice_code'] = $addr_code[0];
  402. $addrs['city_code'] = $addr_code[1];
  403. $addrs['area_code'] = $addr_code[2];
  404. $addr_code = json_encode($addrs);
  405. }
  406. }
  407. Db::startTrans();
  408. try{
  409. $var=$info['status'];
  410. $info['status']=$info['order_type']==1?3:4;
  411. $info['remark']=$remark;
  412. $info['updatetime']=date("Y-m-d H:i:s");
  413. $up =Db::name("order_return")->save($info);
  414. if($up){
  415. // var_dump($contactor);
  416. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  417. if(empty($returninfo)){
  418. $returninfo=[
  419. "returnCode"=>$bkcode,
  420. "return_wsm"=>$wsm_code,
  421. "contactor"=>$contactor,
  422. "mobile"=>$mobile ,
  423. "addr"=>$addr,
  424. "addr_code"=>$addr_code,
  425. "addtime"=>date("Y-m-d H:i:s")
  426. ];
  427. }else{
  428. $returninfo['return_wsm'] = $wsm_code;
  429. //if($info['is_th']==1 && $info['order_type']==1) {
  430. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  431. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  432. $addr!==""? $returninfo['addr'] = $addr:"";
  433. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  434. // }
  435. }
  436. // var_dump($contactor);
  437. // var_dump($returninfo);
  438. $in=Db::name("order_returninfo")->save($returninfo);
  439. if($in){
  440. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  441. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  442. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  443. ProcessOrder::AddProcess($this->post['token'],$process);
  444. Db::commit();
  445. return app_show(0,"更新成功");
  446. }
  447. }
  448. Db::rollback();
  449. return error_show(1004,"更新失败");
  450. }catch (\Exception $e){
  451. Db::rollback();
  452. return error_show(1004,$e->getMessage());
  453. }
  454. }
  455. /**
  456. * @return \think\response\Json|void
  457. * @throws \think\db\exception\DataNotFoundException
  458. * @throws \think\db\exception\DbException
  459. * @throws \think\db\exception\ModelNotFoundException
  460. */
  461. public function addpost(){
  462. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  463. if($bkcode==""){
  464. return error_show(1005,"参数returnCode 不能为空");
  465. }
  466. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  467. if(empty($info)){
  468. return error_show(1005,"未找到售后数据");
  469. }
  470. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  471. if(empty($return_info)){
  472. $return_info=[
  473. "returnCode"=>$bkcode,
  474. "return_wsm"=>'',
  475. "contactor"=>'',
  476. "mobile"=>'',
  477. "addr"=>'',
  478. "addr_code"=>'',
  479. "addtime"=>date("Y-m-d H:i:s"),
  480. "post_company"=>'',
  481. "post_code"=>'',
  482. "post_fee"=>'',
  483. ];
  484. }
  485. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  486. if($post_own==''){
  487. return error_show(1005,"参数own不能为空");
  488. }
  489. $info['post_own'] = $post_own;
  490. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  491. if($post_company==''){
  492. return error_show(1005,"参数company不能为空");
  493. }
  494. $return_info['post_company'] = $post_company;
  495. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  496. if($post_code==''){
  497. return error_show(1005,"参数post_code不能为空");
  498. }
  499. $return_info['post_code'] = $post_code;
  500. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  501. if($fee===''){
  502. return error_show(1005,"参数post_fee不能为空");
  503. }
  504. $return_info['post_fee'] = $fee;
  505. Db::startTrans();
  506. try{
  507. $str=$info['status'];
  508. $info['status']=$info['order_type']==1?4:5;
  509. $info['updatetime']=date("Y-m-d H:i:s");
  510. $up =Db::name("order_return")->save($info);
  511. if($up){
  512. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  513. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD",$info['status'],$order);
  514. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'SHD':"ZXSHD"];
  515. ProcessOrder::AddProcess($this->post['token'],$process);
  516. $in=Db::name("order_returninfo")->save($return_info);
  517. if($in){
  518. $data=[
  519. 'thNo'=>makeNo("TH"),
  520. "orderCode"=>$info['orderCode'],
  521. "order_type"=>$info['order_type'],
  522. "outCode"=>$info['outCode'],
  523. "returnCode"=>$info['returnCode'],
  524. "good_code"=>$info['good_code'],
  525. "good_name"=>$info['good_name'],
  526. "return_wsm"=>$return_info['return_wsm'],
  527. "return_num"=>$info['error_num'],
  528. "contactor"=>$return_info['contactor'],
  529. "mobile"=>$return_info['mobile'],
  530. "addr"=>$return_info['addr'],
  531. "addr_code"=>$return_info['addr_code'],
  532. "return_code"=>$info['error_code'],
  533. "return_msg"=>$info['error_msg'],
  534. "post_fee"=>$return_info['post_fee'],
  535. "post_code"=>$return_info['post_code'],
  536. "post_company"=>$return_info['post_company'],
  537. "customer_code"=>$info['customer_code'],
  538. "addtime"=>date("Y-m-d H:i:s"),
  539. "updatetime"=>date("Y-m-d H:i:s")
  540. ];
  541. $back =Db::name("order_back")->insert($data,true);
  542. if($back>0){
  543. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  544. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'SHD':"ZXSHD", 0,$data);
  545. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  546. ProcessOrder::AddProcess($this->post['token'],$process);
  547. Db::commit();
  548. return app_show(0,"更新成功");
  549. }
  550. }
  551. }
  552. Db::rollback();
  553. return error_show(1004,"更新失败");
  554. }catch (\Exception $e){
  555. Db::rollback();
  556. return error_show(1004,$e->getMessage());
  557. }
  558. }
  559. /**
  560. * @return \think\response\Json|void
  561. * @throws \think\db\exception\DataNotFoundException
  562. * @throws \think\db\exception\DbException
  563. * @throws \think\db\exception\ModelNotFoundException
  564. */
  565. public function GysFeed(){
  566. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  567. if($bkcode==""){
  568. return error_show(1005,"参数returnCode 不能为空");
  569. }
  570. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  571. if(empty($info)){
  572. return error_show(1005,"未找到售后数据");
  573. }
  574. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  575. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  576. :"";
  577. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  578. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  579. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  580. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  581. if($isth==1){
  582. if($contactor==''){
  583. return error_show(1005,"参数 contactor 不能为空");
  584. }
  585. if($mobile==''){
  586. return error_show(1005,"参数 mobile 不能为空");
  587. }
  588. if($addr==''){
  589. return error_show(1005,"参数 addr 不能为空");
  590. }
  591. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  592. if($addr_code==''){
  593. return error_show(1005,"参数 addr_code 不能为空");
  594. }
  595. if(is_array($addr_code)){
  596. $addrs=[];
  597. $addrs['provice_code'] = $addr_code[0];
  598. $addrs['city_code'] = $addr_code[1];
  599. $addrs['area_code'] = $addr_code[2];
  600. $addr_code = json_encode($addrs);
  601. }
  602. }
  603. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  604. if(empty($orde)){
  605. return error_show(1005,"未找到出库单数据");
  606. }
  607. Db::startTrans();
  608. try{
  609. $stat=$info['status'];
  610. $info['status']=$info['order_status']==1?5:3;
  611. $info['is_th']=$isth;
  612. $info['updatetime']=date("Y-m-d H:i:s");
  613. $up =Db::name("order_return")->save($info);
  614. if($up){
  615. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  616. if(empty($returninfo)){
  617. $returninfo=[
  618. "returnCode"=>$bkcode,
  619. "return_wsm"=>'',
  620. "contactor"=>$contactor,
  621. "mobile"=>$mobile ,
  622. "addr"=>$addr,
  623. "addr_code"=>$addr_code,
  624. "gys_remark"=>$remark,
  625. "addtime"=>date("Y-m-d H:i:s")
  626. ];
  627. }else{
  628. $returninfo['return_wsm'] = '';
  629. $returninfo['contactor'] = $contactor;
  630. $returninfo['mobile'] = $mobile;
  631. $returninfo['addr'] = $addr;
  632. $returninfo['gys_remark'] = $remark;
  633. $returninfo['addr_code'] = $addr_code;
  634. }
  635. $in=Db::name("order_returninfo")->save($returninfo);
  636. if($in){
  637. if( $info['order_status']==1&&$info['order_type']==2){
  638. $orderout= Db::name("order_out")->where($orde)->save(['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  639. $order = ["order_code"=>$orde['outCode'],"status"=>$orde['status'],"action_remark"=>'',"action_type"=>"edit"];
  640. ActionLog::logAdd($this->post['token'],$order,$orde['order_type']==1?'CKD':"ZXCKD", 3,
  641. ['status'=>3,"updatetime"=>date("Y-m-d H:i:s")]);
  642. $process=["order_code"=>$orde['outCode'],"order_id"=>$orde['id'],"order_status"=>3,
  643. "order_type"=>$orde['order_type']==1?'CKD':"ZXCKD"];
  644. ProcessOrder::AddProcess($this->post['token'],$process);
  645. if($orderout){
  646. Db::commit();
  647. return app_show(0,"更新成功");
  648. }else{
  649. Db::rollback();
  650. return error_show(1004,"更新失败");
  651. }
  652. }
  653. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  654. ActionLog::logAdd($this->post['token'],$order,$info['order_type']==1?'CKTHD':"ZXCKTHD",3,$order);
  655. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>$info['order_type']==1?'CKTHD':"ZXCKTHD"];
  656. ProcessOrder::AddProcess($this->post['token'],$process);
  657. Db::commit();
  658. return app_show(0,"更新成功");
  659. }
  660. }
  661. Db::rollback();
  662. return error_show(1004,"更新失败");
  663. }catch (\Exception $e){
  664. Db::rollback();
  665. return error_show(1004,$e->getMessage());
  666. }
  667. }
  668. public function GetWsm(){
  669. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  670. if($bkcode==""){
  671. return error_show(1005,"参数returnCode 不能为空");
  672. }
  673. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  674. if(empty($info)){
  675. return error_show(1005,"未找到售后数据");
  676. }
  677. $list=[];
  678. if($info['is_th']==1){
  679. if($info["order_type"]==1){
  680. $out =Db::name("order_out")->where(["outCode"=>$info['outCode']])->find();
  681. if(empty($out)){
  682. return error_show(1005,"未找到出库单数据");
  683. }
  684. $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")
  685. ->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();
  686. if(empty($ware)){
  687. return error_show(1005,"未找到仓库数据");
  688. }
  689. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  690. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  691. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  692. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  693. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  694. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  695. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  696. $list[]=$temp;
  697. }else {
  698. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  699. if (empty($returninfo)) {
  700. return error_show(1005, "未找到供应商仓库数据");
  701. }
  702. $data = [];
  703. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  704. $data['wsm_name'] = '供应商仓';
  705. $data['supplier_name'] = '供应商';
  706. $data['contactor'] = $returninfo['contactor'];
  707. $data['mobile'] = $returninfo['mobile'];
  708. $data['addr'] = $returninfo['addr'];
  709. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  710. $data['addr_code'] = $returninfo['addr_code'];
  711. $list[] = $data;
  712. }
  713. }
  714. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  715. if(empty($supplier)){
  716. return error_show(1005,"未找到供应商仓库数据");
  717. }
  718. foreach ($supplier as $value){
  719. $temp=[];
  720. $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")
  721. ->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();
  722. if(empty($ware)){
  723. continue;
  724. }
  725. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  726. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  727. $temp['supplier_name']=$value['name'];
  728. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  729. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  730. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  731. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  732. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  733. $list[]=$temp;
  734. }
  735. return app_show(0,"获取成功",$list);
  736. }
  737. public function setdelivery(){
  738. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  739. if($bkcode==""){
  740. return error_show(1005,"参数returnCode 不能为空");
  741. }
  742. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  743. if(empty($info)){
  744. return error_show(1005,"未找到售后数据");
  745. }
  746. if(($info['is_receive']==0&&$info['status']!=3)||($info['is_receive']==1&&$info['status']!=4) ){
  747. return error_show(1005,"售后单流程状态有误");
  748. }
  749. $out=Db::name("order_out")->where(["outCode"=>$info["outCode"]])->find();
  750. $is_th = isset($this->post['is_th'])&&$this->post['is_th']!=="" ? intval($this->post['is_th']):"";
  751. if($is_th===""){
  752. return error_show(1005,"参数is_th不能为空");
  753. }
  754. $company=isset($this->post['company'])&&$this->post['company']!=""?trim($this->post['company']):"";
  755. $post_code=isset($this->post['post_code'])&&$this->post['post_code']!=""?trim($this->post['post_code']):"";
  756. $post_fee=isset($this->post['post_fee'])&&$this->post['post_fee']!==""?floatval($this->post['post_fee']):"";
  757. if($is_th==1){
  758. if($company==""){
  759. return error_show(1005,"参数company不能为空");
  760. }
  761. if($post_code==""){
  762. return error_show(1005,"参数post_code不能为空");
  763. }
  764. if($post_fee==""){
  765. return error_show(1005,"参数post_fee不能为空");
  766. }
  767. }
  768. try {
  769. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  770. if($returninfo==false){
  771. $returninfo=[
  772. "returnCode"=>$bkcode,
  773. "return_wsm"=>"",
  774. "contactor"=>"",
  775. "mobile"=>"",
  776. "addr"=>"",
  777. "addr_code"=>"",
  778. "post_code"=>$post_code,
  779. "post_company"=>$company,
  780. "post_fee"=>$post_fee,
  781. "gys_remark"=>"",
  782. "addtime"=>date("Y-m-d H:i:s")
  783. ];
  784. }else{
  785. $returninfo['post_fee']=$post_fee;
  786. $returninfo['post_company']=$company;
  787. $returninfo['post_code']=$post_code;
  788. }
  789. $up =Db::name("order_returninfo")->save($returninfo);
  790. if($up){
  791. $info['status']=5;
  792. $info['updatetime']=date("y-m-d H:i:s");
  793. $ro =Db::name("order_return")->save($info);
  794. if($ro){
  795. $thNo =makeNo("TH");
  796. $thdata=[
  797. "thNo"=>$thNo,
  798. "orderCode"=>$out["orderCode"],
  799. "outCode"=>$out["outCode"],
  800. "order_type"=>$info["order_type"],
  801. "returnCode"=>$info["returnCode"],
  802. "good_code"=>$info["good_code"],
  803. "good_name"=>$info["good_name"],
  804. "return_wsm"=>$returninfo["return_wsm"],
  805. "defective_wsm"=>'',
  806. "return_msg"=>$out["error_msg"],
  807. "return_num"=>$info["total_num"],
  808. "normal_num"=>0,
  809. "received_num"=>0,
  810. "defective_num"=>0,
  811. "loss_num"=>0,
  812. "contactor"=>$returninfo["contactor"],
  813. "mobile"=>$returninfo["mobile"],
  814. "addr"=>$returninfo["addr"],
  815. "addr_code"=>$returninfo["addr_code"],
  816. "return_code"=>$info["error_code"],
  817. "post_fee"=>$returninfo["post_fee"],
  818. "post_code"=>$returninfo["post_code"],
  819. "post_company"=>$returninfo["post_company"],
  820. "customer_code"=>$returninfo["customer_code"],
  821. "status"=>1,
  822. "addtime"=>date("Y-m-d H:i:s"),
  823. "updatetime"=>date("Y-m-d H:i:s")
  824. ];
  825. $sav= Db::name("order_back")->insert($thdata);
  826. if($sav){
  827. Db::commit();
  828. return app_show(0,"退货单新建成功",["thNo"=>$thNo]);
  829. }
  830. }
  831. }
  832. Db::rollback();
  833. return error_show(1004,'退货失败');
  834. }catch (\Exception $e){
  835. Db::rollback();
  836. return error_show(1004,$e->getMessage());
  837. }
  838. }
  839. }