1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\ActionLog;
- use app\admin\model\DataGroup as DataGroupModel;
- use app\admin\model\GoodLog;
- use app\admin\model\GoodStockInfo;
- use app\admin\model\ProcessOrder;
- use think\App;
- use think\Exception;
- use think\facade\Db;
- use think\facade\Validate;
- class After extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
-
- public function create()
- {
- $param = $this->request->only(['outCode', 'errorCode', 'remark' => '', 'is_receive', 'num', 'except_code' => '', 'img'], 'post', 'trim');
- $val = Validate::rule([
- 'outCode' => 'require',
- 'errorCode' => 'require',
- 'is_receive' => 'require|in:0,1',
- 'num' => 'requireIf:is_receive,1',
- 'except_code' => 'require',
- 'img' => 'require',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $orderout = Db::name("order_out")
- ->field('id,orderCode,wsm_code,send_num,order_type')
- ->where(["outCode" => $param['outCode'], 'is_del' => 0])
- ->findOrEmpty();
- if (empty($orderout)) return error_show(1005, "未找到发货单数据");
- $after_num = Db::name("order_return")
- ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode']])
- ->where("status", "not in", [5, 6, 8])
- ->sum("error_num");
- $th_num = Db::name("order_back")
- ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
- ->where("status", "<", 4)
- ->sum("return_num");
- if ($th_num != 0 || $after_num != 0) return error_show(1005, "存在售后或售后退货未结束流程");
- $oder = Db::name("sale")
- ->where(["orderCode" => $orderout['orderCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($oder)) return error_show(1005, "未找到订单数据");
- if ($oder['order_type'] != 1) {
- $wsm = Db::name("warehouse_info")
- ->where(["wsm_code" => $orderout['wsm_code']])
- ->findOrEmpty();
- if (empty($wsm)) return error_show(1005, "未找到仓库数据");
- }
- if ($oder['order_type'] == 3||$oder['order_type'] == 4) {
- $goon = Db::name("good_zixun")
- ->where(["spuCode" => $oder['good_code'], "is_del" => 0])
- ->findOrEmpty();
- } else {
- $goon = Db::name('good_platform')
- ->alias('a')
- ->field("b.creater,b.createrid,b.supplierNo,b.supplierName")
- ->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $oder['skuCode']])
- ->findOrEmpty();
- }
- $error = Db::name('result_info')
- ->where(["result_code" => $param['errorCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($error)) return error_show(1005, "未找到退货原因数据");
- $userCommon = \app\admin\common\User::getIns();
- $supplier = $userCommon->handle('sInfo', ['code' => $goon['supplierNo']]);
- $supplier = $supplier['data'];
- $num = $param['is_receive'] == 1 ? $param['num'] : $orderout['send_num'];
- $thnum = Db::name("order_back")
- ->where(["orderCode" => $orderout['orderCode'], "outCode" => $param['outCode'], "is_del" => 0])
- ->where("status", "=", 4)
- ->sum("return_num");
- if ($num > ($orderout['send_num'] - $thnum)) return error_show(1004, "可用售后数量不足");
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$orderout['orderCode']]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- return json_show(1005, $fininfo['message']??"结算校验失败");
- }
- $rm = $this->uid;
- $ri = $this->uname;
- $returnCode = makeNo("RS");
- Db::startTrans();
- try {
- $in = [
- "returnCode" => $returnCode,
- "outCode" => $param['outCode'],
- "orderCode" => $oder['orderCode'],
- "good_code" => $oder['good_code'],
- "good_name" => $oder['good_name'],
- "customer_code" => $oder['customer_code'],
- "customer_name" =>$oder['customerName'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- 'supplierNo' => $goon['supplierNo'],
- 'supplierName' => $goon['supplierName'],
- "cgder" => $wsm['contactor_name'] ?? '',
- "cgderid" => $wsm['contactor'] ?? 0,
- "person" => $supplier['person'] ?? '',
- "person_id" => $supplier['personid'] ?? 0,
- 'total_num' => $orderout['send_num'],
- "error_code" => $param['errorCode'],
- "error_num" => $num,
- "error_img" => is_array($param['img']) ? implode(',', $param['img']) : $param['img'],
- "error_msg" => $error['result'],
- "error_remark" => $param['remark'],
- "is_receive" => $param['is_receive'],
- "remark" => '',
- "except_code" => $param['except_code'],
- "order_type" => $orderout['order_type'],
- 'companyNo' => $oder['supplierNo'],
- 'companyName' => $oder['supplierName'],
- "status" => 1,
- "is_del" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- $create = Db::name("order_return")->insert($in, true);
- $orde = ["order_code" => $returnCode, "status" => $in['status'], "action_remark" => '', "action_type" => "create"];
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, 'SHD', 1, $orde);
- if ($create > 0) {
-
- 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`)");
-
-
- $process = ["order_code" => $returnCode, "order_id" => $create, "order_status" => $in['status'], "order_type" => 'SHD', "before_status" => 0, 'holder_id' => $in['apply_id']];
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], $process);
- Db::commit();
- return json_show(0, "售后申请单新建成功", ["returnCode" => $returnCode]);
- }
- Db::rollback();
- return error_show(1005, "售后申请单新建失败");
- } catch (Exception $exception) {
- Db::rollback();
- return json_show(1005, $exception->getMessage());
- }
- }
-
- public function list()
- {
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 10,
- 'relaComNo' => '',
- 'returnCode' => '',
- 'outCode' => '',
- 'status' => '',
- 'order_type' => '',
- 'orderCode' => '',
- 'good_code' => '',
- 'good_name' => '',
- 'except_code' => '',
- 'apply_name' => '',
- 'start' => '',
- 'end' => '',
- 'company_name' => '',
- 'supplierNo' => '',
- 'customer_code' => '',
- 'companyNo' => '',
- 'order_source' => '',
- 'use_type' => '',
- ], 'post', 'trim');
- $where = [['a.is_del', "=", 0]];
- if ($param['relaComNo'] !== '') $where[] = ['c.supplierNo', "=", $param['relaComNo']];
- if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
- if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
- if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
- if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
- if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
- if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
- if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
- if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
- if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
- if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
- if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
- if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
- if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
- if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
- if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- if ($param['use_type'] !== '') $where[] = ['p.use_type', '=', $param['use_type']];
- $condition = [];
-
- if ($this->level == 2) {
- $hand = resign_hand_user($this->uid, 0);
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $condition[] = ["a.person_id", "in", $hand];
- $condition[] = ["a.apply_id", "in", $arr];
- $condition[] = ["a.cgderid", "in", $hand];
-
- $supplierNos = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $arr])
- ->column('code');
- $where[] = ["a.supplierNo", "in", $supplierNos];
- }
- }
-
- if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
- if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
- $count = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->count('a.id');
- $list = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->leftJoin('platform p', 'p.id=c.platform_id AND p.is_del=0')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->field("a.*,b.return_wsm,b.contactor,b.mobile,b.addr,b.addr_code,b.post_code,b.post_company,b.post_fee,b.gys_remark,c.order_source,p.use_type")
- ->page($param['page'], $param['size'])
- ->order("a.addtime desc")
- ->select()
- ->toArray();
-
- $all_createrid = array_column($list, 'apply_id');
- $item = get_company_name_by_uid($all_createrid);
-
- $codes = array_unique(array_column($list,'supplierNo'));
- if($codes){
- $tmp=\app\admin\common\User::getIns()->handle('sGetList',['more_code'=>$codes,'size'=>count($codes)]);
- $person = array_column($tmp['data']['list'],'person','code');
- $personid = array_column($tmp['data']['list'],'personid','code');
- }
-
-
- $supp_account = checkHasAccountBySupplierNos(array_unique(array_column($list,'supplierNo')));
- $data = [];
- foreach ($list as $value) {
- $value['company_name'] = $item[$value['apply_id']] ?? '';
- $value['has_account'] = (int)isset($supp_account[$value['supplierNo']]);
- $value['person'] = $person[$value['supplierNo']]??0;
- $value['person_id'] = $personid[$value['supplierNo']]??0;
-
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, "count" => $count]);
- }
-
- public function info()
- {
- $bkcode = $this->request->post('returnCode', '', 'trim');
- if ($bkcode == "") return error_show(1005, "参数returnCode 不能为空");
- $info = Db::name("order_return")
- ->alias("a")
- ->leftJoin("order_returninfo b", "a.returnCode=b.returnCode")
- ->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")
- ->where(['a.returnCode' => $bkcode])
- ->findOrEmpty();
- if (empty($info)) return error_show(1005, "未找到售后数据");
- $orderinfo = Db::name("sale")->where(["orderCode" => $info["orderCode"]])->findOrEmpty();
- $info['origin_price'] = $orderinfo['origin_price'];
- $info['order_type'] = $orderinfo['order_type'];
- $info['order_source'] = $orderinfo['order_source'];
- $info['is_stock'] = $orderinfo['is_stock'];
- $info['sale_price'] = $orderinfo['sale_price'];
- $info['total_price'] = sprintf("%1\$.2f", $orderinfo['sale_price'] * $info['error_num']);
- if ($orderinfo['order_type'] == 3 || $orderinfo['order_type'] == 4) {
- $goon = Db::name("good_zixun")
- ->field('cat_id,supplierNo')
- ->where(["spuCode" => $orderinfo['good_code'], "is_del" => 0])
- ->findOrEmpty();
- } else {
- $goon = Db::name('good_platform')
- ->alias('a')
- ->field('b.cat_id,b.supplierNo')
- ->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $orderinfo['skuCode']])
- ->findOrEmpty();
- }
- if (empty($goon)) return error_show(1003, "未找到商品数据");
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $info['can'] = $int;
- $addcode = '';
- if ($info['addr_code'] != "") {
- $temp=json_decode($info['addr_code'],true);
- if($temp) $addcode = $info['addr_code'];
- else {
- $temp = explode(',',$info['addr_code']);
- $addcode = json_encode(["provice_code" => $temp[0], "city_code" => $temp[1], "area_code" => $temp[2]]);
- }
- }
- $info["addr_cn"] = GetAddr($addcode);
-
- $out = Db::name("order_out")->where(["outCode" => $info['outCode'], "is_del" => 0])->find();
- $info['out_num'] = isset($out['send_num']) ? $out['send_num'] : '';
- $wsmcode = [];
- $info['wsm_supplier'] = '';
- if ($info['return_wsm'] != '') {
- $wsmcode = Db::name("warehouse_info")
- ->alias("a")
- ->where(["a.wsm_code" => $info['return_wsm']])
- ->find();
- }
- if ($info['return_wsm'] != '') {
- $info['wsm_supplierNo'] = $wsmcode['supplierNo'] ?? "";
- $info['wsm_supplier'] = $wsmcode['supplierName'];
- $info['wsm_customer_name'] = $wsmcode['companyName'];
- $info['wsm_customer_code'] = $wsmcode['companyNo'] ?? "";
- $info['wsm_code'] = isset($wsmcode['wsm_code']) ? $wsmcode['wsm_code'] : "";
- $info['wsm_name'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- }
-
- isset($wsmcode['contactor_name']) ? $info['contactor'] = $wsmcode['contactor_name'] : '';
- isset($wsmcode['mobile']) ? $info['mobile'] = $wsmcode['mobile'] : '';
- isset($wsmcode['addrs_code']) ? $info['addr_code'] = $wsmcode['addrs_code'] : '';
- isset($wsmcode['addr']) ? $info['addr'] = $wsmcode['addr'] : '';
- $info['spuCode'] = $orderinfo['good_code'];
- $info['skuCode'] = $orderinfo['skuCode'];
- $info['return_tag'] = $info['return_tag'] == 0 ? "" : $info['return_tag'];
- $info['is_th'] = $info['is_th'] == 0 ? "" : $info['is_th'];
-
- $supp_account = checkHasAccountBySupplierNos([$info['supplierNo']]);
- $info['has_account']=(int)isset($supp_account[$info['supplierNo']]);
- return app_show(0, "获取成功", $info);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public function status()
- {
- try {
- $param = $this->request->only([
- 'returnCode',
- 'status',
- 'remark' => '',
- 'wsm_code' => '',
- 'contactor' => '',
- 'mobile' => '',
- 'addr_code' => '',
- 'addr' => '',
- ], 'post', 'trim');
- $val = Validate::rule([
- 'returnCode' => 'require',
- 'status' => 'require|number|in:1,2,4,5,6,9,10,11',
- 'remark' => 'requireIf:status,6|requireIf:status,10',
- ]);
- if ($val->check($param) == false) throw new Exception($val->getError());
- $info = Db::name("order_return")
- ->where(['is_del' => 0, 'returnCode' => $param['returnCode']])
- ->findOrEmpty();
- if (empty($info)) throw new Exception('未找到售后数据');
- if ($info['status'] == 6) throw new Exception('业务已驳回,无法操作');
- if ($info['status'] == 5) throw new Exception('售后已完成,无法操作');
- if ($info['status'] == 8) throw new Exception('申请已取消,无法操作');
- switch ($info['status']) {
- case 1:
- if (in_array($param['status'], [6, 2, 9]) == false) throw new Exception('选项错误');
- if ($info['order_type'] == 1 && $param['status'] != 2) throw new Exception('选项错误');
- break;
- case 9:
- if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');
- if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
- if ($param['status'] == 4) {
- if ($param['contactor'] == '') throw new Exception('收货人不能为空');
- if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
- if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
- if ($param['addr'] == '') throw new Exception('退货地址不能为空');
- }
- break;
- case 2:
- if ((($info['is_receive'] == 1) && (in_array($param['status'], [10, 11]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [10, 5]) == false)))) throw new Exception('选项错误');
- if ($info['order_type'] == 1 && $param['status'] != 11) throw new Exception('选项错误');
- break;
- case 10:
- if ((($info['is_receive'] == 1) && (in_array($param['status'], [2, 4]) == false) || (($info['is_receive'] == 0) && (in_array($param['status'], [2, 5]) == false)))) throw new Exception('选项错误');
- if ($param['status'] == 2 && $param['remark'] == '') throw new Exception('remark不能为空');
- if ($param['status'] == 4) {
- if ($param['contactor'] == '') throw new Exception('收货人不能为空');
- if ($param['mobile'] == '') throw new Exception('联系电话不能为空');
- if ($param['addr_code'] == '') throw new Exception('省市区编码不能为空');
- if ($param['addr'] == '') throw new Exception('退货地址不能为空');
- }
- break;
- }
-
- $s_info = \app\admin\common\User::getIns()->handle('sInfo', ['code' => $info['supplierNo']]);
- $info['person_id'] = $s_info['data']['personid'];
- $info['person'] = $s_info['data']['person'];
-
- if (in_array($info['status'], [9, 10]) && ($this->level == 2) && ($this->uid != $info['person_id'])) return json_show(1004, '您不是供应商负责人,此时无权操作');
- if ($param['remark'] != '') $info['remark'] = $param['remark'];
- Db::startTrans();
- try {
- $date = date('Y-m-d H:i:s');
- $action_log_user = ['id' => $this->uid, 'nickname' => $this->uname];
-
- if ($param['status'] == 10) $info['loop_total'] += 1;
-
- if ($info['status'] == 2 && $param['status'] == 11) {
- $info['return_tag'] = 2;
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode']]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- throw new Exception($fininfo['message']??"结算校验失败");
- }
-
- $wsm = Db::name('warehouse_info')->where(['is_del' => 0, 'wsm_code' => $param['wsm_code']])->findOrEmpty();
- if (empty($wsm)) throw new Exception('返回仓库不存在');
- if ($wsm['wsm_type'] != 4) throw new Exception('不是次品仓');
- Db::name('order_returninfo')->insert([
- 'returnCode' => $param['returnCode'],
- 'return_wsm' => $param['wsm_code'],
- 'contactor' => $wsm['contactor_name'],
- 'mobile' => $wsm['mobile'],
- 'addr' => $wsm['addr'],
- 'addr_code' => $wsm['addrs_code'],
- 'post_code' => '',
- 'post_company' => '',
- 'post_fee' => 0,
- 'gys_remark' => '',
- 'addtime' => $date,
- ]);
- } else{
- $fininfo =GetFin("admin/orderischeck",["token"=>$this->post['token'],"orderCode"=>$info['orderCode'],"isCgd"=>1]);
- if(!isset($fininfo['code'])||$fininfo['code']!=0 ){
- throw new Exception($fininfo['message']??"结算校验失败");
- }
- $info['return_tag'] = 1;
- }
- $var = $info['status'];
- $info['status'] = $param['status'];
- $info['updatetime'] = $date;
- $up = Db::name("order_return")->save($info);
- if ($up) {
-
- if ($param['status'] == 5 && $info['is_receive'] == 0) {
- $orde = Db::name("order_out")
- ->field('id,outCode,status')
- ->where(["outCode" => $info['outCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($orde)) throw new Exception('未找到出库单数据');
- $sale = Db::name("sale")
- ->field('id,th_num,th_fee,sale_price,good_code,good_name,cat_id')
- ->where(['is_del' => 0, "orderCode" => $info['orderCode']])
- ->findOrEmpty();
- if (empty($sale)) throw new Exception('未找到销售单数据');
- $od_status = $orde['status'];
- $orde['status'] = 4;
- $orde['updatetime'] = $date;
- $out = Db::name("order_out")->save($orde);
- if ($out == false) throw new Exception("发货单更新失败");
- $order = ["order_code" => $orde['outCode'], "status" => $od_status, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd($action_log_user, $order, "CKD", $orde['status'], $this->post);
- $process = ["order_code" => $orde['outCode'], "order_id" => $orde['id'], "order_status" => $orde['status'], "order_type" => "CKD", "before_status" => $od_status];
- ProcessOrder::AddProcess($action_log_user, $process);
- $sale['th_num'] += $info['error_num'];
- $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
- $sale['updatetime'] = $date;
- $sup = Db::name("sale")->save($sale);
- if ($sup == false) throw new Exception("销售单更新失败");
- $data = [
- "orderCode" => $info['orderCode'],
- "th_type" => 2,
- "th_num" => $info['error_num'],
- "th_fee" => round($info['error_num'] * $sale['sale_price'], 2),
- "thCode" => $info['returnCode'],
- "spuCode" => $sale['good_code'],
- "good_name" => $sale['good_name'],
- "cat_id" => $sale['cat_id'],
- "apply_id" => $info['apply_id'],
- "apply_name" => $info['apply_name'],
- "addtime" => $date,
- "status" => 1,
- "is_del" => 0
- ];
- $inse = Db::name("th_data")->insert($data);
- if ($inse == false) throw new Exception('退回单更新失败');
- }
-
- if ($info['is_receive'] == 1 && $param['status'] == 4) {
- $tmp = Db::name('order_returninfo')
- ->field('id')
- ->where('returnCode', $param['returnCode'])
- ->findOrEmpty();
- if (empty($tmp)) {
-
- Db::name('order_returninfo')
- ->insert([
- 'returnCode' => $param['returnCode'],
- 'return_wsm' => $param['wsm_code'],
- 'contactor' => $param['contactor'],
- 'mobile' => $param['mobile'],
- 'addr' => $param['addr'],
- 'addr_code' => $param['addr_code'],
- 'addtime' => $date
- ]);
- } else {
- Db::name('order_returninfo')
- ->where('id', $tmp['id'])
- ->update([
- 'return_wsm' => $param['wsm_code'],
- 'contactor' => $param['contactor'],
- 'mobile' => $param['mobile'],
- 'addr' => $param['addr'],
- 'addr_code' => $param['addr_code'],
- ]);
- }
- }
- $order = ["order_code" => $info['returnCode'], "status" => $var, "action_remark" => '', "action_type" => "edit"];
- ActionLog::logAdd($action_log_user, $order, "SHD", $info['status'], $this->post);
- $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']];
- ProcessOrder::AddProcess($action_log_user, $process);
- Db::commit();
- return app_show(0, "更新成功");
- }
- throw new Exception('更新失败');
- } catch (Exception $e) {
- Db::rollback();
- throw new Exception($e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
- }
- } catch (Exception $exception) {
- return json_show(1005, $exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
- }
- }
-
- public function setWsm(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- if($info['status']!=3){
- return error_show(1005,"采购主管未审核无法设置退回仓库");
- }
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']) :"";
- $warehouse=[];
- if($info['return_tag']==2) {
- if($wsm_code==""){
- return error_show(1005,"参数 wsm_code 不能为空");
- }
- $warehouse =Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code])->find();
- if($warehouse==false){
- return error_show(1005,"仓库数据未找到");
- }
- $wareaddr =Db::name("warehouse_addr")->where(["wsm_code"=>$wsm_code,"is_del"=>0,"status"=>1])->find();
- }
- $addrcode=isset($this->post['addr_code'])&&$this->post['addr_code']!=""?$this->post['addr_code']:"";
- if($addrcode==""){
- return error_show(1005,"参数 addr_code 不能为空");
- }
- $addr=isset($this->post['addr'])&&$this->post['addr']!=""?trim($this->post['addr']):"";
- if($addr==""){
- return error_show(1005,"参数 addr 不能为空");
- }
- $mobile=isset($this->post['mobile'])&&$this->post['mobile']!=""?trim($this->post['mobile']):"";
- if($mobile==""){
- return error_show(1005,"参数 mobile 不能为空");
- }
- $contactor=isset($this->post['contactor'])&&$this->post['contactor']!=""?trim($this->post['contactor']):"";
- if($contactor==""){
- return error_show(1005,"参数 contactor 不能为空");
- }
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>$wsm_code,
- "contactor"=>$contactor,
- "mobile"=>$mobile ,
- "addr"=>$addr,
- "addr_code"=>$addrcode,
- "addtime"=>date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- try {
- $in=Db::name("order_returninfo")->insert($returninfo);
- if($in){
- if($info['return_tag']==2 &&$wareaddr==false) {
- $addrs =[
- "wsm_code"=>$wsm_code,
- "wsm_type"=>1,
- "wsm_name"=>$contactor,
- "wsm_addr"=>$addr,
- "addr_code"=>$addrcode,
- "wsm_mobile"=>$mobile,
- "status"=>'1',
- "is_del"=>'0',
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $wareaddr =Db::name("warehouse_addr")->insert($addrs);
- if($wareaddr==false){
- Db::rollback();
- return app_show(1004,"退货仓库地址录入失败");
- }
- }
- $old_info_status = $info['status'];
- $info['status']=4;
- if($info['order_type']==1){
- $info['cgder']=$warehouse['contactor_name']??"";
- $info['cgderid']=$warehouse['contactor']??0;
- }
- $info["updatetime"]=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
-
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $info['returnCode'],
- "status" => $old_info_status,
- "action_remark" => '',
- "action_type" => "status"
- ], "SHD", $info['status'], $info);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'SHD',
- "order_code" => $info['returnCode'],
- "order_id" => $info['id'],
- "order_status" => $info['status'],
- "before_status"=>$old_info_status,
- 'holder_id'=>$info['apply_id']
- ]);
- Db::commit();
- return app_show(0,"退货仓库设置成功");
- }
- }
- Db::rollback();
- return error_show(1004,"设置失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
-
- public function postfeed(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor']) :"";
- $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
- $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
- $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ?
- $this->post['addr_code']:"";
- $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
- if($wsm_code==""){
- return error_show(1005,"参数 wsm_code不能为空");
- }
- if($info['is_th']==0&&$info['order_type']==1) {
- $wsm = Db::name("warehouse_info")->where(["wsm_code" => $wsm_code])->find();
- if (empty($wsm)) {
- return error_show(1005, "未找到仓库数据");
- }
- $sm = Db::name("warehouse_addr")->where(["wsm_code" => $wsm_code,"is_del"=>0])->find();
- $contactor==""?(isset($sm['wsm_name']) ? $contactor=$sm['wsm_name']:""):"";
- $sm['wsm_name'] =isset($sm['wsm_name']) ? $sm['wsm_name']:"";
- $mobile==""?(isset($sm['wsm_mobile']) ? $mobile=$sm['wsm_mobile']:""):"";
- $sm['wsm_mobile'] =isset($sm['wsm_mobile']) ? $sm['wsm_mobile']:"";
- $addr==""?(isset($sm['wsm_addr']) ? $addr=$sm['wsm_addr']:""):"";
- $sm['wsm_addr'] =isset($sm['wsm_addr']) ? $sm['wsm_addr']:"";
- $addr_code==""?(isset($sm['addr_code']) ? $addr=$sm['addr_code']:""):"";
- $sm['addr_code'] =isset($sm['addr_code']) ? $sm['addr_code']:"";
- }
- $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
- if($info['is_th']==1 && $info['order_type']==1){
- if($contactor==''){
- return error_show(1005,"参数 contactor 不能为空");
- }
- if($mobile==''){
- return error_show(1005,"参数 mobile 不能为空");
- }
- if($addr==''){
- return error_show(1005,"参数 addr 不能为空");
- }
- if($addr_code==''){
- return error_show(1005,"参数 addr_code 不能为空");
- }
- if($addr_code!==''&&is_array($addr_code)){
- $addrs=[];
- $addrs['provice_code'] = $addr_code[0];
- $addrs['city_code'] = $addr_code[1];
- $addrs['area_code'] = $addr_code[2];
- $addr_code = json_encode($addrs);
- }
- }
- Db::startTrans();
- try{
- $var=$info['status'];
- $info['status']=$info['order_type']==1?3:4;
- $info['remark']=$remark;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
-
- $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
- if(empty($returninfo)){
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>$wsm_code,
- "contactor"=>$contactor,
- "mobile"=>$mobile ,
- "addr"=>$addr,
- "addr_code"=>$addr_code,
- "addtime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $returninfo['return_wsm'] = $wsm_code;
-
- $contactor !==""? $returninfo['contactor'] = $contactor:"";
- $mobile!==""?$returninfo['mobile'] = $mobile:"";
- $addr!==""? $returninfo['addr'] = $addr:"";
- $addr_code!==""?$returninfo['addr_code'] = $addr_code:"";
-
- }
- $in=Db::name("order_returninfo")->save($returninfo);
- if($in){
- $order = ["order_code"=>$info['returnCode'],"status"=>$var,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$var,'holder_id'=>$info['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }
- }
- Db::rollback();
- return error_show(1004,"更新失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
-
- public function addpost(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $return_info = Db::name("order_returninfo")->where(['returnCode'=>$bkcode])->find();
- if(empty($return_info)){
- $return_info=[
- "returnCode"=>$bkcode,
- "return_wsm"=>'',
- "contactor"=>'',
- "mobile"=>'',
- "addr"=>'',
- "addr_code"=>'',
- "addtime"=>date("Y-m-d H:i:s"),
- "post_company"=>'',
- "post_code"=>'',
- "post_fee"=>'',
- ];
- }
- $post_own = isset($this->post['own']) &&$this->post['own']!='' ? trim($this->post['own']):"";
- if($post_own==''){
- return error_show(1005,"参数own不能为空");
- }
- $info['post_own'] = $post_own;
- $post_company = isset($this->post['company'])&&$this->post['company']!='' ? trim($this->post['company']):"";
- if($post_company==''){
- return error_show(1005,"参数company不能为空");
- }
- $return_info['post_company'] = $post_company;
- $post_code = isset($this->post['post_code'])&&$this->post['post_code']!='' ? trim($this->post['post_code']):"";
- if($post_code==''){
- return error_show(1005,"参数post_code不能为空");
- }
- $return_info['post_code'] = $post_code;
- $fee= isset($this->post['post_fee'])&&$this->post['post_fee']!=='' ? round($this->post['post_fee'],2):"";
- if($fee===''){
- return error_show(1005,"参数post_fee不能为空");
- }
- $return_info['post_fee'] = $fee;
- Db::startTrans();
- try{
- $str=$info['status'];
- $info['status']=$info['order_type']==1?4:5;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- $order = ["order_code"=>$info['orderCode'],"status"=>$str,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD",$info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>"SHD","before_status"=>$str,'holder_id'=>$info['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
- $in=Db::name("order_returninfo")->save($return_info);
- if($in){
- $data=[
- 'thNo'=>makeNo("ST"),
- "orderCode"=>$info['orderCode'],
- "order_type"=>$info['order_type'],
- "outCode"=>$info['outCode'],
- "returnCode"=>$info['returnCode'],
- "good_code"=>$info['good_code'],
- "good_name"=>$info['good_name'],
- "return_wsm"=>$return_info['return_wsm'],
- "return_num"=>$info['error_num'],
- "contactor"=>$return_info['contactor'],
- "mobile"=>$return_info['mobile'],
- "addr"=>$return_info['addr'],
- "addr_code"=>$return_info['addr_code'],
- "return_code"=>$info['error_code'],
- "return_msg"=>$info['error_msg'],
- "post_fee"=>$return_info['post_fee'],
- "post_code"=>$return_info['post_code'],
- "post_company"=>$return_info['post_company'],
- "customer_code"=>$info['customer_code'],
- "customer_name"=>$info['customer_name'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'supplierNo' => $info['supplierNo'],
- 'supplierName' => $info['supplierName'],
- 'companyNo' => $info['companyNo'],
- 'companyName' => $info['companyName'],
- ];
- $back =Db::name("order_back")->insert($data,true);
- if($back>0){
-
- 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`)");
- $order = ["order_code"=>$data['thNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"CKTHD", 0,$data);
- $process=["order_code"=>$data['thNo'],"order_id"=>$back,"order_status"=>0,"order_type"=>"CKTHD","before_status"=>0];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }
- }
- }
- Db::rollback();
- return error_show(1004,"更新失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
-
- public function GysFeed(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if(empty($info)){
- return error_show(1005,"未找到售后数据");
- }
- $isth = isset($this->post['is_th']) && $this->post['is_th']!="" ? intval($this->post['is_th']):"0";
- $contactor = isset($this->post['contactor']) && $this->post['contactor']!="" ? trim($this->post['contactor'])
- :"";
- $mobile = isset($this->post['mobile']) && $this->post['mobile']!="" ? trim($this->post['mobile']):"";
- $addr = isset($this->post['addr']) && $this->post['addr']!="" ? trim($this->post['addr']):"";
- $addr_code = isset($this->post['addr_code']) && $this->post['addr_code']!=""&&!empty($this->post['addr_code']) ? $this->post['addr_code']:"";
- $remark = isset($this->post['remark']) && $this->post['remark']!="" ? trim($this->post['remark']):"";
- if($isth==1){
- if($contactor==''){
- return error_show(1005,"参数 contactor 不能为空");
- }
- if($mobile==''){
- return error_show(1005,"参数 mobile 不能为空");
- }
- if($addr==''){
- return error_show(1005,"参数 addr 不能为空");
- }
-
- if($addr_code==''){
- return error_show(1005,"参数 addr_code 不能为空");
- }
- if(is_array($addr_code)){
- $addrs=[];
- $addrs['provice_code'] = $addr_code[0];
- $addrs['city_code'] = $addr_code[1];
- $addrs['area_code'] = $addr_code[2];
- $addr_code = json_encode($addrs);
- }
- }
- $orde= Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
- if(empty($orde)){
- return error_show(1005,"未找到出库单数据");
- }
- Db::startTrans();
- try{
- $stat=$info['status'];
- $info['status']=$info['order_status']==1?5:3;
- $info['is_th']=$isth;
- $info['updatetime']=date("Y-m-d H:i:s");
- $up =Db::name("order_return")->save($info);
- if($up){
- $returninfo = Db::name("order_returninfo")->where(["returnCode"=>$bkcode])->find();
- if(empty($returninfo)){
- $returninfo=[
- "returnCode"=>$bkcode,
- "return_wsm"=>'',
- "contactor"=>$contactor,
- "mobile"=>$mobile ,
- "addr"=>$addr,
- "addr_code"=>$addr_code,
- "gys_remark"=>$remark,
- "addtime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $returninfo['return_wsm'] = '';
- $returninfo['contactor'] = $contactor;
- $returninfo['mobile'] = $mobile;
- $returninfo['addr'] = $addr;
- $returninfo['gys_remark'] = $remark;
- $returninfo['addr_code'] = $addr_code;
- }
- $in=Db::name("order_returninfo")->save($returninfo);
- if($in){
- $order = ["order_code"=>$info['returnCode'],"status"=>$stat,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$order,"SHD", $info['status'],$this->post);
- $process=["order_code"=>$info['returnCode'],"order_id"=>$info['id'],"order_status"=>$info['status'],"SHD","before_status"=>$stat,'holder_id'=>$info['apply_id']];
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname],$process);
- Db::commit();
- return app_show(0,"更新成功");
- }
- }
- Db::rollback();
- return error_show(1004,"更新失败");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function GetWsm(){
- $bkcode = isset($this->post['returnCode']) && $this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
- if($bkcode==""){
- return error_show(1005,"参数returnCode 不能为空");
- }
- $info = Db::name("order_return")->where(['returnCode'=>$bkcode])->find();
- if($info==false){
- return error_show(1005,"未找到售后数据");
- }
- $list=[];
- if($info['is_th']==1){
- if($info["order_type"]==1){
- $out =Db::name("order_out")->where(["outCode"=>$info['outCode'],"is_del"=>0])->find();
- if(empty($out)){
- return error_show(1005,"未找到出库单数据");
- }
- $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")
- ->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();
- if(empty($ware)){
- return error_show(1005,"未找到仓库数据");
- }
- $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
- $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
- $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
- $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
- $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
- $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
- $temp['addr_cn'] =GetAddr( $ware['addr_code']);
- $list[]=$temp;
- }else {
- $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->find();
- if (empty($returninfo)) {
- return error_show(1005, "未找到供应商仓库数据");
- }
- $data = [];
- $data['wsm_code'] = isset($returninfo['return_wsm']) && $returninfo['return_wsm'] != "" ? $returninfo['return_wsm'] : "-";
- $data['wsm_name'] = '供应商仓';
- $data['supplier_name'] = '供应商';
- $data['contactor'] = $returninfo['contactor'];
- $data['mobile'] = $returninfo['mobile'];
- $data['addr'] = $returninfo['addr'];
- $data['addr_cn'] =GetAddr( $returninfo['addr_code']);
- $data['addr_code'] = $returninfo['addr_code'];
- $list[] = $data;
- }
- }
- $supplier = Db::name("supplier")->where(["is_platform"=>1,"status"=>1,"is_del"=>0])->column("code,name");
- if(empty($supplier)){
- return error_show(1005,"未找到供应商仓库数据");
- }
- foreach ($supplier as $value){
- $temp=[];
- $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")
- ->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();
- if(empty($ware)){
- continue;
- }
- $temp['wsm_code']=isset($ware['wsm_code'])?$ware['wsm_code']:"";
- $temp['wsm_name']=isset($ware['name'])?$ware['name']:"";
- $temp['supplier_name']=$value['name'];
- $temp['contactor'] = isset($ware['wsm_name'])?$ware['wsm_name']:"";
- $temp['mobile'] =isset($ware['wsm_mobile'])?$ware['wsm_mobile']:"";
- $temp['addr'] =isset($ware['wsm_addr'])?$ware['wsm_addr']:"";
- $temp['addr_cn'] =GetAddr($ware['addr_code']);
- $temp['addr_code'] = isset($ware['addr_code'])?$ware['addr_code']:"";
- $list[]=$temp;
- }
- return app_show(0,"获取成功",$list);
- }
-
- public function setdelivery()
- {
- $param = $this->request->only(['returnCode', 'company', 'post_code', 'post_fee'], 'post', 'trim');
- $val = Validate::rule([
- 'returnCode|售后申请单编号' => 'require',
- 'company|快递公司名' => 'require|max:255',
- 'post_code|快递单号' => 'require|max:255',
- 'post_fee|快递费用' => 'require|float',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $bkcode = $param['returnCode'];
- $company = $param['company'];
- $post_code = $param['post_code'];
- $post_fee = $param['post_fee'];
- $info = Db::name("order_return")
- ->where(['is_del' => 0, 'returnCode' => $bkcode])
- ->findOrEmpty();
- if (empty($info)) return error_show(1005, "未找到售后数据");
- if (($info['is_receive'] != 1 || $info['status'] != 4)) return error_show(1005, "售后单流程状态有误");
- $out = Db::name("order_out")
- ->where(["outCode" => $info["outCode"], "is_del" => 0])
- ->findOrEmpty();
- if (empty($out)) return error_show(1005, "未找到发货单数据");
- $sale = Db::name('sale')
- ->where(['orderCode' => $info['orderCode'], "is_del" => 0])
- ->findOrEmpty();
- if (empty($sale)) return error_show(1004, "未找到销售单数据");
- Db::startTrans();
- try {
- $returninfo = Db::name("order_returninfo")->where(["returnCode" => $bkcode])->findOrEmpty();
- if (empty($returninfo)) {
-
- $wsm = Db::name('warehouse_info')
- ->where(['is_del' => 0, 'companyNo' => $sale['supplierNo'], 'status' => 1, 'wsm_type' => 4])
- ->findOrEmpty();
- $returninfo = [
- "returnCode" => $bkcode,
- "return_wsm" => $wsm['wsm_code'] ?? '',
- "contactor" => $wsm['contactor_name'] ?? '',
- "mobile" => $wsm['mobile'] ?? '',
- "addr" => $wsm['addr'] ?? '',
- "addr_code" => $wsm['addrs_code'] ?? '',
- "post_code" => $post_code,
- "post_company" => $company,
- "post_fee" => $post_fee,
- "gys_remark" => "",
- "addtime" => date("Y-m-d H:i:s")
- ];
- $up = Db::name("order_returninfo")->insert($returninfo);
- } else {
- $up = Db::name("order_returninfo")
- ->where(["returnCode" => $bkcode])
- ->update([
- 'post_fee' => $post_fee,
- 'post_company' => $company,
- 'post_code' => $post_code,
- ]);
- }
- if ($up) {
-
- $temp = Db::name('order_return_prepare')
- ->field('id')
- ->where(['is_del' => 0, 'returnCode' => $bkcode,'status'=>1])
- ->findOrEmpty();
- if (empty($temp)) $info['status'] = 5;
- else $info['status'] = 12;
- $old_info_status = $info['status'];
- $info['updatetime'] = date("y-m-d H:i:s");
- $ro = Db::name("order_return")->save($info);
- if ($ro) {
-
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_code" => $info['returnCode'],
- "status" => $old_info_status,
- "action_remark" => '',
- "action_type" => "status"
- ], "SHD", $info['status'], $this->post);
- ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
- "order_type" => 'SHD',
- "order_code" => $info['returnCode'],
- "order_id" => $info['id'],
- "order_status" => $info['status'],
- "before_status" => $old_info_status,
- 'holder_id' => $info['apply_id']
- ]);
-
- if ($info['status'] == 5) {
- $sale['th_num'] += $info['error_num'];
- if ($sale['th_num'] == $sale['good_num']) $sale['status'] = 3;
- $sale['th_fee'] += round($info['error_num'] * $sale['sale_price'], 2);
- $sale['updatetime'] = date("Y-m-d H:i:s");
- Db::name("sale")->save($sale);
- if ($info['error_num'] >= $out['send_num']) $out['status'] = 4;
- $out['send_num'] -= $info['error_num'];
- $out['error_num'] += $info['error_num'];
- $out['updatetime'] = date("Y-m-d H:i:s");
- $upout = Db::name("order_out")->save($out);
- if ($upout == false) throw new Exception('出库单数据更新失败');
-
- $error_num = $info['error_num'];
- $tmp_ooc = Db::name('order_out_child')
- ->where(['is_del' => 0, 'outCode' => $info["outCode"]])
- ->field('id,num')
- ->select()
- ->toArray();
- foreach ($tmp_ooc as $tmp) {
- if ($tmp['num'] >= $error_num) {
- Db::name('order_out_child')
- ->data(['updatetime' => date("Y-m-d H:i:s")])
- ->where(['is_del' => 0, 'id' => $tmp["id"]])
- ->dec('num', $error_num)
- ->update();
- $error_num = 0;
- } else {
- Db::name('order_out_child')
- ->where(['is_del' => 0, 'id' => $tmp["id"]])
- ->update(['num' => 0, 'updatetime' => date("Y-m-d H:i:s")]);
- $error_num -= $tmp['num'];
- }
- if ($error_num == 0) break;
- }
-
- if ($info['return_tag'] == 1) {
- $cgd_info = Db::name('order_num')
- ->alias('a')
- ->field('a.id,b.id cgd_id,b.good_price')
- ->leftJoin('purchease_order b','b.cgdNo=a.cgdNo')
- ->where(['a.orderCode' => $info['orderCode']])
- ->findOrEmpty();
- if (!empty($cgd_info)) {
- Db::name('purchease_order')
- ->where(['is_del' => 0, 'id' => $cgd_info['cgd_id']])
- ->inc('th_num', $info['error_num'])
- ->inc('th_fee', round($cgd_info['good_price'] * $info['error_num'], 2))
- ->update();
- }
- }
- }
- Db::commit();
- return json_show(0, '退货成功');
- } else throw new Exception('修改售后申请单状态失败');
- } else throw new Exception('退货失败');
-
- } catch (Exception $e) {
- Db::rollback();
- return json_show(1004, $e->getMessage());
- }
- }
-
- public function Cancel()
- {
-
- $data = $this->request->only(['token', 'returnCode'], 'post', 'trim');
- $val = Validate::rule(['returnCode|售后单编号' => 'require']);
- if (!$val->check($data)) return error_show(1005, $val->getError());
- Db::startTrans();
- try {
- $rs = Db::name('order_return')
- ->field('id,status,apply_id')
- ->where([
- ['returnCode', '=', $data['returnCode']],
- ['is_del', '=', 0]
- ])->findOrEmpty();
- if (empty($rs)) throw new Exception('该售后单记录不存在');
- if (in_array($rs['status'], [4, 12, 5, 8])) throw new Exception('不允许取消');
-
- $res = Db::name('order_return')
- ->where(['id' => $rs['id']])
- ->update(['status' => 8, 'updatetime' => date('Y-m-d H:i:s')]);
- if (!$res) throw new Exception('该售后单记录修改失败');
-
- ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], ["order_code" => $data['returnCode'], "status" => $rs['status'], "action_remark" => '', "action_type" => "delete"], 'SHD', 8, $this->post);
- 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']]);
- Db::name('order_return_prepare')
- ->where(['is_del' => 0, 'returnCode' => $data['returnCode'], 'status' => 1])
- ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
-
- Db::commit();
- return app_show(0, "取消成功");
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1004, $e->getMessage());
- }
- }
-
- public function createSaleAndCgdByAfter()
- {
- $param = $this->request->only(['token', 'returnCode'], 'post', 'trim');
- $val = Validate::rule(['token' => 'require', 'returnCode|售后申请单编号' => 'require']);
- if (!$val->check($param)) return error_show(1005, $val->getError());
-
- $info = Db::name('order_return')
- ->where('returnCode', $param['returnCode'])
- ->where('is_del', 0)
- ->find();
- if (empty($info)) return error_show(1005, '该售后申请单不存在');
- if ($info['status'] != 5) return error_show(1005, '该售后申请单尚未审核完成');
- if ($info['is_reissue'] == 1) return error_show(1005, '该售后申请单已完成补发,无法重复进行');
- $apply_id = GetUserInfo($param['token']);
- if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "申请人数据不存在");
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
-
- $old_sale = Db::name('sale')->where(['is_del' => 0, 'orderCode' => $info['orderCode']])->find();
- if (empty($old_sale)) return error_show(1005, '没有对应的销售单信息');
-
- $old_out = Db::name('order_out')->where(['is_del' => 0, 'orderCode' => $info['orderCode'], 'outCode' => $info['outCode']])->find();
- if (empty($old_out)) return error_show(1005, '没有对应的发货单信息');
-
- if ($info['order_type'] == 3) return $this->createSaleZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out['addrid'], $param['token']);
- else return $this->createSaleNotZixun($info['id'], $info['good_code'], $info, $old_sale, $rm, $ri, $old_out, $param['token']);
- }
-
- private function createSaleZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', int $addrid = 0, string $token = '')
- {
- $zxinfo = Db::name("consult_bids")->where(["bidNo" => $old_sale['zxNo'], "is_del" => 0])->find();
- if ($zxinfo == false) return error_show(1005, '未找到咨询单商品信息');
- $good_num = $info['error_num'];
- $sale_price = 0;
- $orderCode = makeNo("QR");
- $skuCode = "";
-
- $old_cgd = Db::name('order_num')
- ->alias('on')
- ->field('on.id onid,po.*')
- ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
- ->where('on.orderCode', $old_sale['orderCode'])
- ->find();
- $cgd = array_merge($old_cgd, [
- 'id' => null,
- "spuCode" => $spuCode,
- "skuCode" => $skuCode,
- "orderCode" => $orderCode,
- "sale_price" => $old_cgd['good_price'],
- "total_fee" => round($old_cgd['good_price'] * $good_num, 2),
- 'cost_fee' => $old_cgd['teach_fee'],
- "good_num" => $good_num,
- "createrid" => $rm,
- "creater" => $ri,
- "good_type" => 1,
- "order_type" => 3,
- "order_source" => 6,
- 'token' => $token,
- 'good_createrid' => $zxinfo['createrid'],
- 'good_creater' => $zxinfo['creater'],
- ]);
-
- Db::startTrans();
- try {
- $user= \app\admin\common\User::getIns();
- $supplier_temp_info =$user->handle("sInfo",["code"=>$old_cgd['supplierNo']]);
- $data = array_merge($old_sale, [
- 'id' => null,
- "orderCode" => $orderCode,
- "good_code" => $spuCode,
- "good_num" => $good_num,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "status" => 0,
- "send_status" => 0,
- "th_num" => 0,
- "th_fee" => 0,
- "send_num" => 0,
- "wsend_num" => $good_num,
- "good_type" => 1,
- "is_del" => 0,
- "remark" => $old_sale['orderCode'],
- "order_type" => 3,
- "order_source" => 6,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'returnCode' => $info['returnCode'],
- 'cgderid' => $supplier_temp_info['data']['personid']??0,
- 'cgder' => $supplier_temp_info['data']['person']??"",
- 'good_createrid' => $zxinfo['createrid'],
- 'good_creater' => $zxinfo['creater'],
- ]);
- $datainfo = Db::name('sale')->insertGetId($data);
- if ($datainfo > 0) {
- $standing_book_data = [
- 'sale_id' => $datainfo,
- 'infoNo' => $zxinfo['infoNo'],
- 'updatetime' => date('Y-m-d H:i:s')
- ];
-
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $orderCode,
- "status" => 0,
- "action_remark" => '',
- "action_type" => "create"
- ], "XSQRD", $data['status'], $data);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,
- "order_id" => $datainfo,
- "order_status" => $data['status'],
- "before_status" => 0,
- 'holder_id' => $data['apply_id']
- ]);
- $this->createCgd($cgd, $standing_book_data);
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
- if (empty($order)) throw new Exception('采购单关联数据未找到');
- $old_out_addr_info = Db::name('order_out')
- ->alias('oo')
- ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
- ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
- ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
- ->find();
- if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
- $temp = [
- 'orderCode' => $orderCode,
- 'addr' => $old_out_addr_info['addr'],
- 'addr_code' => $old_out_addr_info['addr_code'],
- 'contactor' => $old_out_addr_info['contactor'],
- 'mobile' => $old_out_addr_info['mobile'],
- 'customer_code' => $old_out_addr_info['customer_code'],
- 'receipt_quantity' => $good_num,
- 'arrive_time' => $old_out_addr_info['arrive_time'],
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' => date("Y-m-d H:i:s"),
- ];
- $addrid = Db::name('order_addr')->insertGetId($temp);
- $outCode = makeNo("DF");
- $out = [
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- 'addrid' => $addrid,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $good_num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => "",
- "order_type" => 3,
- "status" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $ou = Db::name("order_out")->insert($out);
- if ($ou == false) throw new Exception('发货地址添加创建失败');
- else {
-
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $outCode,
- "status" => 0,
- "action_remark" => '',
- "action_type" => "create"
- ], "CKD", 0, $out);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CKD',
- "order_code" => $outCode,
- "order_id" => Db::name("order_out")->getLastInsID(),
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $out['apply_id']
- ]);
-
- $standing_book_data['outCode'][] = $outCode;
- }
- $order['send_num'] += $good_num;
- $order['wsend_num'] -= $good_num;
- if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
- $ups = Db::name("order_num")->save($order);
- if ($ups) {
- $sen = Db::name("order_send")->save([
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $good_num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- if ($sen == false) throw new Exception('发货地址添加创建失败');
- }
-
- if (isset($standing_book_data['outCode'])) {
- 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']}'");
- unset($standing_book_data['outCode']);
- }
- Db::name('standing_book')->where('infoNo', $standing_book_data['infoNo'])->update($standing_book_data);
- Db::name('order_return')
- ->where(['id' => $orid, 'is_reissue' => 0])
- ->update([
- 'is_reissue' => 1,
- 'newOrderCode' => $orderCode,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- Db::commit();
- return app_show(0, "咨询订单创建成功", ["order_code" => $orderCode]);
- }
- Db::rollback();
- return error_show(1002, "咨询订单创建失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1003, $e->getMessage() . '|' . $e->getFile() . ':' . $e->getLine());
- }
- }
- private function createCgd($data,array &$standing_book_da=[]){
- $cgdCode = makeNo("CG");
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("sInfo",["code"=>$data['supplierNo']]);
- if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) throw new Exception('该供应商不存在');
- $supplier=$supplier_temp['data'];
- $wsm= Db::name("warehouse_info")
- ->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"wsm_type"=>2,"is_del"=>0])
- ->find();
- if($wsm==false){
- $wsm_code = makeNo("WSM");
- $inwsm=[
- "wsm_code"=>$wsm_code,
- "name"=>$supplier['name'],
- "wsm_type"=>2,
- "supplierNo"=>$supplier['code'],
- "addr"=>"",
- "addrs_code"=>"",
- "contactor"=>$data['order_type']==1? $supplier['personid']:$data['createrid'],
- "contactor_name"=>$data['order_type']==1? $supplier['person']:$data['creater'],
- "mobile"=>"",
- "position"=>"",
- "companyNo"=>$data['companyNo'],
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $in = Db::name("warehouse_info")->insert($inwsm);
- if($in==false) throw new Exception('仓库新增失败');
- }else $wsm_code =$wsm['wsm_code'];
-
- $from_tag=checkHasAccountBySupplierNos([$data['supplierNo']]);
- $cg =[
- "cgdNo"=>$cgdCode,
- "bkcode"=>"",
- "wsm_code"=>$wsm_code,
- "cgder"=>$data['good_creater'],
- "cgder_id"=>$data['good_createrid'],
- "spuCode"=>$data['spuCode'],
- "skuCode"=>$data['skuCode'],
- "good_name"=>$data['good_name'],
- "good_num"=>$data['good_num'],
- "good_price"=>$data['sale_price'],
- "total_fee"=>round($data['sale_price']*$data['good_num'],2),
- "pakge_fee"=>$data['pakge_fee'],
- "cert_fee"=>$data['cert_fee'],
- "open_fee"=>$data['open_fee'],
- "teach_fee"=>$data['cost_fee'],
- "mark_fee"=>$data['mark_fee'],
- "demo_fee"=>$data['demo_fee'],
- "nake_fee"=>$data['nake_fee'],
- "weight"=>$data['weight'],
- "delivery_fee"=>$data['delivery_fee'],
- "gold_price"=>$data['gold_price'],
- "diff_weight"=>"0",
- "diff_fee"=>"0",
- "supplierNo"=>$data['supplierNo'],
- "supplier_name"=>$supplier['name'],
- "companyNo"=>$data['companyNo'],
- "send_status"=>1,
- "send_num"=>0,
- "wsend_num"=>$data['good_num'],
- "remark"=>"",
- "status"=>0,
- "lasttime"=>date("Y-m-d H:i:s"),
- "is_del"=>0,
- "order_type"=>$data['order_type'],
- "order_source"=>$data['order_source'],
- "good_type"=>$data['good_type'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'good_createrid' => $data['good_createrid'],
- 'good_creater' => $data['good_createrid'],
- 'from_tag' => isset($from_tag[$data['supplierNo']]) ? 2 : 1,
- ];
- $up =Db::name("purchease_order")->insertGetId($cg);
- if($up){
-
- ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_code" => $cg['cgdNo'],
- "status" => 0,
- "action_remark" => '',
- "action_type" => "create"
- ], "CGD", $cg['status'], $cg);
- ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
- "order_type" => 'CGD',
- "order_code" => $cg['cgdNo'],
- "order_id" => $up,
- "order_status" => $cg['status'],
- "before_status"=> 0,
- 'holder_id' => $supplier['personid'],
- 'wait_id' => $supplier['personid'],
- 'wait_name' => $supplier['person'],
- ]);
- $standing_book_da = array_merge($standing_book_da, [
- 'orderCode' => $data['orderCode'],
- 'cgdNo' => $cgdCode,
- 'spuCode' => $data['spuCode'],
- 'skuCode' => $data['skuCode'],
- 'order_type' => $data['order_type'],
- 'order_source' => $data['order_source'],
- 'supplierNo' => $data['supplierNo'],
- "companyNo" => $data['companyNo'],
- ]);
- $rela=[
- "orderCode"=>$data['orderCode'],
- "cgdNo"=>$cgdCode,
- "spuCode"=>$data['spuCode'],
- "good_num"=>$data['good_num'],
- "wsend_num"=>$data['good_num'],
- "send_num"=>0,
- "wait_num"=>0,
- "status"=>1,
- "source"=>2
- ];
- Db::name("order_num")->save($rela);
- $stokc =Db::name("good_stock")
- ->where(['spuCode'=>$data['spuCode'],"wsm_code"=>$wsm_code, "is_del"=>0])
- ->find();
- if($stokc==false){
- $stokc=[
- "spuCode"=>$data['spuCode'],
- "wsm_code"=>$wsm_code,
- "wait_in_stock"=>$data['good_num'],
- "wait_out_stock"=>0,
- "usable_stock"=>0,
- "intra_stock"=>0,
- "total_stock"=>0,
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- }else{
- $stokc['wait_in_stock']+=$data['good_num'];
- $stokc['updatetime']=date("Y-m-d H:i:s");
- }
- $stoc= Db::name("good_stock")->save($stokc);
- if($stoc==false) throw new Exception('商品仓库库存修改失败');
- $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"];
- GoodLog::LogAdd($data['token'],$good_data,"CGD");
- return true;
- }else throw new Exception('商品仓库库存修改失败');
- }
-
-
- private function createSaleNotZixun(int $orid = 0, string $spuCode = '', array $info = [], array $old_sale = [], int $rm = 0, string $ri = '', array $old_out = [], string $token = '')
- {
- $goodinfo = Db::name('good')
- ->alias('g')
- ->field('g.*,gp.skuCode')
- ->join('good_platform gp', 'gp.spuCode=g.spuCode AND gp.exam_status=3')
- ->where('g.spuCode', $spuCode)
- ->where('gp.skuCode', $old_sale['skuCode'])
- ->find();
- if (empty($goodinfo)) return error_show(1005, '查不到这个商品,或该商品已下线无法售后');
- $is_activity = $old_sale['is_activity'];
- $actcode = $old_sale['activity_code'];
- $good_num = $info['error_num'];
- $supplierNo = $old_sale['supplierNo'];
- $sale_price = 0;
- $origin_price = $old_sale['origin_price'];
- $goodtype = $old_sale['good_type'];
- $is_stock = $goodinfo['is_stock'];
- $skuCode = $goodinfo['skuCode'];
- $orderCode = makeNo("QR");
- if ($is_stock == 1) {
- $stock_num = Db::name("good_stock")->alias("a")
- ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
- ->leftJoin("good_stock_info c", "a.id=c.stockid and c.balance_num>0")
- ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
- ->sum('balance_num');
- if($stock_num < $good_num){
- return error_show(1003, "批次库存数量不足");
- }
- }
- $goodinfo['cgd_gold_price'] = 0;
- if ($goodtype == 1) {
- if ($is_activity == 1) {
- $act = Db::name("activity_info")
- ->alias("a")
- ->leftJoin("good_activity b", "a.activity_code=b.activity_code")
- ->where(["a.skuCode" => $skuCode, "a.activity_code" => $actcode, "a.is_del" => 0, "a.status" => 1, "b.status" => 6, "b.is_del" => 0])
- ->find();
- if ($act == false) return error_show(1003, "未找到相关活动价");
- if ($act['moq_num'] > $good_num) return error_show(1003, "商品不满足活动价起订量{$act['moq_num']}");
- if ($act['activity_stock'] < $good_num) return error_show(1003, "商品活动库存剩余{$act['activity_stock']}");
- }
- }
-
- if ($is_stock != 1){
- $old_cgd = Db::name('order_num')
- ->alias('on')
- ->field('on.id onid,po.*')
- ->leftJoin('purchease_order po', 'po.cgdNo=on.cgdNo')
- ->where('on.orderCode', $old_sale['orderCode'])
- ->find();
- $cgd = array_merge($old_cgd, [
- 'id' => null,
- "orderCode" => $orderCode,
- "spuCode" => $spuCode,
- "skuCode" => $skuCode,
- "sale_price" => $old_cgd['good_price'],
- "total_fee" => $old_cgd['good_price'] * $good_num,
- 'cost_fee' => $old_cgd['teach_fee'],
- "good_num" => $good_num,
- "order_source" => 6,
- "createrid" => $rm,
- "creater" => $ri,
- 'token' => $token,
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],
- ]);
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("sInfo",["code"=>$cgd['supplierNo']]);
- }else{
- $user= \app\admin\common\User::getIns();
- $supplier_temp =$user->handle("sInfo",["code"=>$goodinfo['supplierNo']]);
- }
- $supplier_temp_info = [
- "id"=>$supplier_temp['data']['id']??0,
- "person"=>$supplier_temp['data']['person']??'',
- "personid"=>$supplier_temp['data']['personid']??0,
- ];
- $send_num = 0;
- Db::startTrans();
- try {
- $data = array_merge($old_sale, [
- 'id' => null,
- "orderCode" => $orderCode,
- "good_code" => $spuCode,
- "skuCode" => $skuCode,
- "good_num" => $good_num,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "origin_price" => $origin_price,
- "th_num" => 0,
- "th_fee" => 0,
- "send_num" => 0,
- "wsend_num" => $good_num,
- "remark" => $old_sale['orderCode'],
- "is_activity" => $is_activity,
- "activity_code" => $actcode,
- "order_source" => 6,
- 'status' => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- 'returnCode' => $info['returnCode'],
- 'cgderid' => $supplier_temp_info['personid'],
- 'cgder' => $supplier_temp_info['person'],
- 'good_createrid' => $goodinfo['createrid'],
- 'good_creater' => $goodinfo['creater'],
- ]);
- $datainfo = Db::name('sale')->insertGetId($data);
- if ($datainfo > 0) {
-
- ActionLog::logAdd($token, [
- "order_code" => $orderCode,
- "status" => 0,
- "action_remark" => '',
- "action_type" => "create"
- ], "XSQRD", 0, $this->post);
- ProcessOrder::AddProcess($token, [
- "order_type" => 'XSQRD',
- "order_code" => $orderCode,
- "order_id" => $datainfo,
- "order_status" => 0,
- "before_status" => 0,
- 'holder_id' => $data['apply_id']
- ]);
- if ($is_activity == 1) {
- $actup = [
- "activity_stock" => $act['activity_stock'] - $good_num,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $actupp = Db::name("activity_info")
- ->where(["skuCode" => $skuCode, "activity_code" => $actcode, "is_del" => 0, "status" => 1])
- ->save($actup);
- if ($actupp == false) throw new Exception('活动库存修改失败');
- }
- $outstatus = 0;
- $standing_book_da = ['sale_id' => $datainfo, 'customer_code' => $old_sale['customer_code'], 'skuCode' => $skuCode, 'updatetime' => date('Y-m-d H:i:s')];
- if ($is_stock == 0) $this->createCgd($cgd, $standing_book_da);
- else {
- $outstatus = 1;
- $stockid= Db::name("good_stock")->alias("a")
- ->leftJoin("warehouse_info b", "a.wsm_code=b.wsm_code")
- ->where(["spuCode" => $spuCode, "a.is_del" => 0, "a.status" => 1, "b.wsm_type" => 5, "b.companyNo" =>$supplierNo])
- ->column('a.id');
- $stockinfo =GoodStockInfo::OrderBn($orderCode,$stockid,$good_num);
- if($stockinfo==false){
- throw new Exception('库存商品更新库存失败');
- }
- }
- $old_out_addr_info = Db::name('order_out')
- ->alias('oo')
- ->field('oo.id,oa.addr,oa.addr_code,oa.contactor,oa.mobile,oa.customer_code,oa.post_fee,oa.arrive_time')
- ->leftJoin('order_addr oa', 'oa.id=oo.addrid')
- ->where(['oo.outCode' => $info['outCode'], 'oo.orderCode' => $info['orderCode']])
- ->find();
- if (empty($old_out_addr_info)) throw new Exception('发货单对应的地址信息查不到');
- $temp = [
- 'orderCode' => $orderCode,
- 'addr' => $old_out_addr_info['addr'],
- 'addr_code' => $old_out_addr_info['addr_code'],
- 'contactor' => $old_out_addr_info['contactor'],
- 'mobile' => $old_out_addr_info['mobile'],
- 'customer_code' => $old_out_addr_info['customer_code'],
- 'receipt_quantity' => $good_num,
- 'arrive_time' => $old_out_addr_info['arrive_time'],
- 'addtime' => date("Y-m-d H:i:s"),
- 'updatetime' => date("Y-m-d H:i:s"),
- ];
- $addrid = Db::name('order_addr')->insertGetId($temp);
- $outCode = makeNo("DF");
- $out = array_merge($old_out, [
- 'id' => null,
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $addrid,
- "post_name" => "",
- "post_code" => "",
- "post_fee" => 0,
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $good_num,
- "check_num" => 0,
- "error_num" => 0,
- "wsm_code" => isset($old_out['wsm_code']) ? $old_out['wsm_code'] : '',
- "order_type" => $is_stock == 1 ? 1 : 2,
- "status" => $outstatus,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- Db::name("order_out")->insert($out);
- $standing_book_da['outCode'] = $outCode;
- if($is_stock==0){
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])->find();
- if (empty($order)) throw new Exception('采购单关联数据未找到');
- $order['send_num'] += $good_num;
- $order['wsend_num'] -= $good_num;
- if ($order['wsend_num'] < 0) throw new Exception('发货数量已超出总数');
- $ups = Db::name("order_num")->save($order);
- if ($ups) {
- $sen = Db::name("order_send")->save([
- "cgdNo" => $order['cgdNo'],
- "outCode" => $outCode,
- "send_num" => $good_num,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- if ($sen == false) throw new Exception('发货地址添加创建失败');
- }
- }
- if (!isset($standing_book_da['returnCode'])) $standing_book_da['returnCode'] = '';
- if (!isset($standing_book_da['thNo'])) $standing_book_da['thNo'] = '';
- if (!isset($standing_book_da['returnGoodCode'])) $standing_book_da['returnGoodCode'] = '';
- if (!isset($standing_book_da['wsm_in_code'])) $standing_book_da['wsm_in_code'] = '';
- if (!isset($standing_book_da['cgdReturnCode'])) $standing_book_da['cgdReturnCode'] = '';
-
- 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')]));
-
- Db::name('order_return')
- ->where(['id' => $orid, 'is_reissue' => 0])
- ->update([
- 'is_reissue' => 1,
- 'newOrderCode' => $orderCode,
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- Db::commit();
- return error_show(0, "操作成功");
- } else throw new Exception('咨询订单创建失败');
- } catch (\Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage() . '|' . $e->getFile() . '|' . $e->getLine());
- }
- }
-
- public function RelaCgd($outinfo,array &$standing_book_da=[]){
- $cgd = Db::name("order_bk")->where([["spuCode","=",$outinfo['spuCode']],["is_del","=",0],["balance_num",">=",$outinfo['good_num']],['companyNo',"=",$outinfo['companyNo']]])->lock(true)->find();
- if($cgd==false) throw new Exception('未查询到备库单信息');
- $good=Db::name("good")
- ->where(["spuCode"=>$outinfo['spuCode'],"is_del"=>0])
- ->find();
- if($good==false) throw new Exception('未查询到商品信息');
- $cgdinfo =Db::name("purchease_order")
- ->where(['cgdNo'=>$cgd['cgdNo'],"is_del"=>0])
- ->find();
- if($cgdinfo==false) throw new Exception('未查询到采购单信息');
-
- $from_tag=checkHasAccountBySupplierNos([$cgdinfo['supplierNo']]);
- $QrdCgd=[
- "cgdNo"=>makeNo("CG"),
- "bkcode" => $cgdinfo['bkcode'],
- 'wsm_code'=>$cgdinfo['wsm_code'],
- "cgder_id"=>$cgdinfo['cgder_id'],
- "cgder"=>$cgdinfo['cgder'],
- "spuCode"=>$cgdinfo['spuCode'],
- "good_name"=>$cgdinfo['good_name'],
- "good_num"=>$outinfo['good_num'],
- "good_price"=>$cgdinfo['good_price'],
- "total_fee"=>round($cgdinfo['good_price']*$outinfo['good_num'],2),
- "pakge_fee"=>$cgdinfo['pakge_fee'],
- "cert_fee"=>$cgdinfo['cert_fee'],
- "open_fee"=>$cgdinfo['open_fee'],
- "delivery_fee"=>$cgdinfo['delivery_fee'],
- "mark_fee"=>$cgdinfo['mark_fee'],
- "teach_fee"=>$cgdinfo['teach_fee'],
- "nake_fee"=>$cgdinfo['nake_fee'],
- "demo_fee"=>$cgdinfo['demo_fee'],
- "weight"=>$cgdinfo['weight'],
- "diff_weight"=>$cgdinfo['diff_weight'],
- "diff_fee"=>$cgdinfo['diff_fee'],
- "gold_price"=>$cgdinfo['gold_price'],
- "supplierNo"=>$cgdinfo['supplierNo'],
- "supplier_name"=>$cgdinfo['supplier_name'],
- "companyNo"=>$cgdinfo['companyNo'],
- "send_status"=>3,
- "send_num"=>$outinfo['good_num'],
- "wsend_num"=>0,
- "remark"=>$cgdinfo['remark'],
- "status"=>3,
- "lasttime"=>$cgdinfo['lasttime'],
- "is_del"=>0,
- "order_type"=>$outinfo['order_type'],
- "order_source"=>$outinfo['order_source'],
- "good_type"=>$cgdinfo['good_type'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'good_createrid' => $good['createrid'],
- 'good_creater' => $good['creater'],
- 'from_tag' => isset($from_tag[$cgdinfo['supplierNo']]) ? 2 : 1,
- ];
- $insetrCgd=Db::name("purchease_order")->insert($QrdCgd);
- if($insetrCgd==false) throw new Exception('新增采购单失败');
- else{
- $standing_book_da = array_merge($standing_book_da, [
- 'orderCode' => $outinfo['orderCode'],
- 'cgdNo' => $cgdinfo['cgdNo'],
- 'spuCode' => $outinfo['spuCode'],
- 'order_type' => $QrdCgd['order_type'],
- 'order_source' => $QrdCgd['order_source'],
- 'supplierNo' => $cgdinfo['supplierNo'],
- 'companyNo' => $cgdinfo['companyNo'],
- 'bk_code' => $cgdinfo['bkcode'],
- 'purchease_id' => Db::name('purchease')->where('bk_code', $cgdinfo['bkcode'])->value('id',0),
- ]);
- }
- if($good['is_gold_price']==1 && $good['is_stock']==1){
- $gold = Db::name("gold_price1")
- ->field('id,price')
- ->where(["type" => $good['noble_metal'], "is_del" => 0, "status" => 1])
- ->order("addtime desc")
- ->find();
- $ct['cgd_gold_price']=$gold["price"];
- $updat=[
- "sale_price"=>0,
- "total_price"=>0,
- "origin_price"=>$cgdinfo['good_price'],
- "gold_price"=>$gold["price"],
- ];
- Db::name("sale")->where(["orderCode"=>$outinfo['orderCode']])->update($updat);
- }
- $merge_num = Db::name("purchease_order")
- ->where(["bkcode"=>$cgdinfo['bkcode'],"order_type"=>1,"is_del"=>0])
- ->where("order_source","<>",0)
- ->field("sum(send_num)-sum(th_num) as num")
- ->find();
- $cgd['balance_num']=$cgd['total_num']-$merge_num['num'];
- $cgd['merge_num']=$merge_num['num'];
- $cgd['updatetime']=date("Y-m-d H:i:s");
- $up=Db::name("order_bk")->save($cgd);
- if($up==false) throw new Exception('修改备库单失败');
- $data=[
- "orderCode"=>$outinfo['orderCode'],
- "cgdNo"=>$QrdCgd['cgdNo'],
- "spuCode"=>$outinfo['spuCode'],
- "companyNo"=>$outinfo['companyNo'],
- "good_num"=>$outinfo['good_num'],
- "wsend_num"=>$outinfo['good_num'],
- "send_num"=>0,
- "wait_num"=>$outinfo['good_num'],
- "status"=>1,
- "source"=>1,
- ];
- $order =Db::name("order_num")->save($data);
- if($order==false) throw new Exception('修改采购单销售单关联失败');
- }
-
- public function export()
- {
- $param = $this->request->only([
- 'returnCode',
- 'outCode' => '',
- 'status' => '',
- 'order_type' => '',
- 'orderCode' => '',
- 'good_code' => '',
- 'good_name' => '',
- 'except_code' => '',
- 'apply_name' => '',
- 'start' => '',
- 'end' => '',
- 'company_name' => '',
- 'supplierNo' => '',
- 'customer_code' => '',
- 'companyNo' => '',
- 'order_source' => '',
- ], 'post', 'trim');
- $val = Validate::rule(['returnCode' => 'require|array|max:10']);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- $where = [['a.is_del', "=", 0], ['a.returnCode', 'in', $param['returnCode']]];
- if ($param['returnCode'] !== '') $where[] = ['a.returnCode', "like", "%{$param['returnCode']}%"];
- if ($param['outCode'] !== '') $where[] = ['a.outCode', "like", "%{$param['outCode']}%"];
- if ($param['status'] !== '') $where[] = ['a.status', "=", $param['status']];
- if ($param['order_type'] !== "") $where[] = ['a.order_type', "=", $param['order_type']];
- if ($param['orderCode'] != "") $where[] = ['a.orderCode', "like", "%{$param['orderCode']}%"];
- if ($param['good_code'] != "") $where[] = ['a.good_code', "like", "%{$param['good_code']}%"];
- if ($param['good_name'] != "") $where[] = ['a.good_name', "like", "%{$param['good_name']}%"];
- if ($param['customer_code'] != "") $where[] = ['a.customer_code', "like", "%{$param['customer_code']}%"];
- if ($param['except_code'] != "") $where[] = ['a.except_code', "=", $param['except_code']];
- if ($param['apply_name'] != "") $where[] = ['a.apply_name', "like", "%{$param['apply_name']}%"];
- if ($param['start'] !== "") $where[] = ['a.addtime', ">=", $param['start']];
- if ($param['end'] !== "") $where[] = ['a.addtime', "<=", $param['end']];
- if ($param['order_source'] !== "") $where[] = ['c.order_source', "=", $param['order_source']];
- if ($param['supplierNo'] !== "") $where[] = ['a.supplierNo', "like", '%' . $param['supplierNo'] . '%'];
- if ($param['companyNo'] !== "") $where[] = ['a.companyNo', "like", '%' . $param['companyNo'] . '%'];
- if ($param['company_name'] !== "") $where[] = ["a.apply_id", 'in', get_company_item_user_by_name($param['company_name'])];
-
- if ($this->level == 2) {
- $hand = resign_hand_user($this->uid, 0);
- $role = $this->checkDataShare();
- if (!empty($role[DataGroupModel::$type_全部])) {
- $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
- $condition[] = ["a.person_id", "in", $hand];
- $condition[] = ["a.apply_id", "in", $arr];
- $condition[] = ["a.cgderid", "in", $hand];
- $code = Db::connect('mysql_sys')
- ->name('supplier')
- ->where(['is_del' => 0, 'personid' => $this->uid])
- ->column('code');
- if($code) $condition[] = ["a.supplierNo", "in", $code];
- }
- }
-
- if ($this->level == 3) $where[] = ['c.is_stock', '<>', 1];
- $list = Db::name('order_return')
- ->field('
- a.returnCode 售后申请单编码,
- a.order_type 订单类型,
- a.apply_name 申请人,
- a.cgder 采购员,
- a.person 采购负责人,
- a.outCode 发货单号,
- a.is_receive 是否收到货,
- a.total_num 总数量,
- a.error_num 异常数量,
- a.error_msg 异常原因,
- a.error_remark 异常备注,
- a.except_code 客户意愿,
- a.orderCode 订单编号,
- a.good_code 商品编号,
- a.good_name 商品名称,
- a.customer_code 客户编码,
- a.customer_name 客户名称,
- a.is_post 是否承担物流费用,
- a.is_th 供应商是否退货,
- a.return_tag 退回何处,
- a.status 状态,
- a.remark 审核备注,
- a.addtime 创建时间,
- a.updatetime 更新时间,
- a.is_reissue 是否完成补发货,
- a.newOrderCode 售后完成后新的销售订单号,
- a.loop_total 状态从业务公司修改待供应商确认到待采购审核的循环次数,
- b.return_wsm 退回仓库,
- b.contactor 仓库联系人,
- b.mobile 联系方式,
- b.addr 地址,
- b.addr_code,
- b.post_code 快递单号,
- b.post_company 快递公司,
- b.post_fee 快递费用,
- b.gys_remark 供应商备注,
- a.supplierNo 供应商编码,
- a.supplierName 供应商名称,
- a.companyNo 业务公司编码,
- a.companyName 业务公司名称')
- ->alias('a')
- ->where($where)
- ->where(function ($query) use ($condition) {
- $query->whereOr($condition);
- })
- ->leftJoin('order_returninfo b', 'b.returnCode=a.returnCode')
- ->leftJoin("sale c", "c.orderCode=a.orderCode AND c.is_del=0")
- ->select()
- ->toArray();
- $order_type = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞', 6 => '售后补换货', 7 => '报备转单', 8 => '支付渠道'];
- $is_receive = [0 => '否', 1 => '是'];
- $except_code = [0 => [1 => '退货', 2 => '补发'], 1 => [1 => '退货', 2 => '换货'],];
- $return_tag = [1 => '供应商', 2 => '业务企业'];
- $status = [1 => '待业务审核', 2 => '待采购审核', 4 => '待客户退货', 5 => '售后已完成', 6 => '业务已驳回', 8 => '申请已取消', 9 => '供应商审核', 10 => '业务公司修改待供应商确认'];
- foreach ($list as &$value) {
- $value['订单类型'] = $order_type[$value['订单类型']] ?? '';
- $value['客户意愿'] = $except_code[$value['是否收到货']][$value['客户意愿']] ?? '';
- $value['是否收到货'] = $is_receive[$value['是否收到货']] ?? '';
- $value['是否承担物流费用'] = $is_receive[$value['是否承担物流费用']] ?? '';
- $value['供应商是否退货'] = $is_receive[$value['供应商是否退货']] ?? '';
- $value['退回何处'] = $return_tag[$value['退回何处']] ?? '';
- $value['状态'] = $status[$value['状态']] ?? '';
- $value['是否完成补发货'] = $is_receive[$value['是否完成补发货']] ?? '';
- $addr_code = explode(',', $value['addr_code']);
- $value['地址'] = GetAddr(json_encode(['provice_code' => $addr_code[0], 'city_code' => $addr_code[1], 'area_code' => $addr_code[2]])) . $value['地址'];
- unset($value['addr_code']);
- }
- if (empty($list)) $list[] = ['没有相关可导出的数据'];
- excelSave('售后申请单' . date('YmdHis'), array_keys($list[0]), $list);
- }
- }
|