After.php 49 KB

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