After.php 44 KB

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