After.php 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\DataGroup as DataGroupModel;
  5. use app\admin\model\GoodLog;
  6. use app\admin\model\GoodStockInfo;
  7. use app\admin\model\ProcessOrder;
  8. use app\admin\model\ThData;use think\App;
  9. use think\Exception;
  10. use think\facade\Db;
  11. use think\facade\Validate;
  12. //售后
  13. class After extends Base
  14. {
  15. public function __construct(App $app)
  16. {
  17. parent::__construct($app);
  18. }
  19. //新建售后申请单
  20. public function create()
  21. {
  22. $param = $this->request->only(['outCode', 'errorCode', 'remark' => '', 'is_receive', 'num', 'except_code' => '', 'img'], 'post', 'trim');
  23. $val = Validate::rule([
  24. 'outCode' => 'require',
  25. 'errorCode' => 'require',
  26. 'is_receive' => 'require|in:0,1',
  27. 'num' => 'requireIf:is_receive,1',
  28. 'except_code' => 'require',
  29. 'img' => 'require',
  30. ]);
  31. if ($val->check($param) == false) return json_show(1004, $val->getError());
  32. // $outCode = isset($this->post['outCode']) &&$this->post['outCode']!=''?trim($this->post['outCode']) :"";
  33. // if($outCode==''){
  34. // return error_show(1004,"参数outCode 不能为空");
  35. // }
  36. $orderout = Db::name("order_out")
  37. ->field('id,orderCode,wsm_code,send_num,order_type')
  38. ->where(["outCode" => $param['outCode'], 'is_del' => 0])
  39. ->findOrEmpty();
  40. if (empty($orderout)) return error_show(1005, "未找到发货单数据");
  41. $after_num = Db::name("order_return")
  42. ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], 'is_del' => 0])
  43. ->where("status", "not in", [5, 6, 8])
  44. ->sum("error_num");
  45. $th_num = Db::name("order_back")
  46. ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
  47. ->where("status", "<", 4)
  48. ->sum("return_num");
  49. if ($th_num != 0 || $after_num != 0) return error_show(1005, "存在售后或售后退货未结束流程");
  50. $oder = Db::name("sale")
  51. ->where(["orderCode" => $orderout['orderCode'], "is_del" => 0])
  52. ->findOrEmpty();
  53. if (empty($oder)) return error_show(1005, "未找到订单数据");
  54. if ($oder['order_type'] != 1) {
  55. $wsm = Db::name("warehouse_info")
  56. ->where(["wsm_code" => $orderout['wsm_code']])
  57. ->findOrEmpty();
  58. if (empty($wsm)) return error_show(1005, "未找到仓库数据");
  59. // $cgder =$wsm['contactor_name'] ??'';
  60. // $cgderid =$wsm['contactor'] ??0;
  61. }
  62. // else{
  63. // $roleArr=\think\facade\Config::get("app");
  64. // $kuguan = Db::name("user_role")->where(["roleid"=>$roleArr['wsm_cgder_role'],"is_del"=>0])->column("uid");
  65. // if(empty($kuguan)){
  66. // return error_show(1005,"未找到仓库管理员数据");
  67. // }
  68. // $userinfo = Db::name("dapart_user")
  69. // $cgder =$wsm['contactor_name'] ??'';
  70. // $cgderid =$wsm['contactor'] ??0;
  71. // }
  72. if ($oder['order_type'] == 3||$oder['order_type'] == 4) {
  73. $goon = Db::name("good_zixun")
  74. ->where(["spuCode" => $oder['good_code'], "is_del" => 0])
  75. ->findOrEmpty();
  76. } else {
  77. $goon = Db::name('good_platform')
  78. ->alias('a')
  79. ->field("b.creater,b.createrid,b.supplierNo,b.supplierName")
  80. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  81. ->where(['a.skuCode' => $oder['skuCode']])
  82. ->findOrEmpty();
  83. }
  84. // $errorCode = isset($this->post['errorCode']) &&$this->post['errorCode']!=''?trim($this->post['errorCode']) :"";
  85. // if($param['outCode']==''){
  86. // return error_show(1004,"参数errorCode 不能为空");
  87. // }
  88. $error = Db::name('result_info')
  89. ->where(["result_code" => $param['errorCode'], "is_del" => 0])
  90. ->findOrEmpty();
  91. if (empty($error)) return error_show(1005, "未找到退货原因数据");
  92. $userCommon = \app\admin\common\User::getIns();
  93. $supplier = $userCommon->handle('sInfo', ['code' => $goon['supplierNo']]);
  94. // if (!isset($supplier['code']) || $supplier['code'] != 0) return json_show($supplier['code'], $supplier['message'], $supplier['data']);
  95. $supplier = $supplier['data'];
  96. // $names = $userCommon->handle('getCodeAndName', ['code' => [$oder['customer_code'], $oder['supplierNo']]]);
  97. // $supplier =Db::name("supplier")->where(["code"=>$goon['supplierNo']])->find();
  98. // if($supplier==false){
  99. // return error_show(1005,"未找到商品供应商数据");
  100. // }
  101. // $remark =isset($this->post['remark']) &&$this->post['remark']!=''?trim($this->post['remark']) :"";
  102. // $is_receive =isset($this->post['is_receive']) &&$this->post['is_receive']!==''?intval($this->post['is_receive']):"";
  103. // if($is_receive===""){
  104. // return error_show(1004,"参数 is_receive 不能为空");
  105. // }
  106. $num = $param['is_receive'] == 1 ? $param['num'] : $orderout['send_num'];
  107. // if($param['is_receive']==0){
  108. // $num=$orderout['send_num'];
  109. // }else{
  110. // $num =isset($this->post['num']) &&$this->post['num']!=''?intval($this->post['num']) :"";
  111. // if($num==""){
  112. // return error_show(1004,"参数 num 不能为空或零");
  113. // }
  114. // }
  115. $thnum = Db::name("order_back")
  116. ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
  117. ->where("status", "=", 4)
  118. ->sum("return_num");
  119. if ($num > ($orderout['send_num'] - $thnum)) return error_show(1004, "可用售后数量不足");
  120. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$orderout['orderCode']]);
  121. if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
  122. return json_show(1005, $fininfo['message']??"结算校验失败");
  123. }
  124. // $except_code =isset($this->post['except_code']) &&$this->post['except_code']!=''?trim($this->post['except_code']) :"";
  125. // $img = isset($this->post['img']) &&$this->post['img']!=''?trim($this->post['img']) :"";
  126. // $token = isset($this->post['token'])&&$this->post['token']!='' ? trim($this->post['token']):"";
  127. // if($token==''){
  128. // return error_show(105,"参数token不能为空");
  129. // }
  130. // $user =GetUserInfo($token);
  131. // if(empty($user)||$user['code']!=0){
  132. // return error_show(102,"申请人数据不存在");
  133. // }
  134. $rm = $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  135. $ri = $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  136. $returnCode = makeNo("RS");
  137. Db::startTrans();
  138. try {
  139. $in = [
  140. "returnCode" => $returnCode,
  141. "outCode" => $param['outCode'],
  142. "orderCode" => $oder['orderCode'],
  143. "good_code" => $oder['good_code'],
  144. "good_name" => $oder['good_name'],
  145. "customer_code" => $oder['customer_code'],
  146. "customer_name" =>$oder['customerName'],
  147. "apply_id" => $rm,
  148. "apply_name" => $ri,
  149. 'supplierNo' => $goon['supplierNo'],
  150. 'supplierName' => $goon['supplierName'],
  151. "cgder" => $wsm['contactor_name'] ?? '',
  152. "cgderid" => $wsm['contactor'] ?? 0,
  153. "person" => $supplier['person'] ?? '',
  154. "person_id" => $supplier['personid'] ?? 0,
  155. 'total_num' => $orderout['send_num'],
  156. "error_code" => $param['errorCode'],
  157. "error_num" => $num,
  158. "error_img" => is_array($param['img']) ? implode(',', $param['img']) : $param['img'],
  159. "error_msg" => $error['result'],
  160. "error_remark" => $param['remark'],
  161. "is_receive" => $param['is_receive'],
  162. "remark" => '',
  163. "except_code" => $param['except_code'],
  164. "order_type" => $orderout['order_type'],
  165. 'companyNo' => $oder['supplierNo'],
  166. 'companyName' => $oder['supplierName'],
  167. "status" => 1,
  168. "is_del" => 0,
  169. "addtime" => date("Y-m-d H:i:s"),
  170. "updatetime" => date("Y-m-d H:i:s"),
  171. ];
  172. $create = Db::name("order_return")->insert($in, true);
  173. $orde = ["order_code" => $returnCode, "status" => $in['status'], "action_remark" => '', "action_type" => "create"];
  174. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, 'SHD', 1, $orde);
  175. if ($create > 0) {
  176. //维护台账
  177. // Db::name('standing_book')
  178. // ->whereFindInSet('outCode', $param['outCode'])
  179. // ->update([
  180. // 'returnCode' => $returnCode,
  181. // 'updatetime' => date("Y-m-d H:i:s")
  182. // ]);
  183. Db::execute("UPDATE `wsm_standing_book` SET `returnCode`=CONCAT(IFNULL(`returnCode`,''),',{$returnCode}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$param['outCode']}',`outCode`)");
  184. //当状态为1(即待业务审核)时,要将待办数据推给以下角色的用户
  185. // $user = Db::name('user_role')
  186. // ->where([
  187. // ['is_del', '=', 0],
  188. // ['roleid', 'in', [12, 13, 17, 28]],//12客服负责人,13项目负责人,17平台负责人,28网络负责人
  189. // ['status', '=', 1],
  190. // ])->column('uid');
  191. //筛选符合数据权限的用户
  192. // $temp = getUserIdsByShare('', $in['apply_id']);
  193. // $user = array_intersect($user, $temp);
  194. $process = ["order_code" => $returnCode, "order_id" => $create, "order_status" => $in['status'], "order_type" => 'SHD', "before_status" => 0, 'holder_id' => $in['apply_id']];
  195. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
  196. Db::commit();
  197. return json_show(0, "售后申请单新建成功", ["returnCode" => $returnCode]);
  198. }
  199. Db::rollback();
  200. return error_show(1005, "售后申请单新建失败");
  201. } catch (Exception $exception) {
  202. Db::rollback();
  203. return json_show(1005, $exception->getMessage());
  204. }
  205. }
  206. //售后申请单列表
  207. public function list()
  208. {
  209. $param = $this->request->only([
  210. 'page' => 1,
  211. 'size' => 10,
  212. 'relaComNo' => '',
  213. 'returnCode' => '',
  214. 'outCode' => '',
  215. 'status' => '',
  216. 'order_type' => '',
  217. 'orderCode' => '',
  218. 'good_code' => '',
  219. 'good_name' => '',
  220. 'except_code' => '',
  221. 'apply_name' => '',
  222. 'start' => '',
  223. 'end' => '',
  224. 'company_name' => '',//部门名称
  225. 'supplierNo' => '',
  226. 'customer_code' => '',
  227. 'companyNo' => '',
  228. 'order_source' => '',
  229. 'use_type' => '',
  230. ], 'post', 'trim');
  231. $where = [['a.is_del', "=", 0]];
  232. if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
  233. if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
  234. if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
  235. if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
  236. if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
  237. if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
  238. if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
  239. if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
  240. if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
  241. if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
  242. if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
  243. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
  244. if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
  245. if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
  246. if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
  247. if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  248. if ($param['use_type'] !== '') $where[] = ['p.use_type', '=', $param['use_type']];
  249. $condition = [];
  250. //只有level2的账号过滤数据权限
  251. if ($this->level == 2) {
  252. $hand = resign_hand_user($this->uid, 0);
  253. $role = $this->checkDataShare();
  254. if (!empty($role[DataGroupModel::$type_全部])) {
  255. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  256. $condition[] = ["a.person_id", "in", $hand];
  257. $condition[] = ["a.apply_id", "in", $arr];
  258. $condition[] = ["a.cgderid", "in", $hand];
  259. // //查询所负责的供应商
  260. // $supplierNos = Db::connect('mysql_sys')
  261. // ->name('supplier')
  262. // ->where(['is_del' => 0, 'personid' => $arr])
  263. // ->column('code');
  264. // $condition[] = ["a.supplierNo", "in", $supplierNos];//这个地方不应该使用condition,应该使用where与其他条件并列
  265. }
  266. }
  267. //level3账号不允许看到库存品订单
  268. if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
  269. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  270. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  271. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  272. $count = Db::name("order_return")
  273. ->alias("a")
  274. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  275. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  276. ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
  277. ->where($where)
  278. ->where(function ($query) use ($condition) {
  279. $query->whereOr($condition);
  280. })
  281. ->count('a.id');
  282. // $total = ceil($count/$size);
  283. // $page = $total>=$page ? $page :$total;
  284. $list = Db::name("order_return")
  285. ->alias("a")
  286. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  287. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  288. ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
  289. ->where($where)
  290. ->where(function ($query) use ($condition) {
  291. $query->whereOr($condition);
  292. })
  293. ->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,c.order_source,p.use_type")
  294. ->page($param['page'], $param['size'])
  295. ->order("a.addtime desc")
  296. ->select()
  297. ->toArray();
  298. //申请人及部门
  299. $all_createrid = array_column($list, 'apply_id');
  300. $item = get_company_name_by_uid($all_createrid);
  301. //获取最新的供应商负责人信息
  302. $codes = array_unique(array_column($list,'supplierNo'));
  303. if($codes){
  304. $tmp=\app\admin\common\User::getIns()->handle('sGetList',['more_code'=>$codes,'size'=>count($codes)]);
  305. $person = array_column($tmp['data']['list'],'person','code');
  306. $personid = array_column($tmp['data']['list'],'personid','code');
  307. }
  308. //获取客户信息
  309. // $all_customer_code = array_column($list, 'customer_code');
  310. // $userCommon = \app\admin\common\User::getIns();
  311. // $customer_ = $userCommon->handle('getCodeAndName', ['code' => array_unique(array_merge(array_column($list, 'customer_code'), array_column($list, 'supplierNo')))]);
  312. //校验是否开通了供应商账号
  313. $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'supplierNo')));
  314. $data = [];
  315. foreach ($list as $value) {
  316. // $value['customer_name'] = $customer_['data'][$value['customer_code']] ?? '';
  317. // $value['supplierName'] = $customer_['data'][$value['supplierNo']] ?? '';
  318. $value['company_name'] = $item[$value['apply_id']] ?? '';
  319. $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]);
  320. $value['person'] = $person[$value['supplierNo']]??0;
  321. $value['person_id'] = $personid[$value['supplierNo']]??0;
  322. //是否具有编辑权限
  323. // $value['is_allow_update'] = 0;
  324. // if (in_array($this->roleid, [1, 33]) || in_array($value['apply_id'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  325. $data[] = $value;
  326. }
  327. return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
  328. }
  329. /**
  330. * @return \think\response\Json|void
  331. * @throws \think\db\exception\DataNotFoundException
  332. * @throws \think\db\exception\DbException
  333. * @throws \think\db\exception\ModelNotFoundException
  334. */
  335. public function info()
  336. {
  337. $bkcode = $this->request->post('returnCode', '', 'trim');//isset($this->post['returnCode']) && $this->post['returnCode'] != "" ? trim($this->post['returnCode']) : "";
  338. if ($bkcode == "") return error_show(1005, "参数returnCode 不能为空");
  339. $info = Db::name("order_return")
  340. ->alias("a")
  341. ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
  342. ->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")
  343. ->where(['a.returnCode' => $bkcode])
  344. ->findOrEmpty();
  345. if (empty($info)) return error_show(1005, "未找到售后数据");
  346. $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->findOrEmpty();
  347. $info['origin_price'] = $orderinfo['origin_price'];
  348. $info['order_type'] = $orderinfo['order_type'];
  349. $info['order_source'] = $orderinfo['order_source'];
  350. $info['is_stock'] = $orderinfo['is_stock'];
  351. // $info['customer_code'] = $orderinfo['customer_code'];
  352. // $info['companyNo'] = $orderinfo['supplierNo'];
  353. $info['sale_price'] = $orderinfo['sale_price'];
  354. $info['total_price'] = sprintf("%1\$.2f", $orderinfo['sale_price'] * $info['error_num']);
  355. if ($orderinfo['order_type'] == 3 || $orderinfo['order_type'] == 4) {
  356. $goon = Db::name("good_zixun")
  357. ->field('cat_id,supplierNo')
  358. ->where(["spuCode" => $orderinfo['good_code'], "is_del" => 0])
  359. ->findOrEmpty();
  360. } else {
  361. $goon = Db::name('good_platform')
  362. ->alias('a')
  363. ->field('b.cat_id,b.supplierNo')
  364. ->join('good b', 'b.spuCode=a.spuCode', 'left')
  365. ->where(['a.skuCode' => $orderinfo['skuCode']])
  366. ->findOrEmpty();
  367. }
  368. if (empty($goon)) return error_show(1003, "未找到商品数据");
  369. // $info['supplierNo'] = $goon['supplierNo'];
  370. $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
  371. $info['can'] = $int;
  372. $addcode = '';
  373. if ($info['addr_code'] != "") {
  374. $temp=json_decode($info['addr_code'],true);
  375. if($temp) $addcode = $info['addr_code'];
  376. else {
  377. $temp = explode(',',$info['addr_code']);
  378. $addcode = json_encode(["provice_code" => $temp[0], "city_code" => $temp[1], "area_code" => $temp[2]]);
  379. }
  380. // list($a, $b, $c) = explode(",", $info['addr_code']);
  381. // $addcode = json_encode(["provice_code" => $a, "city_code" => $b, "area_code" => $c]);
  382. }
  383. $info["addr_cn"] = GetAddr($addcode);
  384. // $info["addr_code"]=json_decode($addcode,true);
  385. $out = Db::name("order_out")->where(["outCode" => $info['outCode'], "is_del" => 0])->find();
  386. $info['out_num'] = isset($out['send_num']) ? $out['send_num'] : '';
  387. // $customer = Db::name("customer_info")->where(["companyNo"=>$info['customer_code']])->find();
  388. $wsmcode = [];
  389. $info['wsm_supplier'] = '';
  390. if ($info['return_wsm'] != '') {
  391. $wsmcode = Db::name("warehouse_info")
  392. ->alias("a")
  393. // ->leftJoin("supplier b", "a.supplierNo=b.code")
  394. ->where(["a.wsm_code" => $info['return_wsm']])
  395. // ->field("a.name as wsm_name,a.wsm_code,a.contactor_name,a.position,a.mobile,a.addrs_code,a.addr,a.companyNo,a.supplierNo")
  396. ->find();
  397. }
  398. // $userCommon = \app\admin\common\User::getIns();
  399. // $names = $userCommon->handle('getCodeAndName', ['code' => [
  400. // $wsmcode['supplierNo'] ?? '',
  401. // $wsmcode['companyNo'] ?? '',
  402. //// $info['customer_code'],
  403. //// $info['companyNo'],
  404. //// $info['supplierNo'],
  405. // ]]);
  406. if ($info['return_wsm'] != '') {
  407. $info['wsm_supplierNo'] = $wsmcode['supplierNo'] ?? "";
  408. $info['wsm_supplier'] = $wsmcode['supplierName'];//isset($wsmcode['name']) ? $wsmcode['name'] : "";
  409. $info['wsm_customer_name'] = $wsmcode['companyName'];//isset($customer['company']) ? trim($customer['company']) : '';
  410. $info['wsm_customer_code'] = $wsmcode['companyNo'] ?? "";//isset($customer['companyNo']) ? trim($customer['companyNo']) : '';
  411. $info['wsm_code'] = isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code'] : "";
  412. $info['wsm_name'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
  413. }
  414. // $customer = [];
  415. // if (isset($orderinfo['supplierNo']) && $orderinfo['supplierNo'] != '') {
  416. // $customer = Db::name("business")->field('id,company,companyNo')->where(["companyNo" => $orderinfo['supplierNo']])->find();
  417. // }
  418. // $info['customer_name'] = $names['data'][$info['customer_code']] ?? '';
  419. // $info['companyName'] = $names['data'][$info['companyNo']] ?? '';
  420. // $info['supplierName'] = $names['data'][$info['supplierNo']] ?? '';
  421. //仓库的联系人、职位、电话、省市区和地址
  422. isset($wsmcode['contactor_name']) ? $info['contactor'] = $wsmcode['contactor_name'] : '';//联系人
  423. isset($wsmcode['mobile']) ? $info['mobile'] = $wsmcode['mobile'] : '';//电话
  424. isset($wsmcode['addrs_code']) ? $info['addr_code'] = $wsmcode['addrs_code'] : '';//省市区
  425. isset($wsmcode['addr']) ? $info['addr'] = $wsmcode['addr'] : '';//和地址
  426. // $info['position'] = $wsmcode['position'];//职位
  427. // $info['mobile'] = $wsmcode['mobile'];//电话
  428. // $info['addrs_code'] = json_decode($wsmcode['addrs_code'], true);//省市区编码
  429. // $info['addr'] = $wsmcode['addr'];//地址
  430. $info['spuCode'] = $orderinfo['good_code'];
  431. $info['skuCode'] = $orderinfo['skuCode'];
  432. $info['return_tag'] = $info['return_tag'] == 0 ? "" : $info['return_tag'];
  433. $info['is_th'] = $info['is_th'] == 0 ? "" : $info['is_th'];
  434. //校验是否开通了供应商账号
  435. $supp_account = checkHasAccountBySupplierNos([$info['supplierNo']]);
  436. $info['has_account']=(int)isset($supp_account[$info['supplierNo']]);
  437. return app_show(0, "获取成功", $info);
  438. }
  439. //售后申请单 审核
  440. //申请单状态:
  441. //1待业务审核,
  442. //2待采购审核,
  443. //3待设置仓库(该节点废除),
  444. //4待客户退货(已收到货才有),
  445. //5售后已完成,
  446. //6业务已驳回,
  447. //7采购已驳回(该节点废除),
  448. //8申请已取消,
  449. //9供应商审核,
  450. //10业务公司修改待供应商确认
  451. //11待设置退货工单(已收到货才有),
  452. //12待库管收货(已收到货才有),
  453. public function status()
  454. {
  455. try {
  456. $param = $this->request->only([
  457. 'returnCode',
  458. 'status',
  459. 'remark' => '',
  460. 'wsm_code' => '',
  461. 'contactor' => '',
  462. 'mobile' => '',
  463. 'addr_code' => '',
  464. 'addr' => '',
  465. ], 'post', 'trim');
  466. $val = Validate::rule([
  467. 'returnCode' => 'require',
  468. 'status' => 'require|number|in:1,2,4,5,6,9,10,11',
  469. 'remark' => 'requireIf:status,6|requireIf:status,10',
  470. ]);
  471. if ($val->check($param) == false) throw new Exception($val->getError());
  472. $info = Db::name("order_return")
  473. ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
  474. ->findOrEmpty();
  475. if (empty($info)) throw new Exception('未找到售后数据');
  476. if ($info['status'] == 6) throw new Exception('业务已驳回,无法操作');
  477. if ($info['status'] == 5) throw new Exception('售后已完成,无法操作');
  478. if ($info['status'] == 8) throw new Exception('申请已取消,无法操作');
  479. switch ($info['status']) {
  480. case 1:
  481. if (in_array($param['status'], [6, 2, 9]) == false) throw new Exception('选项错误');
  482. if ($info['order_type'] == 1 && $param['status'] == 9) throw new Exception('选项错误');
  483. //库存品不允许供应商审核,只允许走2-11-4-12-5流程
  484. break;
  485. case 9:
  486. if (in_array($param['status'], [2, 4]) == false) throw new Exception('选项错误');
  487. if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
  488. if ($param['status'] == 4) {
  489. $info['return_tag'] = 1;
  490. if ($param['contactor'] == '') throw new Exception('收货人不能为空');
  491. if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
  492. if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
  493. if ($param['addr'] == '') throw new Exception('退货地址不能为空');
  494. }else{
  495. $info['return_tag'] = 2;
  496. }
  497. break;
  498. case 2:
  499. if ((($info['order_type'] == 1) && (in_array($param['status'], [10, 11]) == false)
  500. || (($info['order_type'] != 1) && (in_array($param['status'], [10,4]) == false)))) throw new Exception('选项错误');
  501. break;
  502. case 10:
  503. if (in_array($param['status'], [2, 4]) == false) throw new Exception('选项错误');
  504. if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
  505. if ($param['status'] == 4) {
  506. $info['return_tag'] = 1;
  507. if ($param['contactor'] == '') throw new Exception('收货人不能为空');
  508. if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
  509. if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
  510. if ($param['addr'] == '') throw new Exception('退货地址不能为空');
  511. }else{
  512. $info['return_tag'] = 2;
  513. }
  514. break;
  515. }
  516. if(in_array($info['status'],[9,10])&& $param['status'] == 4){
  517. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode'],"isCgd"=>1]);
  518. if(!isset($fininfo['code'])||$fininfo['code']!=0 )throw new Exception($fininfo['message']??"结算校验失败");
  519. }else{
  520. $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode']]);
  521. if(!isset($fininfo['code'])||$fininfo['code']!=0 )throw new Exception($fininfo['message']??"结算校验失败");
  522. }
  523. //获取最新的供应商负责人
  524. $s_info = \app\admin\common\User::getIns()->handle('sInfo', ['code' => $info['supplierNo']]);
  525. $info['person_id'] = $s_info['data']['personid']??"0";
  526. $info['person'] = $s_info['data']['person']??"";
  527. //当处于以下节点时,level2账号必须是供应商负责人操作,level3账号不做限制
  528. // if (in_array($info['status'], [9, 10]) && ($this->level == 2) && ($this->uid != $info['person_id'])) return json_show(1004, '您不是供应商负责人,此时无权操作');
  529. if ($param['remark'] != '') $info['remark'] = $param['remark'];
  530. Db::startTrans();
  531. try {
  532. $date = date('Y-m-d H:i:s');
  533. $action_log_user = ['id' => $this->uid, 'nickname' => $this->uname];
  534. //如果是小循环,增加次数
  535. if ($param['status'] == 10) $info['loop_total'] += 1;//只要走到节点10(业务公司修改,待供应商确认),就增加次数
  536. //判断 退回供应商 or 退回业务公司
  537. if ($info['status'] == 2 && $param['status'] == 11) {
  538. //退入次品仓,维护
  539. $wsm = Db::name('warehouse_info')->where(['is_del' => 0, 'wsm_code' => $param['wsm_code']])->findOrEmpty();
  540. if (empty($wsm)) throw new Exception('返回仓库不存在');
  541. if ($wsm['wsm_type'] != 4) throw new Exception('不是次品仓');
  542. Db::name('order_returninfo')->insert([
  543. 'returnCode' => $param['returnCode'],
  544. 'return_wsm' => $param['wsm_code'],
  545. 'contactor' => $wsm['contactor_name'],
  546. 'mobile' => $wsm['mobile'],
  547. 'addr' => $wsm['addr'],
  548. 'addr_code' => $wsm['addrs_code'],
  549. 'post_code' => '',
  550. 'post_company' => '',
  551. 'post_fee' => 0,
  552. 'gys_remark' => '',
  553. 'addtime' => $date,
  554. ]);
  555. }
  556. $var = $info['status'];
  557. $info['status'] = $param['status'];
  558. $info['updatetime'] = $date;
  559. $up = Db::name("order_return")->save($info);
  560. if ($up) {
  561. //售后完成
  562. if ($param['status'] == 5 && $info['is_receive'] == 0) {
  563. $orde = Db::name("order_out")
  564. ->field('id,outCode,status,send_num,error_num')
  565. ->where(["outCode" => $info['outCode'], "is_del" => 0])
  566. ->findOrEmpty();
  567. if (empty($orde)) throw new Exception('未找到出库单数据');
  568. $sale = Db::name("sale")
  569. ->field('id,th_num,th_fee,sale_price,good_code,good_name,cat_id')
  570. ->where(['is_del' => 0, "orderCode" => $info['orderCode']])
  571. ->findOrEmpty();
  572. if (empty($sale)) throw new Exception('未找到销售单数据');
  573. $od_status = $orde['status'];
  574. // $orde['status'] = 4;
  575. if ($info['error_num'] >= $orde['send_num']) $orde['status'] = 4;
  576. $orde['send_num'] -= $info['error_num'];
  577. $orde['error_num'] += $info['error_num'];
  578. $orde['updatetime'] = $date;
  579. $out = Db::name("order_out")->save($orde);
  580. if ($out == false) throw new Exception("发货单更新失败");
  581. $order = ["order_code" => $orde['outCode'], "status" => $od_status, "action_remark" => '', "action_type" => "edit"];
  582. ActionLog::logAdd($action_log_user, $order, "CKD", $orde['status'], $this->post);
  583. $process = ["order_code" => $orde['outCode'], "order_id" => $orde['id'], "order_status" => $orde['status'], "order_type" => "CKD", "before_status" => $od_status];
  584. ProcessOrder::AddProcess($action_log_user, $process);
  585. $sale['th_num'] += $info['error_num'];
  586. $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
  587. $sale['updatetime'] = $date;
  588. $sup = Db::name("sale")->save($sale);
  589. if ($sup == false) throw new Exception("销售单更新失败");
  590. $data = [
  591. "orderCode" => $info['orderCode'],
  592. "th_type" => 2,
  593. "th_num" => $info['error_num'],
  594. "th_fee" => round($info['error_num'] * $sale['sale_price'], 2),
  595. "thCode" => $info['returnCode'],
  596. "spuCode" => $sale['good_code'],
  597. "good_name" => $sale['good_name'],
  598. "cat_id" => $sale['cat_id'],
  599. "apply_id" => $info['apply_id'],
  600. "apply_name" => $info['apply_name'],
  601. "addtime" => $date,
  602. "status" => 1,
  603. "is_del" => 0
  604. ];
  605. $inse = Db::name("th_data")->insert($data);
  606. if ($inse == false) throw new Exception('退回单更新失败');
  607. }
  608. //维护退货地址的收货信息
  609. if ($info['is_receive'] == 1 && $param['status'] == 4) {
  610. $tmp = Db::name('order_returninfo')
  611. ->field('id')
  612. ->where('returnCode', $param['returnCode'])
  613. ->findOrEmpty();
  614. if (empty($tmp)) {
  615. //新增
  616. Db::name('order_returninfo')
  617. ->insert([
  618. 'returnCode' => $param['returnCode'],
  619. 'return_wsm' => $param['wsm_code'],
  620. 'contactor' => $param['contactor'],
  621. 'mobile' => $param['mobile'],
  622. 'addr' => $param['addr'],
  623. 'addr_code' => $param['addr_code'],
  624. 'addtime' => $date
  625. ]);
  626. } else {
  627. Db::name('order_returninfo')
  628. ->where('id', $tmp['id'])
  629. ->update([
  630. 'return_wsm' => $param['wsm_code'],
  631. 'contactor' => $param['contactor'],
  632. 'mobile' => $param['mobile'],
  633. 'addr' => $param['addr'],
  634. 'addr_code' => $param['addr_code'],
  635. ]);
  636. }
  637. }
  638. $order = ["order_code" => $info['returnCode'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
  639. ActionLog::logAdd($action_log_user, $order, "SHD", $info['status'], $this->post);
  640. $process = ["order_code" => $info['returnCode'], "order_id" => $info['id'], "order_status" => $param['status'], "order_type" => "SHD", "before_status" => $var, 'wait_id' => $info['person_id'], 'wait_name' => $info['person'], 'holder_id' => $info['person_id']];
  641. ProcessOrder::AddProcess($action_log_user, $process);
  642. Db::commit();
  643. return app_show(0, "更新成功");
  644. }
  645. throw new Exception('更新失败');
  646. } catch (Exception $e) {
  647. Db::rollback();
  648. throw new Exception($e->getMessage());
  649. }
  650. } catch (Exception $exception) {
  651. return json_show(1005, $exception->getMessage() );
  652. }
  653. }
  654. //设置仓库
  655. public function setWsm(){
  656. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  657. if($bkcode==""){
  658. return error_show(1005,"参数returnCode 不能为空");
  659. }
  660. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  661. if(empty($info)){
  662. return error_show(1005,"未找到售后数据");
  663. }
  664. if($info['status']!=3){
  665. return error_show(1005,"采购主管未审核无法设置退回仓库");
  666. }
  667. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']) :"";
  668. $warehouse=[];
  669. if($info['return_tag']==2) {
  670. if($wsm_code==""){
  671. return error_show(1005,"参数 wsm_code 不能为空");
  672. }
  673. $warehouse =Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
  674. if($warehouse==false){
  675. return error_show(1005,"仓库数据未找到");
  676. }
  677. $wareaddr =Db::name("warehouse_addr")->where(["wsm_code"=>$wsm_code,"is_del"=>0,"status"=>1])->find();
  678. }
  679. $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
  680. if($addrcode==""){
  681. return error_show(1005,"参数 addr_code 不能为空");
  682. }
  683. $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
  684. if($addr==""){
  685. return error_show(1005,"参数 addr 不能为空");
  686. }
  687. $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
  688. if($mobile==""){
  689. return error_show(1005,"参数 mobile 不能为空");
  690. }
  691. $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
  692. if($contactor==""){
  693. return error_show(1005,"参数 contactor 不能为空");
  694. }
  695. $returninfo=[
  696. "returnCode"=>$bkcode,
  697. "return_wsm"=>$wsm_code,
  698. "contactor"=>$contactor,
  699. "mobile"=>$mobile ,
  700. "addr"=>$addr,
  701. "addr_code"=>$addrcode,
  702. "addtime"=>date("Y-m-d H:i:s")
  703. ];
  704. Db::startTrans();
  705. try {
  706. $in=Db::name("order_returninfo")->insert($returninfo);
  707. if($in){
  708. if($info['return_tag']==2 &&$wareaddr==false) {
  709. $addrs =[
  710. "wsm_code"=>$wsm_code,
  711. "wsm_type"=>1,
  712. "wsm_name"=>$contactor,
  713. "wsm_addr"=>$addr,
  714. "addr_code"=>$addrcode,
  715. "wsm_mobile"=>$mobile,
  716. "status"=>'1',
  717. "is_del"=>'0',
  718. "addtime"=>date("Y-m-d H:i:s"),
  719. "updatetime"=>date("Y-m-d H:i:s")
  720. ];
  721. $wareaddr =Db::name("warehouse_addr")->insert($addrs);
  722. if($wareaddr==false){
  723. Db::rollback();
  724. return app_show(1004,"退货仓库地址录入失败");
  725. }
  726. }
  727. $old_info_status = $info['status'];
  728. $info['status']=4;
  729. if($info['order_type']==1){
  730. $info['cgder']=$warehouse['contactor_name']??"";
  731. $info['cgderid']=$warehouse['contactor']??0;
  732. }
  733. $info["updatetime"]=date("Y-m-d H:i:s");
  734. $up =Db::name("order_return")->save($info);
  735. if($up){
  736. //修改状态,添加待办
  737. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  738. "order_code" => $info['returnCode'],//销售单code
  739. "status" => $old_info_status,//这里的status是之前的值
  740. "action_remark" => '',//备注
  741. "action_type" => "status"//新建create,编辑edit,更改状态status
  742. ], "SHD", $info['status'], $info);
  743. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  744. "order_type" => 'SHD',
  745. "order_code" => $info['returnCode'],//销售单code
  746. "order_id" => $info['id'],
  747. "order_status" => $info['status'],
  748. "before_status"=>$old_info_status,
  749. 'holder_id'=>$info['apply_id']
  750. ]);
  751. Db::commit();
  752. return app_show(0,"退货仓库设置成功");
  753. }
  754. }
  755. Db::rollback();
  756. return error_show(1004,"设置失败");
  757. }catch (\Exception $e){
  758. Db::rollback();
  759. return error_show(1004,$e->getMessage());
  760. }
  761. }
  762. /**
  763. * @return \think\response\Json|void
  764. * @throws \think\db\exception\DataNotFoundException
  765. * @throws \think\db\exception\DbException
  766. * @throws \think\db\exception\ModelNotFoundException
  767. */
  768. public function postfeed(){
  769. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  770. if($bkcode==""){
  771. return error_show(1005,"参数returnCode 不能为空");
  772. }
  773. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  774. if(empty($info)){
  775. return error_show(1005,"未找到售后数据");
  776. }
  777. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
  778. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  779. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  780. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
  781. $this->post['addr_code']:"";
  782. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  783. if($wsm_code==""){
  784. return error_show(1005,"参数 wsm_code不能为空");
  785. }
  786. if($info['is_th']==0&&$info['order_type']==1) {
  787. $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
  788. if (empty($wsm)) {
  789. return error_show(1005, "未找到仓库数据");
  790. }
  791. $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
  792. $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
  793. $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
  794. $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
  795. $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
  796. $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
  797. $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
  798. $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
  799. $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
  800. }
  801. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  802. if($info['is_th']==1 && $info['order_type']==1){
  803. if($contactor==''){
  804. return error_show(1005,"参数 contactor 不能为空");
  805. }
  806. if($mobile==''){
  807. return error_show(1005,"参数 mobile 不能为空");
  808. }
  809. if($addr==''){
  810. return error_show(1005,"参数 addr 不能为空");
  811. }
  812. if($addr_code==''){
  813. return error_show(1005,"参数 addr_code 不能为空");
  814. }
  815. if($addr_code!==''&&is_array($addr_code)){
  816. $addrs=[];
  817. $addrs['provice_code'] = $addr_code[0];
  818. $addrs['city_code'] = $addr_code[1];
  819. $addrs['area_code'] = $addr_code[2];
  820. $addr_code = json_encode($addrs);
  821. }
  822. }
  823. Db::startTrans();
  824. try{
  825. $var=$info['status'];
  826. $info['status']=$info['order_type']==1?3:4;
  827. $info['remark']=$remark;
  828. $info['updatetime']=date("Y-m-d H:i:s");
  829. $up =Db::name("order_return")->save($info);
  830. if($up){
  831. // var_dump($contactor);
  832. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  833. if(empty($returninfo)){
  834. $returninfo=[
  835. "returnCode"=>$bkcode,
  836. "return_wsm"=>$wsm_code,
  837. "contactor"=>$contactor,
  838. "mobile"=>$mobile ,
  839. "addr"=>$addr,
  840. "addr_code"=>$addr_code,
  841. "addtime"=>date("Y-m-d H:i:s")
  842. ];
  843. }else{
  844. $returninfo['return_wsm'] = $wsm_code;
  845. //if($info['is_th']==1 && $info['order_type']==1) {
  846. $contactor !==""? $returninfo['contactor'] = $contactor:"";
  847. $mobile!==""?$returninfo['mobile'] = $mobile:"";
  848. $addr!==""? $returninfo['addr'] = $addr:"";
  849. $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
  850. // }
  851. }
  852. // var_dump($contactor);
  853. // var_dump($returninfo);
  854. $in=Db::name("order_returninfo")->save($returninfo);
  855. if($in){
  856. $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
  857. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
  858. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$var,'holder_id'=>$info['apply_id']];
  859. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  860. Db::commit();
  861. return app_show(0,"更新成功");
  862. }
  863. }
  864. Db::rollback();
  865. return error_show(1004,"更新失败");
  866. }catch (\Exception $e){
  867. Db::rollback();
  868. return error_show(1004,$e->getMessage());
  869. }
  870. }
  871. /**
  872. * @return \think\response\Json|void
  873. * @throws \think\db\exception\DataNotFoundException
  874. * @throws \think\db\exception\DbException
  875. * @throws \think\db\exception\ModelNotFoundException
  876. */
  877. public function addpost(){
  878. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  879. if($bkcode==""){
  880. return error_show(1005,"参数returnCode 不能为空");
  881. }
  882. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  883. if(empty($info)){
  884. return error_show(1005,"未找到售后数据");
  885. }
  886. $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
  887. if(empty($return_info)){
  888. $return_info=[
  889. "returnCode"=>$bkcode,
  890. "return_wsm"=>'',
  891. "contactor"=>'',
  892. "mobile"=>'',
  893. "addr"=>'',
  894. "addr_code"=>'',
  895. "addtime"=>date("Y-m-d H:i:s"),
  896. "post_company"=>'',
  897. "post_code"=>'',
  898. "post_fee"=>'',
  899. ];
  900. }
  901. $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
  902. if($post_own==''){
  903. return error_show(1005,"参数own不能为空");
  904. }
  905. $info['post_own'] = $post_own;
  906. $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
  907. if($post_company==''){
  908. return error_show(1005,"参数company不能为空");
  909. }
  910. $return_info['post_company'] = $post_company;
  911. $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
  912. if($post_code==''){
  913. return error_show(1005,"参数post_code不能为空");
  914. }
  915. $return_info['post_code'] = $post_code;
  916. $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
  917. if($fee===''){
  918. return error_show(1005,"参数post_fee不能为空");
  919. }
  920. $return_info['post_fee'] = $fee;
  921. Db::startTrans();
  922. try{
  923. $str=$info['status'];
  924. $info['status']=$info['order_type']==1?4:5;
  925. $info['updatetime']=date("Y-m-d H:i:s");
  926. $up =Db::name("order_return")->save($info);
  927. if($up){
  928. $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
  929. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
  930. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$str,'holder_id'=>$info['apply_id']];
  931. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  932. $in=Db::name("order_returninfo")->save($return_info);
  933. if($in){
  934. $data=[
  935. 'thNo'=>makeNo("ST"),
  936. "orderCode"=>$info['orderCode'],
  937. "order_type"=>$info['order_type'],
  938. "outCode"=>$info['outCode'],
  939. "returnCode"=>$info['returnCode'],
  940. "good_code"=>$info['good_code'],
  941. "good_name"=>$info['good_name'],
  942. "return_wsm"=>$return_info['return_wsm'],
  943. "return_num"=>$info['error_num'],
  944. "contactor"=>$return_info['contactor'],
  945. "mobile"=>$return_info['mobile'],
  946. "addr"=>$return_info['addr'],
  947. "addr_code"=>$return_info['addr_code'],
  948. "return_code"=>$info['error_code'],
  949. "return_msg"=>$info['error_msg'],
  950. "post_fee"=>$return_info['post_fee'],
  951. "post_code"=>$return_info['post_code'],
  952. "post_company"=>$return_info['post_company'],
  953. "customer_code"=>$info['customer_code'],
  954. "customer_name"=>$info['customer_name'],
  955. "addtime"=>date("Y-m-d H:i:s"),
  956. "updatetime"=>date("Y-m-d H:i:s"),
  957. 'supplierNo' => $info['supplierNo'],
  958. 'supplierName' => $info['supplierName'],
  959. 'companyNo' => $info['companyNo'],
  960. 'companyName' => $info['companyName'],
  961. ];
  962. $back =Db::name("order_back")->insert($data,true);
  963. if($back>0){
  964. //维护台账
  965. // Db::name('standing_book')
  966. // ->where('returnCode', $bkcode)
  967. // ->update([
  968. // 'thNo' => $data['thNo'],
  969. // 'updatetime' => date("Y-m-d H:i:s")
  970. // ]);
  971. Db::execute("UPDATE `wsm_standing_book` SET `thNo`=CONCAT(IFNULL(`thNo`,''),',{$data['thNo']}'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE FIND_IN_SET('{$bkcode}',`returnCode`)");//这里的returnCode可能有多个
  972. $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
  973. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CKTHD", 0,$data);
  974. $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>"CKTHD","before_status"=>0];
  975. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  976. Db::commit();
  977. return app_show(0,"更新成功");
  978. }
  979. }
  980. }
  981. Db::rollback();
  982. return error_show(1004,"更新失败");
  983. }catch (\Exception $e){
  984. Db::rollback();
  985. return error_show(1004,$e->getMessage());
  986. }
  987. }
  988. /**
  989. * @return \think\response\Json|void
  990. * @throws \think\db\exception\DataNotFoundException
  991. * @throws \think\db\exception\DbException
  992. * @throws \think\db\exception\ModelNotFoundException
  993. */
  994. public function GysFeed(){
  995. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  996. if($bkcode==""){
  997. return error_show(1005,"参数returnCode 不能为空");
  998. }
  999. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  1000. if(empty($info)){
  1001. return error_show(1005,"未找到售后数据");
  1002. }
  1003. $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
  1004. $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
  1005. :"";
  1006. $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
  1007. $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
  1008. $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
  1009. $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
  1010. if($isth==1){
  1011. if($contactor==''){
  1012. return error_show(1005,"参数 contactor 不能为空");
  1013. }
  1014. if($mobile==''){
  1015. return error_show(1005,"参数 mobile 不能为空");
  1016. }
  1017. if($addr==''){
  1018. return error_show(1005,"参数 addr 不能为空");
  1019. }
  1020. // var_dump(isset($this->post['addr_code']) , $this->post['addr_code']!="",!empty($addr_code));
  1021. if($addr_code==''){
  1022. return error_show(1005,"参数 addr_code 不能为空");
  1023. }
  1024. if(is_array($addr_code)){
  1025. $addrs=[];
  1026. $addrs['provice_code'] = $addr_code[0];
  1027. $addrs['city_code'] = $addr_code[1];
  1028. $addrs['area_code'] = $addr_code[2];
  1029. $addr_code = json_encode($addrs);
  1030. }
  1031. }
  1032. $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  1033. if(empty($orde)){
  1034. return error_show(1005,"未找到出库单数据");
  1035. }
  1036. Db::startTrans();
  1037. try{
  1038. $stat=$info['status'];
  1039. $info['status']=$info['order_status']==1?5:3;
  1040. $info['is_th']=$isth;
  1041. $info['updatetime']=date("Y-m-d H:i:s");
  1042. $up =Db::name("order_return")->save($info);
  1043. if($up){
  1044. $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
  1045. if(empty($returninfo)){
  1046. $returninfo=[
  1047. "returnCode"=>$bkcode,
  1048. "return_wsm"=>'',
  1049. "contactor"=>$contactor,
  1050. "mobile"=>$mobile ,
  1051. "addr"=>$addr,
  1052. "addr_code"=>$addr_code,
  1053. "gys_remark"=>$remark,
  1054. "addtime"=>date("Y-m-d H:i:s")
  1055. ];
  1056. }else{
  1057. $returninfo['return_wsm'] = '';
  1058. $returninfo['contactor'] = $contactor;
  1059. $returninfo['mobile'] = $mobile;
  1060. $returninfo['addr'] = $addr;
  1061. $returninfo['gys_remark'] = $remark;
  1062. $returninfo['addr_code'] = $addr_code;
  1063. }
  1064. $in=Db::name("order_returninfo")->save($returninfo);
  1065. if($in){
  1066. $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
  1067. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD", $info['status'],$this->post);
  1068. $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"SHD","before_status"=>$stat,'holder_id'=>$info['apply_id']];
  1069. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
  1070. Db::commit();
  1071. return app_show(0,"更新成功");
  1072. }
  1073. }
  1074. Db::rollback();
  1075. return error_show(1004,"更新失败");
  1076. }catch (\Exception $e){
  1077. Db::rollback();
  1078. return error_show(1004,$e->getMessage());
  1079. }
  1080. }
  1081. public function GetWsm(){
  1082. $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
  1083. if($bkcode==""){
  1084. return error_show(1005,"参数returnCode 不能为空");
  1085. }
  1086. $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
  1087. if($info==false){
  1088. return error_show(1005,"未找到售后数据");
  1089. }
  1090. $list=[];
  1091. if($info['is_th']==1){
  1092. if($info["order_type"]==1){
  1093. $out =Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
  1094. if(empty($out)){
  1095. return error_show(1005,"未找到出库单数据");
  1096. }
  1097. $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")
  1098. ->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();
  1099. if(empty($ware)){
  1100. return error_show(1005,"未找到仓库数据");
  1101. }
  1102. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  1103. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  1104. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  1105. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  1106. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  1107. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  1108. $temp['addr_cn'] =GetAddr( $ware['addr_code']);
  1109. $list[]=$temp;
  1110. }else {
  1111. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
  1112. if (empty($returninfo)) {
  1113. return error_show(1005, "未找到供应商仓库数据");
  1114. }
  1115. $data = [];
  1116. $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
  1117. $data['wsm_name'] = '供应商仓';
  1118. $data['supplier_name'] = '供应商';
  1119. $data['contactor'] = $returninfo['contactor'];
  1120. $data['mobile'] = $returninfo['mobile'];
  1121. $data['addr'] = $returninfo['addr'];
  1122. $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
  1123. $data['addr_code'] = $returninfo['addr_code'];
  1124. $list[] = $data;
  1125. }
  1126. }
  1127. $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
  1128. if(empty($supplier)){
  1129. return error_show(1005,"未找到供应商仓库数据");
  1130. }
  1131. foreach ($supplier as $value){
  1132. $temp=[];
  1133. $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")
  1134. ->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();
  1135. if(empty($ware)){
  1136. continue;
  1137. }
  1138. $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
  1139. $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
  1140. $temp['supplier_name']=$value['name'];
  1141. $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
  1142. $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
  1143. $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
  1144. $temp['addr_cn'] =GetAddr($ware['addr_code']);
  1145. $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
  1146. $list[]=$temp;
  1147. }
  1148. return app_show(0,"获取成功",$list);
  1149. }
  1150. //客户发货
  1151. public function setdelivery()
  1152. {
  1153. $param = $this->request->only(['returnCode', 'company', 'post_code', 'post_fee'], 'post', 'trim');
  1154. $val = Validate::rule([
  1155. 'returnCode|售后申请单编号' => 'require',
  1156. 'company|快递公司名' => 'require|max:255',
  1157. 'post_code|快递单号' => 'require|max:255',
  1158. 'post_fee|快递费用' => 'require|float',
  1159. ]);
  1160. if ($val->check($param) == false) return json_show(1004, $val->getError());
  1161. $bkcode = $param['returnCode'];
  1162. $company = $param['company'];
  1163. $post_code = $param['post_code'];
  1164. $post_fee = $param['post_fee'];
  1165. $info = Db::name("order_return")
  1166. ->where(['is_del' => 0, 'returnCode' => $bkcode])
  1167. ->findOrEmpty();
  1168. if (empty($info)) return error_show(1005, "未找到售后数据");
  1169. if (($info['is_receive'] != 1 || $info['status'] != 4)) return error_show(1005, "售后单流程状态有误");
  1170. $out = Db::name("order_out")
  1171. ->where(["outCode" => $info["outCode"], "is_del" => 0])
  1172. ->findOrEmpty();
  1173. if (empty($out)) return error_show(1005, "未找到发货单数据");
  1174. $sale = Db::name('sale')
  1175. ->where(['orderCode' => $info['orderCode'], "is_del" => 0])
  1176. ->findOrEmpty();
  1177. if (empty($sale)) return error_show(1004, "未找到销售单数据");
  1178. Db::startTrans();
  1179. try {
  1180. $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->findOrEmpty();
  1181. if (empty($returninfo)) {
  1182. //查询次品仓的信息
  1183. $wsm = Db::name('warehouse_info')
  1184. ->where(['is_del' => 0, 'companyNo' => $sale['supplierNo'], 'status' => 1, 'wsm_type' => 4])
  1185. ->findOrEmpty();
  1186. $returninfo = [
  1187. "returnCode" => $bkcode,
  1188. "return_wsm" => $wsm['wsm_code'] ?? '',
  1189. "contactor" => $wsm['contactor_name'] ?? '',
  1190. "mobile" => $wsm['mobile'] ?? '',
  1191. "addr" => $wsm['addr'] ?? '',
  1192. "addr_code" => $wsm['addrs_code'] ?? '',
  1193. "post_code" => $post_code,
  1194. "post_company" => $company,
  1195. "post_fee" => $post_fee,
  1196. "gys_remark" => "",
  1197. "addtime" => date("Y-m-d H:i:s")
  1198. ];
  1199. $up = Db::name("order_returninfo")->insert($returninfo);
  1200. } else {
  1201. $up = Db::name("order_returninfo")
  1202. ->where(["returnCode" => $bkcode])
  1203. ->update([
  1204. 'post_fee' => $post_fee,
  1205. 'post_company' => $company,
  1206. 'post_code' => $post_code,
  1207. ]);
  1208. }
  1209. if ($up) {
  1210. //查看是否有退货工单设置信息
  1211. $temp = Db::name('order_return_prepare')
  1212. ->field('id')
  1213. ->where(['is_del' => 0, 'returnCode' => $bkcode,'status'=>1])
  1214. ->findOrEmpty();
  1215. if (empty($temp)) $info['status'] = 5;//没有,更新到status5,售后申请已结束
  1216. else $info['status'] = 12;//存在,要更新到status12(待库管收货)
  1217. $old_info_status = $info['status'];
  1218. // $info['status'] = 5;
  1219. $info['updatetime'] = date("y-m-d H:i:s");
  1220. $ro = Db::name("order_return")->save($info);
  1221. if ($ro) {
  1222. //修改状态,添加待办
  1223. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  1224. "order_code" => $info['returnCode'],//销售单code
  1225. "status" => $old_info_status,//这里的status是之前的值
  1226. "action_remark" => '',//备注
  1227. "action_type" => "status"//新建create,编辑edit,更改状态status
  1228. ], "SHD", $info['status'], $this->post);
  1229. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  1230. "order_type" => 'SHD',
  1231. "order_code" => $info['returnCode'],//销售单code
  1232. "order_id" => $info['id'],
  1233. "order_status" => $info['status'],
  1234. "before_status" => $old_info_status,
  1235. 'holder_id' => $info['apply_id']
  1236. ]);
  1237. //如果售后已完成,维护销售单、发货单和采购单
  1238. if ($info['status'] == 5) {
  1239. $sale['th_num'] += $info['error_num'];
  1240. if ($sale['th_num'] == $sale['good_num']) $sale['status'] = 3;
  1241. $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
  1242. $sale['updatetime'] = date("Y-m-d H:i:s");
  1243. Db::name("sale")->save($sale);
  1244. if ($info['error_num'] >= $out['send_num']) $out['status'] = 4;
  1245. $out['send_num'] -= $info['error_num'];
  1246. $out['error_num'] += $info['error_num'];
  1247. $out['updatetime'] = date("Y-m-d H:i:s");
  1248. $upout = Db::name("order_out")->save($out);
  1249. if ($upout == false) throw new Exception('出库单数据更新失败');
  1250. $error_num = $info['error_num'];
  1251. $tmp_ooc = Db::name('order_out_child')
  1252. ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
  1253. ->field('id,num')
  1254. ->select()
  1255. ->toArray();
  1256. foreach ($tmp_ooc as $tmp) {
  1257. if ($tmp['num'] >= $error_num) {
  1258. Db::name('order_out_child')
  1259. ->data(['updatetime' => date("Y-m-d H:i:s")])
  1260. ->where(['is_del' => 0, 'id' => $tmp["id"]])
  1261. ->dec('num', $error_num)
  1262. ->update();
  1263. $error_num = 0;
  1264. } else {
  1265. Db::name('order_out_child')
  1266. ->where(['is_del' => 0, 'id' => $tmp["id"]])
  1267. ->update(['num' => 0, 'updatetime' => date("Y-m-d H:i:s")]);
  1268. $error_num -= $tmp['num'];
  1269. }
  1270. if ($error_num == 0) break;
  1271. }
  1272. //如果供应商承担,维护采购单 todo:: 新逻辑 无论供应商是否同意退货采购单都要减退回
  1273. // if ($info['return_tag'] == 1) {
  1274. $cgd_info = Db::name('order_num')
  1275. ->alias('a')
  1276. ->field('a.id,b.id cgd_id,b.good_price,b.cgdNo')
  1277. ->leftJoin('purchease_order b','b.cgdNo=a.cgdNo')
  1278. ->where(['a.orderCode' => $info['orderCode']])
  1279. ->findOrEmpty();
  1280. if (!empty($cgd_info)) {
  1281. $up= Db::name('purchease_order')
  1282. ->where(['is_del' => 0, 'id' => $cgd_info['cgd_id']])
  1283. ->data(['updatetime' => date("Y-m-d H:i:s")])
  1284. ->inc('th_num', $info['error_num'])
  1285. ->inc('th_fee', round($cgd_info['good_price'] * $info['error_num'], 2))
  1286. ->update();
  1287. if($up==false) throw new Exception('采购单更新失败');
  1288. }
  1289. // }
  1290. //todo::供应商不同意退货 生成转库存数据
  1291. }
  1292. Db::commit();
  1293. if($info["status"]==5){
  1294. $data = [
  1295. 'orderCode' => $info['orderCode'],
  1296. 'th_type' => 2,
  1297. 'th_num' => $info['error_num'],
  1298. 'th_fee' => round($info['error_num'] * $sale['sale_price'], 2),
  1299. 'thCode' => $info['returnCode'],
  1300. 'spuCode' => $sale['good_code'],
  1301. 'good_name' => $sale['good_name'],
  1302. 'sale_price' => $sale['sale_price'],
  1303. 'cgd_price' => $cgd_info['good_price'],
  1304. 'cgdNo' => $cgd_info['cgdNo'],
  1305. 'cat_id' => $sale['cat_id'],
  1306. 'apply_id' => $info['apply_id'],
  1307. 'apply_name' => $info['apply_name'],
  1308. 'addtime' => $info['updatetime'],
  1309. 'status' => 1,
  1310. 'is_del' => 0
  1311. ];
  1312. event('thdata',$data);
  1313. }
  1314. return json_show(0, '退货成功');
  1315. } else throw new Exception('修改售后申请单状态失败');
  1316. } else throw new Exception('退货失败');
  1317. } catch (Exception $e) {
  1318. Db::rollback();
  1319. return json_show(1004, $e->getMessage());
  1320. }
  1321. }
  1322. //取消售后
  1323. public function Cancel()
  1324. {
  1325. //接收参数
  1326. $data = $this->request->only(['token', 'returnCode'], 'post', 'trim');
  1327. $val = Validate::rule(['returnCode|售后单编号' => 'require']);
  1328. if (!$val->check($data)) return error_show(1005, $val->getError());
  1329. Db::startTrans();
  1330. try {
  1331. $rs = Db::name('order_return')
  1332. ->field('id,status,apply_id')
  1333. ->where([
  1334. ['returnCode', '=', $data['returnCode']],
  1335. ['is_del', '=', 0]
  1336. ])->findOrEmpty();
  1337. if (empty($rs)) throw new Exception('该售后单记录不存在');
  1338. if (in_array($rs['status'], [5,6,8,11,12])) throw new Exception('不允许取消');
  1339. //修改记录
  1340. $res = Db::name('order_return')
  1341. ->where(['id' => $rs['id']])
  1342. ->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);
  1343. if (!$res) throw new Exception('该售后单记录修改失败');
  1344. //记录日志
  1345. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "status" => $rs['status'], "action_remark" => '', "action_type" => "delete"], 'SHD', 8, $this->post);
  1346. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "order_id" => $rs['id'], "order_status" => 8, "order_type" => 'SHD', "before_status" => $rs['status'], 'holder_id' => $rs['apply_id']]);
  1347. Db::name('order_return_prepare')
  1348. ->where(['is_del' => 0, 'returnCode' => $data['returnCode'], 'status' => 1])
  1349. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  1350. //提交
  1351. Db::commit();
  1352. return app_show(0, "取消成功");
  1353. } catch (\Exception $e) {
  1354. Db::rollback();
  1355. return error_show(1004, $e->getMessage());
  1356. }
  1357. }
  1358. //根据审核完成的售后申请单,创建新的销售单和采购单
  1359. public function createSaleAndCgdByAfter()
  1360. {
  1361. $param = $this->request->only(['token', 'returnCode'], 'post', 'trim');
  1362. $val = Validate::rule(['token' => 'require', 'returnCode|售后申请单编号' => 'require']);
  1363. if (!$val->check($param)) return error_show(1005, $val->getError());
  1364. //查询售后申请单详情
  1365. $info = Db::name('order_return')
  1366. ->where('returnCode', $param['returnCode'])
  1367. ->where('is_del', 0)
  1368. ->find();
  1369. if (empty($info)) return error_show(1005, '该售后申请单不存在');
  1370. if ($info['status'] != 5) return error_show(1005, '该售后申请单尚未审核完成');
  1371. if ($info['is_reissue'] == 1) return error_show(1005, '该售后申请单已完成补发,无法重复进行');
  1372. $apply_id = GetUserInfo($param['token']);
  1373. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  1374. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1375. $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1376. //原本销售单信息
  1377. $old_sale = Db::name('sale')->where(['is_del' => 0, 'orderCode' => $info['orderCode']])->find();
  1378. if (empty($old_sale)) return error_show(1005, '没有对应的销售单信息');
  1379. //发货单信息
  1380. $old_out = Db::name('order_out')->where(['is_del' => 0, 'orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])->find();
  1381. if (empty($old_out)) return error_show(1005, '没有对应的发货单信息');
  1382. //根据是否咨询类商品,分别处理
  1383. if ($info['order_type'] == 3) return $this->createSaleZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out['addrid'], $param['token']);
  1384. else return $this->createSaleNotZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out, $param['token']);
  1385. }
  1386. /**
  1387. * 咨询类商品处理
  1388. * @param int $orid 对应售后记录的id
  1389. * @param string $spuCode 商品的spuCode
  1390. * @param array $info 售后申请单的详情
  1391. * @param array $old_sale 原始销售订单
  1392. * @param int $rm 操作人id
  1393. * @param string $ri 操作人名称
  1394. * @param int $addrid 原始发货单的地址id
  1395. * @param string $token 当前用户的token
  1396. * @throws \think\db\exception\DataNotFoundException
  1397. * @throws \think\db\exception\DbException
  1398. * @throws \think\db\exception\ModelNotFoundException
  1399. */
  1400. private function createSaleZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', int $addrid = 0, string $token = '')
  1401. {
  1402. $zxinfo = Db::name("consult_bids")->where(["bidNo" => $old_sale['zxNo'], "is_del" => 0])->find();
  1403. if ($zxinfo == false) return error_show(1005, '未找到咨询单商品信息');
  1404. $good_num = $info['error_num'];
  1405. $sale_price = 0;
  1406. $orderCode = makeNo("QR");
  1407. $skuCode = "";
  1408. //原有采购单信息
  1409. $old_cgd = Db::name('order_num')
  1410. ->alias('on')
  1411. ->field('on.id onid,po.*')
  1412. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1413. ->where('on.orderCode', $old_sale['orderCode'])
  1414. ->find();
  1415. $cgd = array_merge($old_cgd, [
  1416. 'id' => null,
  1417. // "supplierNo"=>$zxinfo['supplierNo'],
  1418. // "companyNo"=>$zxorder['companyNo'],
  1419. "spuCode" => $spuCode,
  1420. "skuCode" => $skuCode,
  1421. "orderCode" => $orderCode,
  1422. // "good_name"=>$zxinfo['good_name'],
  1423. "sale_price" => $old_cgd['good_price'],//采购单价格不为0,取原采购单的价格
  1424. "total_fee" => round($old_cgd['good_price'] * $good_num, 2),
  1425. // "pakge_fee"=>$zxinfo['pakge_fee'],
  1426. // "cert_fee"=>$zxinfo['cert_fee'],
  1427. // "open_fee"=>$zxinfo['open_fee'],
  1428. 'cost_fee' => $old_cgd['teach_fee'],
  1429. // $old_sale['cost_fee']=$old_sale['teach_fee'];
  1430. // "mark_fee"=>$zxinfo['mark_fee'],
  1431. // "demo_fee"=>$zxinfo['demo_fee'],
  1432. // "nake_fee"=>$zxinfo['nake_fee'],
  1433. // "delivery_fee"=>$zxinfo['delivery_fee'],
  1434. "good_num" => $good_num,
  1435. "createrid" => $rm,
  1436. "creater" => $ri,
  1437. "good_type" => 1,
  1438. // "weight"=>$zxinfo['good_weight'],
  1439. // "gold_price"=>$zxinfo['gold_price'],
  1440. // "is_diff"=>$zxinfo['is_diff'],
  1441. "order_type" => 3,//咨询商品
  1442. "order_source" => 6,//6售后补换货
  1443. // 'send_way'=>$zxinfo['send_way']
  1444. 'token' => $token,
  1445. 'good_createrid' => $zxinfo['createrid'],
  1446. 'good_creater' => $zxinfo['creater'],//商品创建人
  1447. ]);
  1448. // $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
  1449. // if($token==""){
  1450. // return error_show(102, "参数token不能为空");
  1451. // }
  1452. // $apply_id = GetUserInfo($token);
  1453. // if (empty($apply_id) || $apply_id['code'] != 0) {
  1454. // return error_show(102, "申请人数据不存在");
  1455. // }
  1456. // $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1457. // $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  1458. // $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
  1459. // $send_num=0;
  1460. // if($sendtype==1){
  1461. // if ($va == "") {
  1462. // return error_show(1002, "参数order_addr不能为空");
  1463. // }
  1464. // $send_num = array_sum(array_column($va,"receipt_quantity"));
  1465. // }
  1466. // if($good_num<$send_num){
  1467. // return error_show(1002, "发货数量不能超过购买数量");
  1468. // }
  1469. // $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
  1470. // if($arrtime==""){
  1471. // return error_show(1002, "参数arrtime不能为空");
  1472. // }
  1473. //新加字段
  1474. // $platform_order=isset($this->post['platform_order'])&&$this->post['platform_order']!="" ?$this->post['platform_order']:"";
  1475. // $workNo=isset($this->post['workNo'])&&$this->post['workNo']!="" ?$this->post['workNo']:"";
  1476. // $proof_type = isset($this->post['proof_type']) && $this->post['proof_type'] != "" ? intval($this->post['proof_type']) : 0;
  1477. // $proof_url = isset($this->post['proof_url']) && $this->post['proof_url'] != "" ? trim($this->post['proof_url']) : '';
  1478. Db::startTrans();
  1479. try {
  1480. // $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->lock(true)->find();
  1481. // if($zx==false){
  1482. // Db::rollback();
  1483. // return error_show(1003,"未找到咨询单信息");
  1484. // }
  1485. // $supplier_temp_info = Db::name('supplier')
  1486. // ->field('id,person,personid')
  1487. // ->where('code',$old_cgd['supplierNo'])
  1488. // ->findOrEmpty();
  1489. $user= \app\admin\common\User::getIns();
  1490. $supplier_temp_info =$user->handle("sInfo",["code"=>$old_cgd['supplierNo']]);
  1491. $data = array_merge($old_sale, [
  1492. 'id' => null,
  1493. "orderCode" => $orderCode,
  1494. "good_code" => $spuCode,
  1495. // "skuCode"=>$skuCode,
  1496. // "customer_code"=>$zxorder['khNo'],
  1497. // "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
  1498. "good_num" => $good_num,
  1499. // "cat_id"=>$zxinfo['cat_id'],
  1500. "apply_id" => $rm,
  1501. "apply_name" => $ri,
  1502. // "origin_price"=>$zxinfo['total_fee'],
  1503. // "sale_price" => $old_sale['sale_price'],//取原价格
  1504. // "post_fee"=>0,
  1505. "status" => 0,
  1506. "send_status" => 0,
  1507. "th_num" => 0,
  1508. "th_fee" => 0,//退货金额为0
  1509. "send_num" => 0,
  1510. "wsend_num" => $good_num,
  1511. // "send_status"=>1,
  1512. "good_type" => 1,
  1513. // "send_type"=>$sendtype,
  1514. // "supplierNo"=>$zxorder['companyNo'],
  1515. "is_del" => 0,
  1516. // "zxNo"=>$bidNo,
  1517. // "platform_order"=>$platform_order,
  1518. // "platform_id"=> $zxorder['platform_code'],
  1519. "remark" => $old_sale['orderCode'],
  1520. // "arrive_time"=>$arrtime,
  1521. // "is_stock"=>0,
  1522. // "is_activity"=>0,
  1523. // "proof_id"=>0,
  1524. "order_type" => 3,
  1525. "order_source" => 6,//6售后补换货
  1526. // 'good_weight'=>$zxinfo['good_weight'],
  1527. // 'gold_price'=>$zxinfo['gold_price'],
  1528. // 'cost_price'=>$zxinfo['sale_cost_fee'],
  1529. // 'diff_weight'=>0,
  1530. // 'diff_fee'=>0,
  1531. "addtime" => date("Y-m-d H:i:s"),
  1532. "updatetime" => date("Y-m-d H:i:s"),
  1533. 'returnCode' => $info['returnCode'],
  1534. // 'total_price' => round($sale_price * $good_num, 2),
  1535. // 'workNo'=>$workNo,
  1536. 'cgderid' => $supplier_temp_info['data']['personid']??0,
  1537. 'cgder' => $supplier_temp_info['data']['person']??"",//采购员(供应商负责人)
  1538. 'good_createrid' => $zxinfo['createrid'],
  1539. 'good_creater' => $zxinfo['creater'],//商品创建人
  1540. ]);
  1541. $datainfo = Db::name('sale')->insertGetId($data);
  1542. if ($datainfo > 0) {
  1543. $standing_book_data = [
  1544. 'sale_id' => $datainfo,
  1545. 'infoNo' => $zxinfo['infoNo'],
  1546. 'updatetime' => date('Y-m-d H:i:s')
  1547. ];
  1548. //修改状态,添加待办
  1549. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1550. "order_code" => $orderCode,//销售单code
  1551. "status" => 0,//这里的status是之前的值
  1552. "action_remark" => '',//备注
  1553. "action_type" => "create"//新建create,编辑edit,更改状态status
  1554. ], "XSQRD", $data['status'], $data);
  1555. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1556. "order_type" => 'XSQRD',
  1557. "order_code" => $orderCode,//销售单code
  1558. "order_id" => $datainfo,
  1559. "order_status" => $data['status'],
  1560. "before_status" => 0,
  1561. 'holder_id' => $data['apply_id']
  1562. ]);
  1563. // $old_zx_status = $zx['status'];
  1564. // $zx['status']=5;
  1565. // $zx['updatetime']=date("Y-m-d H:i:s");
  1566. // $sa=Db::name("consult_info")->save($zx);
  1567. // if($sa==false){
  1568. // Db::rollback();
  1569. // return error_show(1002,"咨询单修改失败");
  1570. // }else{
  1571. // //修改状态,添加待办
  1572. // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1573. // "order_code" => $zx['infoNo'],//咨询单详情编号
  1574. // "status" => $old_zx_status,//这里的status是之前的值
  1575. // "action_remark" => '',//备注
  1576. // "action_type" => "status"//新建create,编辑edit,更改状态status
  1577. // ], "ZXD", 5, $zx);
  1578. //
  1579. // }
  1580. $this->createCgd($cgd, $standing_book_data);
  1581. // if($bol==false){
  1582. // Db::rollback();
  1583. // return error_show(1002,"咨询订单创建失败");
  1584. // }
  1585. // $limt=[
  1586. // "spuCode"=>$zxinfo['spuCode'],
  1587. // "good_name"=>$zxinfo['good_name'],
  1588. // "brand_id"=>$zxinfo['brand_id'],
  1589. // "good_unit"=>$zxinfo['unit_id'],
  1590. // "cat_id"=>$zxinfo['cat_id'],
  1591. // "good_type"=>0,
  1592. // "moq"=>1,
  1593. // "customized"=>$zxinfo['work_day'],
  1594. // "tax"=>$zxinfo['tax'],
  1595. // "supplierNo"=>$zxinfo["supplierNo"],
  1596. // "is_auth"=>0,
  1597. // "craft_desc"=>$zxinfo['good_name'],
  1598. // "good_remark"=>"",
  1599. // "platform_id"=>$zxorder['platform_id'],
  1600. // "good_img"=>$zxinfo['good_img'],
  1601. // "good_thumb_img"=>"",
  1602. // "good_info_img"=>"",
  1603. // "specinfo"=>$zxinfo['specinfo'],
  1604. // "work_day"=>$zxinfo['work_day'],
  1605. // "noble_metal"=>$zxinfo['metal_id'],
  1606. // "is_gold_price"=>$zxinfo['is_gold_price'],
  1607. // "config"=>$zxinfo['config'],
  1608. // "other_config"=>$zxinfo['other_config'],
  1609. // "weight"=>$zxinfo['weight'],
  1610. // "good_weight"=>$zxinfo['good_weight'],
  1611. // "is_diff"=>$zxinfo['is_diff'],
  1612. // "supply_area"=>$zxinfo['supply_area'],
  1613. // "pay_way"=>$zxinfo['pay_way'],
  1614. // "send_way"=>$zxinfo['send_way'],
  1615. // "companyNo"=>$zxorder['companyNo'],
  1616. // "status"=>1,
  1617. // "is_del"=>0,
  1618. // "createrid"=>$zxinfo['createrid'],
  1619. // "creater"=>$zxinfo['creater'],
  1620. // "addtime"=>date("Y-m-d H:i:s"),
  1621. // "updatetime"=>date("Y-m-d H:i:s"),
  1622. // 'proof_type' => $proof_type,//凭证类型
  1623. // 'proof_url' => $proof_url,//凭证文件
  1624. // ];
  1625. // $good = Db::name("good_zixun")->insert($limt);
  1626. // if(!$good){
  1627. // Db::rollback();
  1628. // return error_show(1006,"咨询商品录入失败");
  1629. // }
  1630. // if(!empty($va)){
  1631. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
  1632. if (empty($order)) throw new Exception('采购单关联数据未找到');
  1633. // foreach ($va as $value){
  1634. // $temp=[];
  1635. // $addrs=[];
  1636. // if($value['addr_code']!==''&&is_array($value['addr_code'])&&!empty($value['addr_code'])){
  1637. // $addrs['provice_code'] = $value['addr_code'][0];
  1638. // $addrs['city_code'] = $value['addr_code'][1];
  1639. // $addrs['area_code'] = $value['addr_code'][2];
  1640. // $addr = json_encode($addrs);
  1641. // }else{
  1642. // $addr = isset($value['addr_code'])?$value['addr_code']:'';
  1643. // }
  1644. // $temp['orderCode']=$orderCode;
  1645. // $temp['contactor']=$value['contactor'];
  1646. // $temp['mobile'] = $value['mobile'];
  1647. // $temp['addr'] = $value['addr'];
  1648. // $temp['addr_code']=$addr;
  1649. // $temp['customer_code'] =$zxorder['khNo'];
  1650. // $temp['receipt_quantity']=$value['receipt_quantity'];
  1651. // $temp['post_fee'] =0;
  1652. // $temp['is_del'] =0;
  1653. // $temp['addtime'] =date("Y-m-d H:i:s");
  1654. // $temp['updatetime'] =date("Y-m-d H:i:s");
  1655. // $temp['arrive_time']=$arrtime;
  1656. $old_out_addr_info = Db::name('order_out')
  1657. ->alias('oo')
  1658. ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
  1659. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  1660. ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
  1661. ->find();
  1662. if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
  1663. $temp = [
  1664. 'orderCode' => $orderCode,
  1665. 'addr' => $old_out_addr_info['addr'],
  1666. 'addr_code' => $old_out_addr_info['addr_code'],
  1667. 'contactor' => $old_out_addr_info['contactor'],
  1668. 'mobile' => $old_out_addr_info['mobile'],
  1669. 'customer_code' => $old_out_addr_info['customer_code'],
  1670. 'receipt_quantity' => $good_num,
  1671. 'arrive_time' => $old_out_addr_info['arrive_time'],
  1672. 'addtime' => date("Y-m-d H:i:s"),
  1673. 'updatetime' => date("Y-m-d H:i:s"),
  1674. // ''=>'',
  1675. ];
  1676. $addrid = Db::name('order_addr')->insertGetId($temp);
  1677. // if($vmp>0){
  1678. $outCode = makeNo("DF");
  1679. $out = [
  1680. "orderCode" => $orderCode,
  1681. "outCode" => $outCode,
  1682. "apply_id" => $rm,
  1683. "apply_name" => $ri,
  1684. 'addrid' => $addrid,
  1685. "post_name" => "",
  1686. "post_code" => "",
  1687. "post_fee" => 0,
  1688. "sendtime" => date("Y-m-d H:i:s"),
  1689. "send_num" => $good_num,
  1690. "check_num" => 0,
  1691. "error_num" => 0,
  1692. "wsm_code" => "",
  1693. "order_type" => 3,
  1694. "status" => 0,
  1695. "addtime" => date("Y-m-d H:i:s"),
  1696. "updatetime" => date("Y-m-d H:i:s")
  1697. ];
  1698. $ou = Db::name("order_out")->insert($out);
  1699. if ($ou == false) throw new Exception('发货地址添加创建失败');
  1700. else {
  1701. //修改状态,添加待办
  1702. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1703. "order_code" => $outCode,//出库单号
  1704. "status" => 0,//这里的status是之前的值
  1705. "action_remark" => '',//备注
  1706. "action_type" => "create"//新建create,编辑edit,更改状态status
  1707. ], "CKD", 0, $out);
  1708. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1709. "order_type" => 'CKD',
  1710. "order_code" => $outCode,//出库单号
  1711. "order_id" => Db::name("order_out")->getLastInsID(),
  1712. "order_status" => 0,
  1713. "before_status" => 0,
  1714. 'holder_id' => $out['apply_id']
  1715. ]);
  1716. //将发货编号添加到台账中
  1717. $standing_book_data['outCode'][] = $outCode;
  1718. }
  1719. $order['send_num'] += $good_num;
  1720. $order['wsend_num'] -= $good_num;
  1721. if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
  1722. $ups = Db::name("order_num")->save($order);
  1723. if ($ups) {
  1724. $sen = Db::name("order_send")->save([
  1725. "cgdNo" => $order['cgdNo'],
  1726. "outCode" => $outCode,
  1727. "send_num" => $good_num,
  1728. "status" => 1,
  1729. "addtime" => date("Y-m-d H:i:s"),
  1730. "updatetime" => date("Y-m-d H:i:s")
  1731. ]);
  1732. if ($sen == false) throw new Exception('发货地址添加创建失败');
  1733. }
  1734. // }else{
  1735. // Db::rollback();
  1736. // return error_show(1002,"发货地址添加创建失败");
  1737. // }
  1738. // }
  1739. //处理台账
  1740. if (isset($standing_book_data['outCode'])) {
  1741. Db::execute("UPDATE `wsm_standing_book` SET `outCode`=CONCAT(IFNULL(`outCode`,''),'," . implode(',', $standing_book_data['outCode']) . "'),`updatetime`='" . date('Y-m-d H:i:s') . "' WHERE `infoNo`='{$standing_book_data['infoNo']}'");
  1742. unset($standing_book_data['outCode']);
  1743. }
  1744. Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
  1745. Db::name('order_return')
  1746. ->where(['id' => $orid, 'is_reissue' => 0])
  1747. ->update([
  1748. 'is_reissue' => 1,
  1749. 'newOrderCode' => $orderCode,
  1750. 'updatetime' => date('Y-m-d H:i:s')
  1751. ]);
  1752. Db::commit();
  1753. return app_show(0, "咨询订单创建成功", ["order_code" => $orderCode]);
  1754. }
  1755. Db::rollback();
  1756. return error_show(1002, "咨询订单创建失败");
  1757. } catch (Exception $e) {
  1758. Db::rollback();
  1759. return error_show(1003, $e->getMessage() . '|' . $e->getFile() . ':' . $e->getLine());
  1760. }
  1761. }
  1762. private function createCgd($data,array &$standing_book_da=[]){
  1763. $cgdCode = makeNo("CG");
  1764. // $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
  1765. $user= \app\admin\common\User::getIns();
  1766. $supplier_temp =$user->handle("sInfo",["code"=>$data['supplierNo']]);
  1767. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
  1768. $supplier=$supplier_temp['data'];
  1769. $wsm= Db::name("warehouse_info")
  1770. ->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"wsm_type"=>2,"is_del"=>0])
  1771. ->find();
  1772. if($wsm==false){
  1773. $wsm_code = makeNo("WSM");
  1774. $inwsm=[
  1775. "wsm_code"=>$wsm_code,
  1776. "name"=>$supplier['name'],
  1777. "wsm_type"=>2,
  1778. "supplierNo"=>$supplier['code'],
  1779. "addr"=>"",
  1780. "addrs_code"=>"",
  1781. "contactor"=>$data['order_type']==1? $supplier['personid']:$data['createrid'],
  1782. "contactor_name"=>$data['order_type']==1? $supplier['person']:$data['creater'],
  1783. "mobile"=>"",
  1784. "position"=>"",
  1785. "companyNo"=>$data['companyNo'],
  1786. "status"=>1,
  1787. "is_del"=>0,
  1788. "addtime"=>date("Y-m-d H:i:s"),
  1789. "updatetime"=>date("Y-m-d H:i:s")
  1790. ];
  1791. $in = Db::name("warehouse_info")->insert($inwsm);
  1792. if($in==false) throw new Exception('仓库新增失败');
  1793. }else $wsm_code =$wsm['wsm_code'];
  1794. //判断该供应商是否开通了供应商账号
  1795. $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
  1796. $cg =[
  1797. "cgdNo"=>$cgdCode,
  1798. "bkcode"=>"",
  1799. "wsm_code"=>$wsm_code,
  1800. "cgder"=>$data['good_creater'],
  1801. "cgder_id"=>$data['good_createrid'],
  1802. "spuCode"=>$data['spuCode'],
  1803. "skuCode"=>$data['skuCode'],
  1804. "good_name"=>$data['good_name'],
  1805. "good_num"=>$data['good_num'],
  1806. "good_price"=>$data['sale_price'],
  1807. "total_fee"=>round($data['sale_price']*$data['good_num'],2),
  1808. "pakge_fee"=>$data['pakge_fee'],
  1809. "cert_fee"=>$data['cert_fee'],
  1810. "open_fee"=>$data['open_fee'],
  1811. "teach_fee"=>$data['cost_fee'],
  1812. "mark_fee"=>$data['mark_fee'],
  1813. "demo_fee"=>$data['demo_fee'],
  1814. "nake_fee"=>$data['nake_fee'],
  1815. "weight"=>$data['weight'],
  1816. "delivery_fee"=>$data['delivery_fee'],
  1817. "gold_price"=>$data['gold_price'],
  1818. "diff_weight"=>"0",
  1819. "diff_fee"=>"0",
  1820. "supplierNo"=>$data['supplierNo'],
  1821. "supplier_name"=>$supplier['name'],
  1822. "companyNo"=>$data['companyNo'],
  1823. "send_status"=>1,
  1824. "send_num"=>0,
  1825. "wsend_num"=>$data['good_num'],
  1826. "remark"=>"",
  1827. "status"=>0,//0初始化
  1828. "lasttime"=>date("Y-m-d H:i:s"),
  1829. "is_del"=>0,
  1830. "order_type"=>$data['order_type'],
  1831. "order_source"=>$data['order_source'],
  1832. "good_type"=>$data['good_type'],
  1833. "addtime"=>date("Y-m-d H:i:s"),
  1834. "updatetime"=>date("Y-m-d H:i:s"),
  1835. 'good_createrid' => $data['good_createrid'],
  1836. 'good_creater' => $data['good_createrid'],//商品创建人
  1837. 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  1838. ];
  1839. $up =Db::name("purchease_order")->insertGetId($cg);
  1840. if($up){
  1841. //修改状态,添加待办
  1842. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1843. "order_code" => $cg['cgdNo'],//销售单code
  1844. "status" => 0,//这里的status是之前的值
  1845. "action_remark" => '',//备注
  1846. "action_type" => "create"//新建create,编辑edit,更改状态status
  1847. ], "CGD", $cg['status'], $cg);
  1848. ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1849. "order_type" => 'CGD',
  1850. "order_code" => $cg['cgdNo'],//销售单code
  1851. "order_id" => $up,
  1852. "order_status" => $cg['status'],
  1853. "before_status"=> 0,
  1854. 'holder_id' => $supplier['personid'],
  1855. 'wait_id' => $supplier['personid'],
  1856. 'wait_name' => $supplier['person'],
  1857. ]);
  1858. $standing_book_da = array_merge($standing_book_da, [
  1859. 'orderCode' => $data['orderCode'],
  1860. 'cgdNo' => $cgdCode,
  1861. 'spuCode' => $data['spuCode'],
  1862. 'skuCode' => $data['skuCode'],
  1863. 'order_type' => $data['order_type'],
  1864. 'order_source' => $data['order_source'],
  1865. 'supplierNo' => $data['supplierNo'],
  1866. "companyNo" => $data['companyNo'],
  1867. ]);
  1868. $rela=[
  1869. "orderCode"=>$data['orderCode'],
  1870. "cgdNo"=>$cgdCode,
  1871. "spuCode"=>$data['spuCode'],
  1872. "good_num"=>$data['good_num'],
  1873. "wsend_num"=>$data['good_num'],
  1874. "send_num"=>0,
  1875. "wait_num"=>0,
  1876. "status"=>1,
  1877. "source"=>2
  1878. ];
  1879. Db::name("order_num")->save($rela);
  1880. $stokc =Db::name("good_stock")
  1881. ->where(['spuCode'=>$data['spuCode'],"wsm_code"=>$wsm_code, "is_del"=>0])
  1882. ->find();
  1883. if($stokc==false){
  1884. $stokc=[
  1885. "spuCode"=>$data['spuCode'],
  1886. "wsm_code"=>$wsm_code,
  1887. "wait_in_stock"=>$data['good_num'],
  1888. "wait_out_stock"=>0,
  1889. "usable_stock"=>0,
  1890. "intra_stock"=>0,
  1891. "total_stock"=>0,
  1892. "status"=>1,
  1893. "addtime"=>date("Y-m-d H:i:s"),
  1894. "updatetime"=>date("Y-m-d H:i:s")
  1895. ];
  1896. }else{
  1897. $stokc['wait_in_stock']+=$data['good_num'];
  1898. $stokc['updatetime']=date("Y-m-d H:i:s");
  1899. }
  1900. $stoc= Db::name("good_stock")->save($stokc);
  1901. if($stoc==false) throw new Exception('商品仓库库存修改失败');
  1902. $good_data[] = ['good_log_code' =>$cgdCode, "stock_id" => isset($stoc['id'])?$stoc['id']:Db::name("good_stock")->getLastInsID(), "type" => 1,'stock'=>$data['good_num'], "stock_name" => "wait_in_stock"];
  1903. GoodLog::LogAdd($data['token'],$good_data,"CGD");
  1904. return true;
  1905. }else throw new Exception('商品仓库库存修改失败');
  1906. }
  1907. //创建采购单
  1908. /**
  1909. * 非咨询类商品处理
  1910. * @param int $orid 售后记录的id
  1911. * @param string $spuCode 商品的spuCode
  1912. * @param array $info 售后申请单的详情
  1913. * @param array $old_sale 原始销售订单信息
  1914. * @param int $rm 操作人id
  1915. * @param string $ri 操作人名称
  1916. * @param array $old_out 原始发货单信息
  1917. * @param string $token 当前用户的token
  1918. * @throws \think\db\exception\DataNotFoundException
  1919. * @throws \think\db\exception\DbException
  1920. * @throws \think\db\exception\ModelNotFoundException
  1921. */
  1922. private function createSaleNotZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', array $old_out = [], string $token = '')
  1923. {
  1924. $goodinfo = Db::name('good')
  1925. ->alias('g')
  1926. ->field('g.*,gp.skuCode')
  1927. ->join('good_platform gp', 'gp.spuCode=g.spuCode AND gp.exam_status=3')
  1928. ->where('g.spuCode', $spuCode)
  1929. ->where('gp.skuCode', $old_sale['skuCode'])
  1930. ->find();
  1931. if (empty($goodinfo)) return error_show(1005, '查不到这个商品,或该商品已下线无法售后');
  1932. $is_activity = $old_sale['is_activity'];
  1933. $actcode = $old_sale['activity_code'];
  1934. $good_num = $info['error_num'];//数量,取售后申请单中的异常数量
  1935. $supplierNo = $old_sale['supplierNo'];
  1936. $sale_price = 0;
  1937. $origin_price = $old_sale['origin_price'];
  1938. $goodtype = $old_sale['good_type'];
  1939. $is_stock = $goodinfo['is_stock'];
  1940. $skuCode = $goodinfo['skuCode'];
  1941. $orderCode = makeNo("QR");
  1942. if ($is_stock == 1) {
  1943. $stock_num = Db::name("good_stock")->alias("a")
  1944. ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  1945. ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
  1946. ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
  1947. ->sum('balance_num');
  1948. if($stock_num < $good_num){
  1949. return error_show(1003, "批次库存数量不足"); //库存不足
  1950. }
  1951. }
  1952. $goodinfo['cgd_gold_price'] = 0;
  1953. if ($goodtype == 1) {
  1954. if ($is_activity == 1) {
  1955. $act = Db::name("activity_info")
  1956. ->alias("a")
  1957. ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
  1958. ->where(["a.skuCode" => $skuCode, "a.activity_code" => $actcode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
  1959. ->find();
  1960. if ($act == false) return error_show(1003, "未找到相关活动价");
  1961. if ($act['moq_num'] > $good_num) return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
  1962. if ($act['activity_stock'] < $good_num) return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
  1963. }
  1964. // else {
  1965. // $good = Db::name("good_ladder")
  1966. // ->where(["skuCode" => $skuCode, "is_del" => 0, "status" => 1])
  1967. // ->where([["min_num", "<=", $good_num]])
  1968. // ->order("min_num desc")
  1969. // ->find();
  1970. //
  1971. // if ($good == false) return error_show(1003, "未找到相关阶梯价格");
  1972. //
  1973. // if ($goodinfo['is_gold_price'] == 1 && $is_stock != 1) {
  1974. // $gold = Db::name("gold_price1")
  1975. // ->field('id,price')
  1976. // ->where(["type" => $goodinfo['noble_metal'], "is_del" => 0, "status" => 1])
  1977. // ->order("addtime desc")
  1978. // ->find();
  1979. //
  1980. // $goodinfo['cgd_gold_price'] = $gold["price"];
  1981. // }
  1982. // }
  1983. }
  1984. //原有采购单信息
  1985. if ($is_stock != 1){
  1986. $old_cgd = Db::name('order_num')
  1987. ->alias('on')
  1988. ->field('on.id onid,po.*')
  1989. ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
  1990. ->where('on.orderCode', $old_sale['orderCode'])
  1991. ->find();
  1992. $cgd = array_merge($old_cgd, [
  1993. 'id' => null,
  1994. // "supplierNo" => $ct['supplierNo'],
  1995. // "companyNo" => $supplierNo,
  1996. "orderCode" => $orderCode,
  1997. "spuCode" => $spuCode,
  1998. "skuCode" => $skuCode,
  1999. // "good_name" => $ct['good_name'],
  2000. "sale_price" => $old_cgd['good_price'],//采购单价格不为0,取原采购单的价格
  2001. "total_fee" => $old_cgd['good_price'] * $good_num,
  2002. // "pakge_fee" => isset($origin['package_fee']) ? $origin['package_fee'] : 0,
  2003. // "cert_fee" => isset($origin['cert_fee']) ? $origin['cert_fee'] : 0,
  2004. // "open_fee" => $ct['open_fee'],
  2005. // "cost_fee" => isset($origin['cost_fee']) ? $origin['cost_fee'] : 0,
  2006. 'cost_fee' => $old_cgd['teach_fee'],
  2007. // "mark_fee" => isset($origin['mark_fee']) ? $origin['mark_fee'] : 0,
  2008. // "nake_fee" => isset($origin['nake_fee']) ? $origin['nake_fee'] : 0,
  2009. // "delivery_fee" => isset($origin['delivery_fee']) ? $origin['delivery_fee'] : 0,
  2010. // "demo_fee" => $ct['demo_fee'],
  2011. "good_num" => $good_num,
  2012. // "good_type" => $goodtype,
  2013. // "weight" => $ct['noble_weight'],
  2014. // "gold_price" => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
  2015. // "order_type" => $is_stock == 1 ? 1 : 2,
  2016. "order_source" => 6,//6售后补换货
  2017. "createrid" => $rm,
  2018. "creater" => $ri,
  2019. // 'send_way' => 2,
  2020. 'token' => $token,
  2021. 'addtime' => date('Y-m-d H:i:s'),
  2022. 'updatetime' => date('Y-m-d H:i:s'),
  2023. 'good_createrid' => $goodinfo['createrid'],
  2024. 'good_creater' => $goodinfo['creater'],//商品创建人
  2025. ]);
  2026. // $supplier_temp_info = Db::name('supplier')
  2027. // ->field('id,person,personid')
  2028. // ->where('code',$cgd['supplierNo'])
  2029. // ->findOrEmpty();
  2030. $user= \app\admin\common\User::getIns();
  2031. $supplier_temp =$user->handle("sInfo",["code"=>$cgd['supplierNo']]);
  2032. }else{
  2033. $user= \app\admin\common\User::getIns();
  2034. $supplier_temp =$user->handle("sInfo",["code"=>$goodinfo['supplierNo']]);
  2035. // $supplier_temp_info = Db::name('supplier')
  2036. // ->field('id,person,personid')
  2037. // ->where('code',$goodinfo['supplierNo'])
  2038. // ->findOrEmpty();
  2039. }
  2040. $supplier_temp_info = [
  2041. "id"=>$supplier_temp['data']['id']??0,
  2042. "person"=>$supplier_temp['data']['person']??'',
  2043. "personid"=>$supplier_temp['data']['personid']??0,
  2044. ];
  2045. // $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
  2046. $send_num = 0;
  2047. // if($sendtype==1){
  2048. // if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
  2049. // return error_show(1004,"参数addrlist不能为空");
  2050. // }
  2051. // $send_num = array_sum(array_column($addrlist,"receipt_quantity"));
  2052. // }
  2053. // if($send_num>$good_num){
  2054. // return error_show(1004,"发货数量超出订单总数量");
  2055. // }
  2056. // $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
  2057. // $proof_id =isset($this->post['proof_id']) && $this->post['proof_id'] !=="" ?intval($this->post['proof_id']):0;
  2058. // $apply_id = GetUserInfo($param['token']);
  2059. // if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
  2060. // $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2061. // $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  2062. Db::startTrans();
  2063. try {
  2064. $data = array_merge($old_sale, [
  2065. 'id' => null,
  2066. "orderCode" => $orderCode,
  2067. "good_code" => $spuCode,
  2068. "skuCode" => $skuCode,
  2069. // "customer_code" => $info['customer_code'],
  2070. // "good_name" => (isset($goodinfo['good_name']) && $goodinfo['good_name'] !== '') ? $goodinfo['good_name'] : '',
  2071. "good_num" => $good_num,
  2072. // "cat_id" => $goodinfo['cat_id'],
  2073. "apply_id" => $rm,
  2074. "apply_name" => $ri,
  2075. "origin_price" => $origin_price,
  2076. // "sale_price" => $old_sale['sale_price'],//取原价格
  2077. // "total_price" => $sale_price,//取原总价
  2078. // "post_fee" => 0,
  2079. // "status" => 0,
  2080. "th_num" => 0,
  2081. "th_fee" => 0,//退货金额为0
  2082. "send_num" => 0,
  2083. "wsend_num" => $good_num,
  2084. // "send_status" => 0,
  2085. // "good_type" => $goodtype,
  2086. // "send_type" => $old_sale['send_type'],
  2087. // "supplierNo" => $supplierNo,
  2088. // "is_del" => 0,
  2089. // "zxNo" => "",
  2090. // "platform_order" => $old_sale['platform_order'],
  2091. // "platform_id" => $old_sale['platform_id'],
  2092. "remark" => $old_sale['orderCode'],
  2093. // "is_stock" => $is_stock,
  2094. "is_activity" => $is_activity,
  2095. "activity_code" => $actcode,
  2096. // "order_type" => $is_stock == 1 ? 1 : 2,
  2097. "order_source" => 6,//6售后补换货
  2098. // "poNo"=>$poNo,
  2099. // 'good_weight' => $ct['noble_weight'],
  2100. // 'gold_price' => isset($ct['cgd_gold_price']) ? $ct['cgd_gold_price'] : 0,
  2101. // 'cost_price' => isset($good['cost_fee']) ? $good['cost_fee'] : 0,
  2102. // 'diff_weight' => 0,
  2103. // 'diff_fee' => 0,
  2104. // "workNo" => '',
  2105. 'status' => 0,
  2106. "addtime" => date("Y-m-d H:i:s"),
  2107. "updatetime" => date("Y-m-d H:i:s"),
  2108. // 'total_price' => round($sale_price * $good_num, 2),
  2109. // 'proof_id' => $old_sale['proof_id'],
  2110. // 'paytime' => $old_sale['paytime'],
  2111. 'returnCode' => $info['returnCode'],
  2112. 'cgderid' => $supplier_temp_info['personid'],
  2113. 'cgder' => $supplier_temp_info['person'],//采购员(供应商负责人)
  2114. 'good_createrid' => $goodinfo['createrid'],
  2115. 'good_creater' => $goodinfo['creater'],//商品创建人
  2116. ]);
  2117. $datainfo = Db::name('sale')->insertGetId($data);
  2118. if ($datainfo > 0) {
  2119. //修改状态,添加待办
  2120. ActionLog::logAdd($token, [
  2121. "order_code" => $orderCode,//销售单code
  2122. "status" => 0,//这里的status是之前的值
  2123. "action_remark" => '',//备注
  2124. "action_type" => "create"//新建create,编辑edit,更改状态status
  2125. ], "XSQRD", 0, $this->post);
  2126. ProcessOrder::AddProcess($token, [
  2127. "order_type" => 'XSQRD',
  2128. "order_code" => $orderCode,//销售单code
  2129. "order_id" => $datainfo,
  2130. "order_status" => 0,
  2131. "before_status" => 0,
  2132. 'holder_id' => $data['apply_id']
  2133. ]);
  2134. if ($is_activity == 1) {
  2135. $actup = [
  2136. "activity_stock" => $act['activity_stock'] - $good_num,
  2137. "updatetime" => date("Y-m-d H:i:s")
  2138. ];
  2139. $actupp = Db::name("activity_info")
  2140. ->where(["skuCode" => $skuCode, "activity_code" => $actcode, "is_del" => 0, "status" => 1])
  2141. ->save($actup);
  2142. if ($actupp == false) throw new Exception('活动库存修改失败');
  2143. }
  2144. $outstatus = 0;
  2145. $standing_book_da = ['sale_id' => $datainfo, 'customer_code' => $old_sale['customer_code'], 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
  2146. if ($is_stock == 0) $this->createCgd($cgd, $standing_book_da);
  2147. else {
  2148. $outstatus = 1;
  2149. $stockid= Db::name("good_stock")->alias("a")
  2150. ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
  2151. ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
  2152. ->column('a.id');
  2153. $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,$good_num);
  2154. if($stockinfo==false){
  2155. throw new Exception('库存商品更新库存失败');
  2156. }
  2157. // $bol = $this->RelaCgd([
  2158. // 'orderCode' => $orderCode,
  2159. // "good_num" => $good_num,
  2160. // "spuCode" => $spuCode,
  2161. // "companyNo" => $supplierNo,
  2162. // "cost_fee" => isset($goodinfo['cost_fee']) ? $goodinfo['cost_fee'] : 0,
  2163. // 'order_type' => $data['order_type'],
  2164. // 'order_source' => $data['order_source'],
  2165. // ], $standing_book_da);
  2166. // if (isset($stock)) {
  2167. //
  2168. // $stck = [
  2169. // "usable_stock" => $stock['usable_stock'] - $good_num,
  2170. // "wait_out_stock" => $stock['wait_out_stock'] + $good_num,
  2171. // "updatetime" => date("Y-m-d H:i:s")
  2172. // ];
  2173. //
  2174. // $upad = Db::name("good_stock")->where($stock)->update($stck);
  2175. // if ($upad == false) throw new Exception('库存商品更新库存失败');
  2176. // $stockinfo =GoodStockInfo::OrderBn($orderCode,$stock['id'],$good_num);
  2177. // if($stockinfo==false){
  2178. // throw new Exception('库存商品更新库存失败'); //库存不足
  2179. // }
  2180. // //商品变动日志表,good_log_code字段存储采购单号
  2181. // $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $stock['id'], "type" => 2, 'stock' => $good_num, "stock_name" => "usable_stock"];
  2182. // $good_data[] = ['good_log_code' => $orderCode, "stock_id" => $stock['id'], "type" => 1, 'stock' => $good_num, "stock_name" => "wait_out_stock"];
  2183. // GoodLog::LogAdd($token, $good_data, "XSQRD");
  2184. // }
  2185. }
  2186. // $old_out = Db::name('order_out')
  2187. // ->field('id,addrid,wsm_code')
  2188. // ->where(['orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])
  2189. // ->find();
  2190. $old_out_addr_info = Db::name('order_out')
  2191. ->alias('oo')
  2192. ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
  2193. ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
  2194. ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
  2195. ->find();
  2196. if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
  2197. $temp = [
  2198. 'orderCode' => $orderCode,
  2199. 'addr' => $old_out_addr_info['addr'],
  2200. 'addr_code' => $old_out_addr_info['addr_code'],
  2201. 'contactor' => $old_out_addr_info['contactor'],
  2202. 'mobile' => $old_out_addr_info['mobile'],
  2203. 'customer_code' => $old_out_addr_info['customer_code'],
  2204. 'receipt_quantity' => $good_num,
  2205. 'arrive_time' => $old_out_addr_info['arrive_time'],
  2206. 'addtime' => date("Y-m-d H:i:s"),
  2207. 'updatetime' => date("Y-m-d H:i:s"),
  2208. // ''=>'',
  2209. ];
  2210. $addrid = Db::name('order_addr')->insertGetId($temp);
  2211. $outCode = makeNo("DF");
  2212. $out = array_merge($old_out, [
  2213. 'id' => null,
  2214. "orderCode" => $orderCode,
  2215. "outCode" => $outCode,
  2216. "apply_id" => $rm,
  2217. "apply_name" => $ri,
  2218. "addrid" => $addrid,
  2219. "post_name" => "",
  2220. "post_code" => "",
  2221. "post_fee" => 0,
  2222. "sendtime" => date("Y-m-d H:i:s"),
  2223. "send_num" => $good_num,
  2224. "check_num" => 0,
  2225. "error_num" => 0,
  2226. "wsm_code" => isset($old_out['wsm_code']) ? $old_out['wsm_code'] : '',
  2227. "order_type" => $is_stock == 1 ? 1 : 2,
  2228. "status" => $outstatus,
  2229. "addtime" => date("Y-m-d H:i:s"),
  2230. "updatetime" => date("Y-m-d H:i:s")
  2231. ]);
  2232. Db::name("order_out")->insert($out);
  2233. $standing_book_da['outCode'] = $outCode;
  2234. if($is_stock==0){
  2235. $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
  2236. if (empty($order)) throw new Exception('采购单关联数据未找到');
  2237. $order['send_num'] += $good_num;
  2238. $order['wsend_num'] -= $good_num;
  2239. if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
  2240. $ups = Db::name("order_num")->save($order);
  2241. if ($ups) {
  2242. $sen = Db::name("order_send")->save([
  2243. "cgdNo" => $order['cgdNo'],
  2244. "outCode" => $outCode,
  2245. "send_num" => $good_num,
  2246. "status" => 1,
  2247. "addtime" => date("Y-m-d H:i:s"),
  2248. "updatetime" => date("Y-m-d H:i:s")
  2249. ]);
  2250. if ($sen == false) throw new Exception('发货地址添加创建失败');
  2251. }
  2252. }
  2253. if (!isset($standing_book_da['returnCode'])) $standing_book_da['returnCode'] = '';
  2254. if (!isset($standing_book_da['thNo'])) $standing_book_da['thNo'] = '';
  2255. if (!isset($standing_book_da['returnGoodCode'])) $standing_book_da['returnGoodCode'] = '';
  2256. if (!isset($standing_book_da['wsm_in_code'])) $standing_book_da['wsm_in_code'] = '';
  2257. if (!isset($standing_book_da['cgdReturnCode'])) $standing_book_da['cgdReturnCode'] = '';
  2258. //处理台账
  2259. Db::name('standing_book')->insert(array_merge($standing_book_da, ['addtime' => date('Y-m-d H:i:s'), 'updatetime' => date('Y-m-d H:i:s'), 'standBookNo' => makeNo('IO')]));
  2260. //维护售后申请单
  2261. Db::name('order_return')
  2262. ->where(['id' => $orid, 'is_reissue' => 0])
  2263. ->update([
  2264. 'is_reissue' => 1,
  2265. 'newOrderCode' => $orderCode,
  2266. 'updatetime' => date('Y-m-d H:i:s')
  2267. ]);
  2268. Db::commit();
  2269. return error_show(0, "操作成功");
  2270. } else throw new Exception('咨询订单创建失败');
  2271. } catch (\Exception $e) {
  2272. Db::rollback();
  2273. return error_show(1005, $e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
  2274. }
  2275. }
  2276. //创建采购单
  2277. public function RelaCgd($outinfo,array &$standing_book_da=[]){
  2278. $cgd = Db::name("order_bk")->where([["spuCode","=",$outinfo['spuCode']],["is_del","=",0],["balance_num",">=",$outinfo['good_num']],['companyNo',"=",$outinfo['companyNo']]])->lock(true)->find();
  2279. if($cgd==false) throw new Exception('未查询到备库单信息');
  2280. $good=Db::name("good")
  2281. ->where(["spuCode"=>$outinfo['spuCode'],"is_del"=>0])
  2282. ->find();
  2283. if($good==false) throw new Exception('未查询到商品信息');
  2284. $cgdinfo =Db::name("purchease_order")
  2285. ->where(['cgdNo'=>$cgd['cgdNo'],"is_del"=>0])
  2286. ->find();
  2287. if($cgdinfo==false) throw new Exception('未查询到采购单信息');
  2288. //判断该供应商是否开通了供应商账号
  2289. $from_tag=checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
  2290. $QrdCgd=[
  2291. "cgdNo"=>makeNo("CG"),
  2292. "bkcode" => $cgdinfo['bkcode'],
  2293. 'wsm_code'=>$cgdinfo['wsm_code'],
  2294. "cgder_id"=>$cgdinfo['cgder_id'],
  2295. "cgder"=>$cgdinfo['cgder'],
  2296. "spuCode"=>$cgdinfo['spuCode'],
  2297. "good_name"=>$cgdinfo['good_name'],
  2298. "good_num"=>$outinfo['good_num'],
  2299. "good_price"=>$cgdinfo['good_price'],
  2300. "total_fee"=>round($cgdinfo['good_price']*$outinfo['good_num'],2),
  2301. "pakge_fee"=>$cgdinfo['pakge_fee'],
  2302. "cert_fee"=>$cgdinfo['cert_fee'],
  2303. "open_fee"=>$cgdinfo['open_fee'],
  2304. "delivery_fee"=>$cgdinfo['delivery_fee'],
  2305. "mark_fee"=>$cgdinfo['mark_fee'],
  2306. "teach_fee"=>$cgdinfo['teach_fee'],
  2307. "nake_fee"=>$cgdinfo['nake_fee'],
  2308. "demo_fee"=>$cgdinfo['demo_fee'],
  2309. "weight"=>$cgdinfo['weight'],
  2310. "diff_weight"=>$cgdinfo['diff_weight'],
  2311. "diff_fee"=>$cgdinfo['diff_fee'],
  2312. "gold_price"=>$cgdinfo['gold_price'],
  2313. "supplierNo"=>$cgdinfo['supplierNo'],
  2314. "supplier_name"=>$cgdinfo['supplier_name'],
  2315. "companyNo"=>$cgdinfo['companyNo'],
  2316. "send_status"=>3,
  2317. "send_num"=>$outinfo['good_num'],
  2318. "wsend_num"=>0,
  2319. "remark"=>$cgdinfo['remark'],
  2320. "status"=>3,
  2321. "lasttime"=>$cgdinfo['lasttime'],
  2322. "is_del"=>0,
  2323. "order_type"=>$outinfo['order_type'],
  2324. "order_source"=>$outinfo['order_source'],
  2325. "good_type"=>$cgdinfo['good_type'],
  2326. "addtime"=>date("Y-m-d H:i:s"),
  2327. "updatetime"=>date("Y-m-d H:i:s"),
  2328. 'good_createrid' => $good['createrid'],
  2329. 'good_creater' => $good['creater'],//商品创建人
  2330. 'from_tag' => isset($from_tag[$cgdinfo['supplierNo']]) ? 2 : 1,//来源标签:1采销(默认),2供应商端
  2331. ];
  2332. $insetrCgd=Db::name("purchease_order")->insert($QrdCgd);
  2333. if($insetrCgd==false) throw new Exception('新增采购单失败');
  2334. else{
  2335. $standing_book_da = array_merge($standing_book_da, [
  2336. 'orderCode' => $outinfo['orderCode'],
  2337. 'cgdNo' => $cgdinfo['cgdNo'],
  2338. 'spuCode' => $outinfo['spuCode'],
  2339. 'order_type' => $QrdCgd['order_type'],
  2340. 'order_source' => $QrdCgd['order_source'],
  2341. 'supplierNo' => $cgdinfo['supplierNo'],
  2342. 'companyNo' => $cgdinfo['companyNo'],
  2343. 'bk_code' => $cgdinfo['bkcode'],
  2344. 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id',0),
  2345. ]);
  2346. }
  2347. if($good['is_gold_price']==1 && $good['is_stock']==1){
  2348. $gold = Db::name("gold_price1")
  2349. ->field('id,price')
  2350. ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
  2351. ->order("addtime desc")
  2352. ->find();
  2353. $ct['cgd_gold_price']=$gold["price"];
  2354. $updat=[
  2355. "sale_price"=>0,
  2356. "total_price"=>0,
  2357. "origin_price"=>$cgdinfo['good_price'],
  2358. "gold_price"=>$gold["price"],
  2359. ];
  2360. Db::name("sale")->where(["orderCode"=>$outinfo['orderCode']])->update($updat);
  2361. // if($upsale==false){
  2362. // return false;
  2363. // }
  2364. }
  2365. $merge_num = Db::name("purchease_order")
  2366. ->where(["bkcode"=>$cgdinfo['bkcode'],"order_type"=>1,"is_del"=>0])
  2367. ->where("order_source","<>",0)
  2368. ->field("sum(send_num)-sum(th_num) as num")
  2369. ->find();
  2370. $cgd['balance_num']=$cgd['total_num']-$merge_num['num'];
  2371. $cgd['merge_num']=$merge_num['num'];
  2372. $cgd['updatetime']=date("Y-m-d H:i:s");
  2373. $up=Db::name("order_bk")->save($cgd);
  2374. if($up==false) throw new Exception('修改备库单失败');
  2375. $data=[
  2376. "orderCode"=>$outinfo['orderCode'],
  2377. "cgdNo"=>$QrdCgd['cgdNo'],
  2378. "spuCode"=>$outinfo['spuCode'],
  2379. "companyNo"=>$outinfo['companyNo'],
  2380. "good_num"=>$outinfo['good_num'],
  2381. "wsend_num"=>$outinfo['good_num'],
  2382. "send_num"=>0,
  2383. "wait_num"=>$outinfo['good_num'],
  2384. "status"=>1,
  2385. "source"=>1,
  2386. ];
  2387. $order =Db::name("order_num")->save($data);
  2388. if($order==false) throw new Exception('修改采购单销售单关联失败');
  2389. }
  2390. //导出
  2391. public function export()
  2392. {
  2393. $param = $this->request->only([
  2394. 'returnCode',
  2395. 'outCode' => '',
  2396. 'status' => '',
  2397. 'order_type' => '',
  2398. 'orderCode' => '',
  2399. 'good_code' => '',
  2400. 'good_name' => '',
  2401. 'except_code' => '',
  2402. 'apply_name' => '',
  2403. 'start' => '',
  2404. 'end' => '',
  2405. 'company_name' => '',//部门名称
  2406. 'supplierNo' => '',
  2407. 'customer_code' => '',
  2408. 'companyNo' => '',
  2409. 'order_source' => '',
  2410. ], 'post', 'trim');
  2411. $val = Validate::rule(['returnCode' => 'require|array|max:10']);
  2412. if ($val->check($param) == false) return json_show(1004, $val->getError());
  2413. $where = [['a.is_del', "=", 0], ['a.returnCode', 'in', $param['returnCode']]];
  2414. // if ($param['relaComNo'] !== '') $where[] = ['a.supplierNo', "=", $param['relaComNo']];
  2415. if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
  2416. if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
  2417. if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
  2418. if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
  2419. if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
  2420. if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
  2421. if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
  2422. if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
  2423. if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
  2424. if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
  2425. if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
  2426. if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
  2427. if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
  2428. if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
  2429. if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
  2430. if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
  2431. //只有level2的账号过滤数据权限
  2432. if ($this->level == 2) {
  2433. $hand = resign_hand_user($this->uid, 0);
  2434. $role = $this->checkDataShare();
  2435. if (!empty($role[DataGroupModel::$type_全部])) {
  2436. $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  2437. $condition[] = ["a.person_id", "in", $hand];
  2438. $condition[] = ["a.apply_id", "in", $arr];
  2439. $condition[] = ["a.cgderid", "in", $hand];
  2440. $code = Db::connect('mysql_sys')
  2441. ->name('supplier')
  2442. ->where(['is_del' => 0, 'personid' => $this->uid])
  2443. ->column('code');
  2444. if($code) $condition[] = ["a.supplierNo", "in", $code];
  2445. }
  2446. }
  2447. //level3账号不允许看到库存品订单
  2448. if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
  2449. // $condition .="a.cgderid in {$hand} or a.person_id in {$hand} or a.apply_id in ("
  2450. // .implode(',',$role[DataGroupModel::$type_全部]).")";
  2451. $list = Db::name('order_return')
  2452. ->field('
  2453. a.returnCode 售后申请单编码,
  2454. a.order_type 订单类型,
  2455. a.apply_name 申请人,
  2456. a.cgder 采购员,
  2457. a.person 采购负责人,
  2458. a.outCode 发货单号,
  2459. a.is_receive 是否收到货,
  2460. a.total_num 总数量,
  2461. a.error_num 异常数量,
  2462. a.error_msg 异常原因,
  2463. a.error_remark 异常备注,
  2464. a.except_code 客户意愿,
  2465. a.orderCode 订单编号,
  2466. a.good_code 商品编号,
  2467. a.good_name 商品名称,
  2468. a.customer_code 客户编码,
  2469. a.customer_name 客户名称,
  2470. a.is_post 是否承担物流费用,
  2471. a.is_th 供应商是否退货,
  2472. a.return_tag 退回何处,
  2473. a.status 状态,
  2474. a.remark 审核备注,
  2475. a.addtime 创建时间,
  2476. a.updatetime 更新时间,
  2477. a.is_reissue 是否完成补发货,
  2478. a.newOrderCode 售后完成后新的销售订单号,
  2479. a.loop_total 状态从业务公司修改待供应商确认到待采购审核的循环次数,
  2480. b.return_wsm 退回仓库,
  2481. b.contactor 仓库联系人,
  2482. b.mobile 联系方式,
  2483. b.addr 地址,
  2484. b.addr_code,
  2485. b.post_code 快递单号,
  2486. b.post_company 快递公司,
  2487. b.post_fee 快递费用,
  2488. b.gys_remark 供应商备注,
  2489. a.supplierNo 供应商编码,
  2490. a.supplierName 供应商名称,
  2491. a.companyNo 业务公司编码,
  2492. a.companyName 业务公司名称')
  2493. ->alias('a')
  2494. ->where($where)
  2495. ->where(function ($query) use ($condition) {
  2496. $query->whereOr($condition);
  2497. })
  2498. ->leftJoin('order_returninfo b', 'b.returnCode=a.returnCode')
  2499. ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
  2500. ->select()
  2501. ->toArray();
  2502. $order_type = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞', 6 => '售后补换货', 7 => '报备转单', 8 => '支付渠道'];
  2503. $is_receive = [0 => '否', 1 => '是'];
  2504. $except_code = [0 => [1 => '退货', 2 => '补发'], 1 => [1 => '退货', 2 => '换货'],];//期望意愿
  2505. $return_tag = [1 => '供应商', 2 => '业务企业'];
  2506. $status = [1 => '待业务审核', 2 => '待采购审核', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 8 => '申请已取消', 9 => '供应商审核', 10 => '业务公司修改待供应商确认'];
  2507. foreach ($list as &$value) {
  2508. $value['订单类型'] = $order_type[$value['订单类型']] ?? '';
  2509. $value['客户意愿'] = $except_code[$value['是否收到货']][$value['客户意愿']] ?? '';
  2510. $value['是否收到货'] = $is_receive[$value['是否收到货']] ?? '';
  2511. $value['是否承担物流费用'] = $is_receive[$value['是否承担物流费用']] ?? '';
  2512. $value['供应商是否退货'] = $is_receive[$value['供应商是否退货']] ?? '';
  2513. $value['退回何处'] = $return_tag[$value['退回何处']] ?? '';
  2514. $value['状态'] = $status[$value['状态']] ?? '';
  2515. $value['是否完成补发货'] = $is_receive[$value['是否完成补发货']] ?? '';
  2516. $addr_code = explode(',', $value['addr_code']);
  2517. $value['地址'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]])) . $value['地址'];
  2518. unset($value['addr_code']);
  2519. }
  2520. if (empty($list)) $list[] = ['没有相关可导出的数据'];
  2521. excelSave('售后申请单' . date('YmdHis'), array_keys($list[0]), $list);
  2522. }
  2523. }