1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878 |
- <?php
- namespace app\admin\controller;
- use app\admin\model\GoodLog;
- use app\admin\model\ProcessOrder;
- use Exception;
- use think\App;
- use think\facade\Db;
- use app\admin\model\ActionLog;
- class Sale extends Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
- public function create()
- {
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- $orderCode=makeNo("CX");
- $customer_code= isset($this->post['customer_code'])&& $this->post['customer_code'] !=="" ? trim($this->post['customer_code']) :"";
- if($customer_code==""){
- return error_show(1002,"客户customer_code不能为空");
- }
- $customer=Db::name("customer_info")->where(["companyNo"=>$customer_code])->find();
- if($customer==false){
- return error_show(1004,"未找到客户数据");
- }
- $supplierNo= isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
- if($supplierNo==""){
- return error_show(1002,"参数supplierNo不能为空");
- }
- $supplier=Db::name("business")->where(["companyNo"=>$supplierNo])->find();
- if($supplier==false){
- return error_show(1004,"未找到平台供应商数据");
- }
- $goodtype =isset($this->post['goodtype']) && $this->post['goodtype'] !=="" ?intval($this->post['goodtype']):"1";
- $order_type =isset($this->post['order_type']) && $this->post['order_type'] !=="" ?intval($this->post['order_type'])
- :"1";
- $sendtype =isset($this->post['sendtype']) && $this->post['sendtype'] !=="" ?intval($this->post['sendtype']):"";
- if($sendtype===''){
- return error_show(1004,"参数sendtype不能为空");
- }
- $platform_id =isset($this->post['platform_id']) && $this->post['platform_id'] !=="" ?intval($this->post['platform_id']):"";
- if($platform_id==''){
- return error_show(1004,"参数platform_id不能为空");
- }
- // $zxinfoNo= isset($this->post['zxinfoNo'])&& $this->post['zxinfoNo'] !=="" ? trim($this->post['zxinfoNo']) :"";
- // if($zxinfoNo=="" &&$order_type!==1){
- // return error_show(1002,"参数 zxinfoNo 不能为空");
- // }
- $platform_order =isset($this->post['platform_order']) && $this->post['platform_order'] !=="" ?trim($this->post['platform_order']):"";
- // if($platform_order==''){
- // return error_show(1004,"参数platform_order不能为空");
- // }
- $good_code =isset($this->post['good_code']) && $this->post['good_code'] !=="" ?trim($this->post['good_code']):"";
- if($good_code==''){
- return error_show(1004,"参数good_code不能为空");
- }
- $good_num =isset($this->post['good_num']) && $this->post['good_num'] !=="" ?intval($this->post['good_num']):"";
- if($good_num===''){
- return error_show(1004,"参数good_num不能为空");
- }
- $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
- if($arrtime==""){
- return error_show(1004,"参数arrtime不能为空");
- }
- $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
- $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
- // $poNo =isset($this->post['poNo'])&&$this->post['poNo']!=""? trim($this->post['poNo']):"";
- $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $good_code])->find();
- if ($ct == false) {
- return error_show(1002, "未找到商品数据");
- }
- $goodinfo=$ct;
- $is_stock=$ct['is_stock'];
- $spuCode = $ct['spuCode'];
- $skuCode = $ct['skuCode'];
- $is_activity= isset($this->post['is_activity'])&&$this->post['is_activity']!=="" ?$this->post['is_activity']:"";
- $actcode= isset($this->post['act_code'])&&$this->post['act_code']!=="" ?trim($this->post['act_code']):"";
- if($order_type==1){
- if($is_activity===""){
- return error_show(1002, "参数is_activity不能为空");
- }
- if($is_activity==1){
- return error_show(1002, "参数act_code不能为空");
- }
- }
- if($goodinfo['is_stock']==1){
- $stock =Db::name("good_stock")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
- if($stock==false||$stock['usable_stock']<$good_num){
- return error_show(1003,"库存数量不足");
- }
- }
- $origin = Db::name("good_nake")->where([["spuCode","=",$spuCode],["min_num","<=",$good_num],["is_del","=",
- 0]])->order("min_num desc")->find();
- if($origin==false){
- return error_show(1003,"未找到相关阶梯成本价格");
- }
- $origin_price = $origin['nake_fee'];
- $sale_price = isset($this->post['good_price'])&&$this->post['good_price']!="" ? floatval($this->post['good_price']):0;
- if($goodtype==1){
- $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->where([["min_num",
- "<=",$good_num]])->order("min_num desc")->find();
- if($good==false){
- return error_show(1003,"未找到相关阶梯价格");
- }
- $sale_price = $good['sale_price'];
- 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['moq_num']}");
- }
- $sale_price=$act['activity_price'];
- }
- }
- $cgd=[
- "supplierNo"=>$ct['supplierNo'],
- "companyNo"=>$supplierNo,
- "orderCode"=>$orderCode,
- "spuCode"=>$ct['spuCode'],
- "skuCode"=>$ct['skuCode'],
- "good_name"=>$ct['good_name'],
- "sale_price"=>$origin_price,
- "total_fee"=>$origin_price*$good_num,
- "pakge_fee"=>$ct['packing_fee'],
- "cert_fee"=>$ct['cert_fee'],
- "open_fee"=>$ct['open_fee'],
- "cost_fee"=>$ct['cost_fee'],
- "mark_fee"=>$ct['mark_fee'],
- "demo_fee"=>$ct['demo_fee'],
- "good_num"=>$good_num,
- "good_type"=>$goodtype,
- "order_type"=>$order_type,
- ];
- $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
- if($sendtype==1){
- if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
- return error_show(1004,"参数addrlist不能为空");
- }
- }
- $remark =isset($this->post['remark']) && $this->post['remark'] !=="" ?trim($this->post['remark']):"";
- $proofid= isset($this->post['proof_id'])&&$this->post['proof_id']===""?intval($this->post['proof_id']):"0";
- $apply_id =GetUserInfo($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'] : "";
- Db::startTrans();
- try {
- $data=[
- "orderCode"=>$orderCode,
- "good_code"=>$spuCode,
- "skuCode"=>$skuCode,
- "customer_code"=>$customer_code,
- "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
- "good_num"=>$good_num,
- "cat_id"=>$goodinfo['cat_id'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "origin_price"=>$origin_price,
- "sale_price"=>$sale_price,
- "post_fee"=>0,
- "status"=>0,
- "send_num"=>0,
- "wsend_num"=>$good_num,
- "send_status"=>1,
- "good_type"=>$goodtype,
- "send_type"=>$sendtype,
- "supplierNo"=>$supplierNo,
- "is_del"=>0,
- "zxNo"=>"",
- "platform_order"=>$platform_order,
- "platform_id"=>$platform_id,
- "remark"=>$remark,
- "is_stock"=>$is_stock,
- "is_activity"=>$is_activity===""?0:$is_activity,
- "proof_id"=>$proofid,
- "order_type"=>$order_type,
- // "poNo"=>$poNo,
- "workNo"=>$workNo,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'total_price'=>round($sale_price*$good_num,2),
- ];
- $paytime==""?"": $data['paytime'] = $paytime;
- $datainfo = Db::name('sale')->insert($data,true);
- if($datainfo>0){
- if($is_stock==0){
- $bol=$this->createCgd($cgd);
- if($bol==false){
- Db::rollback();
- return error_show(1002,"咨询订单创建失败");
- }
- }else{
- $dd=[
- "orderCode"=>$orderCode,
- "spuCode"=>$spuCode,
- "total_num"=>$good_num,
- "merge_num"=>0,
- "balance_num"=>$good_num,
- "status"=>1,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- ];
- $db=Db::name("sale_bk")->insert($dd);
- if($db==false){
- Db::rollback();
- return error_show(1002,"咨询订单创建失败");
- }
- }
- if($sendtype==1){
- foreach ($addrlist as $value){
- $temp=[];
- $addrs=[];
- if($value['addr_code']!==''&&is_array($value['addr_code'])){
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- }else{
- $addr = isset($value['addr_code'])?$value['addr_code']:'';
- }
- $temp['orderCode']=$orderCode;
- $temp['contactor']=$value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code']=$addr;
- $temp['customer_code'] =$customer_code;
- $temp['receipt_quantity']=$value['receipt_quantity'];
- $temp['post_fee'] =0;
- $temp['is_del'] =0;
- $temp['addtime'] =date("Y-m-d H:i:s");
- $temp['updatetime'] =date("Y-m-d H:i:s");
- $temp['arrive_time']=$arrtime;
- $vmp = Db::name('order_addr')->insert($temp,true);
- if($vmp>0){
- // $outCode=makeNo("CK");
- // $out=[
- // "orderCode"=>$orderCode,
- // "outCode"=>$outCode,
- // "apply_id"=>$rm,
- // "apply_name"=>$ri,
- // "addrid"=>$vmp,
- // "post_name"=>"",
- // "post_code"=>"",
- // "post_fee"=>0,
- // "sendtime"=>date("Y-m-d H:i:s"),
- // "send_num"=>$value['receipt_quantity'],
- // "check_num"=>0,
- // "error_num"=>0,
- // "wsm_code"=>"",
- // "order_type"=>$order_type,
- // "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){
- // Db::rollback();
- // return error_show(1002,"发货地址添加创建失败");
- // }
- // if($is_stock==0){
- // $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
- // ->find();
- // if($order==false){
- // Db::rollback();
- // return error_show(1006,"采购单关联数据未找到");
- // }
- // $order['send_num']+=$value['receipt_quantity'];
- // $order['wsend_num']-=$value['receipt_quantity'];
- // if($order['wsend_num']<0){
- // Db::rollback();
- // return error_show(1002,"发货数量已超出总数");
- // }
- // $ups = Db::name("order_num")->save($order);
- // if($ups){
- // $tep=[
- // "cgdNo"=>$order['cgdNo'],
- // "outCode"=>$outCode,
- // "send_num"=>$value['receipt_quantity'],
- // "status"=>1,
- // "addtime"=>date("Y-m-d H:i:s"),
- // "updatetime"=>date("Y-m-d H:i:s")
- // ];
- // $sen=Db::name("order_send")->save($tep);
- // if($sen==false){
- // Db::rollback();
- // return error_show(1002,"发货地址添加创建失败");
- // }
- // }
- // }
- }else{
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- }
- }
- Db::commit();
- return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
- }
- Db::rollback();
- return error_show(1002,"咨询订单创建失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1005,$e->getMessage());
- }
- }
- public function createCgd($data){
- $cgdCode = makeNo("CG");
- $supplier=Db::name("supplier")->where(["code"=>$data['supplierNo'],"is_del"=>0])->find();
- //echo Db::name("supplier")->getLastSql();
- if($supplier==false){
- return false;
- }
- $wsm= Db::name("warehouse_info")->where(["supplierNo"=>$data["supplierNo"],"companyNo"=>$data['companyNo'],"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"=>0,
- "contactor_name"=>0,
- "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){
- return false;
- }
- }else{
- $wsm_code =$wsm['wsm_code'];
- }
- $cg =["cgdNo"=>$cgdCode,
- "bkcode"=>"",
- "wsm_code"=>$wsm_code,
- "cgder"=>$supplier['person'],
- "cgder_id"=>$supplier['personid'],
- "spuCode"=>$data['spuCode'],
- "skuCode"=>$data['skuCode'],
- "good_name"=>$data['good_name'],
- "good_num"=>$data['good_num'],
- "good_price"=>$data['sale_price'],
- "total_fee"=>$data['total_fee'],
- "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'],
- #"weight"=>$data['weight'],
- "diff_weight"=>"0",
- "diff_fee"=>"0",
- "gold_price"=>"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'],
- "good_type"=>$data['good_type'],
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $up =Db::name("purchease_order")->insert($cg);
- if($up){
- $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
- ];
- $re =Db::name("order_num")->save($rela);
- if($re==false){
- return false;
- }else{
- $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"=>$data['good_num'],
- "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['total_stock']+=$data['good_num'];
- $stokc['updatetime']=date("Y-m-d H:i:s");
- }
- $stoc= Db::name("good_stock")->save($stokc);
- if($stoc==false){
- return false;
- }
- return true;
- }
- }else{
- return false;
- }
- }
- public function addAddr(){
- $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=""? trim($this->post['orderCode']):"";
- $etid = Db::name("sale")->where(["orderCode" => $orderCode, "is_del" => 0])->find();
- if (empty($etid)) {
- return error_show(1002, "未找到数据");
- }
- $arrtime = isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
- if($arrtime==""){
- return error_show(1004,"参数arrtime不能为空");
- }
- $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
- ->select()->toArray();
- if(empty($order)){
- return error_show(1004,"未找到可以发货得采购单数据");
- }
- $token = isset($this->post['token']) && $this->post['token'] !=="" ?trim($this->post['token']):"";
- $apply_id =GetUserInfo($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'] : "";
- $addrlist = isset($this->post['addrlist']) && $this->post['addrlist'] !=="" ?$this->post['addrlist']:"";
- if($addrlist=="" || empty($addrlist) ||!is_array($addrlist)){
- return error_show(1004,"参数addrlist不能为空");
- }
- Db::startTrans();
- try{
- foreach ($addrlist as $value){
- $temp=[];
- $addrs=[];
- if($value['addr_code']!==''&&is_array($value['addr_code'])){
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- }else{
- $addr = isset($value['addr_code'])?$value['addr_code']:'';
- }
- $temp['orderCode']=$orderCode;
- $temp['contactor']=$value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code']=$addr;
- $temp['customer_code'] =$etid['customer_code'];
- $temp['receipt_quantity']=$value['receipt_quantity'];
- $temp['post_fee'] =0;
- $temp['is_del'] =0;
- $temp['addtime'] =date("Y-m-d H:i:s");
- $temp['updatetime'] =date("Y-m-d H:i:s");
- $temp['arrive_time']=$arrtime;
- $vmp = Db::name('order_addr')->insert($temp,true);
- if($vmp>0){
- $outCode=makeNo("CK");
- $out=[
- "orderCode"=>$orderCode,
- "outCode"=>$outCode,
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "addrid"=>$vmp,
- "post_name"=>"",
- "post_code"=>"",
- "post_fee"=>0,
- "sendtime"=>date("Y-m-d H:i:s"),
- "send_num"=>$value['receipt_quantity'],
- "check_num"=>0,
- "error_num"=>0,
- "wsm_code"=>"",
- "order_type"=>$etid['order_type'],
- "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){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- $num = $value['receipt_quantity'];
- $orsend=[];
- foreach ($order as $val){
- $tep=[];$ornum=0;
- if($val['wsend_num']>=$num){
- $val['wsend_num']-=$num;
- $val['send_num']+=$num;
- $ornum =$num;
- $num=0;
- }else{
- $num-=$val['wsend_num'];
- $val['send_num']+=$val['wsend_num'];
- $ornum =$val['wsend_num'];
- $val['wsend_num']=0;
- }
- $or =Db::name("order_num")->save($val);
- if($or==false){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- $tep=[
- "cgdNo"=>$val['cgdNo'],
- "outCode"=>$outCode,
- "send_num"=>$ornum,
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $sen=Db::name("order_send")->save($tep);
- if($sen==false){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- if($num==0){
- break;
- }
- }
- }else{
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- }
- Db::commit();
- return app_show(0,"发货地址添加完成");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1002,$e->getMessage());
- }
- }
- public function consultOrder(){
- $bidNo =isset($this->post['bidNo'])&&$this->post['bidNo']!="" ? trim($this->post['bidNo']):"";
- if($bidNo==""){
- return error_show(1003,"参数bidNo不能为空");
- }
- $zxinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
- if($zxinfo==false){
- return error_show(1003,"未找到咨询单商品信息");
- }
- if($zxinfo['status']!=6){
- return error_show(1003,"咨询单状态有误无法转单");
- }
- $zx =Db::name("consult_info")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->find();
- if($zx==false){
- return error_show(1003,"未找到咨询单信息");
- }
- if($zx['status']!=4){
- return error_show(1003,"咨询单状态有误无法转单");
- }
- $zxorder =Db::name("consult_order")->where(["zxNo"=>$zx["zxNo"],"is_del"=>0])->find();
- if($zxorder==false){
- return error_show(1003,"未找到咨询单信息");
- }
- $good_num =isset($this->post['good_num'])&&$this->post['good_num']!="" ? intval($this->post['good_num']):"";
- if($good_num===""){
- return error_show(1003,"参数 good_num 不能为空");
- }
- $sendtype = isset($this->post['sendtype'])&&$this->post['sendtype']!="" ? intval($this->post['sendtype']):"";
- if($sendtype==""){
- return error_show(1003,"参数sendtype不能为空");
- }
- $orderCode = makeNo("QR");
- $spuCode = $zxinfo['spuCode'];
- $skuCode = "";
- $is_stock=0;
- $cgd=[
- "supplierNo"=>$zxinfo['supplierNo'],
- "companyNo"=>$zxorder['companyNo'],
- "spuCode"=>$spuCode,
- "skuCode"=>$skuCode,
- "orderCode"=>$orderCode,
- "good_name"=>$zxinfo['good_name'],
- "sale_price"=>$zxinfo['sale_price'],
- "total_fee"=>$zxinfo['total_fee'],
- "pakge_fee"=>$zxinfo['pakge_fee'],
- "cert_fee"=>$zxinfo['cert_fee'],
- "open_fee"=>$zxinfo['open_fee'],
- "cost_fee"=>$zxinfo['cost_fee'],
- "mark_fee"=>$zxinfo['mark_fee'],
- "demo_fee"=>$zxinfo['demo_fee'],
- "good_num"=>$good_num,
- "good_type"=>1,
- "is_diff"=>$zxinfo['is_diff'],
- "order_type"=>3,
- ];
- $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
- if($token==""){
- return error_show(102, "参数token不能为空");
- }
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) {
- return error_show(102, "申请人数据不存在");
- }
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- $va = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- if($sendtype==1){
- if ($va == "") {
- return error_show(1002, "参数order_addr不能为空");
- }
- }
- $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
- if($arrtime==""){
- return error_show(1002, "参数arrtime不能为空");
- }
- Db::startTrans();
- try{
- $data=[
- "orderCode"=>$orderCode,
- "good_code"=>$spuCode,
- "skuCode"=>$skuCode,
- "customer_code"=>$zxorder['khNo'],
- "good_name"=>isset($zxinfo['good_name'])&&$zxinfo['good_name']!==''?$zxinfo['good_name']:'',
- "good_num"=>$good_num,
- "cat_id"=>$zxinfo['cat_id'],
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "origin_price"=>$zxinfo['nake_fee'],
- "sale_price"=>$zxinfo['sale_price'],
- "post_fee"=>0,
- "status"=>0,
- "send_num"=>0,
- "wsend_num"=>$good_num,
- "send_status"=>1,
- "good_type"=>1,
- "send_type"=>$sendtype,
- "supplierNo"=>$zxorder['companyNo'],
- "is_del"=>0,
- "zxNo"=>$bidNo,
- "platform_order"=>"",
- "platform_id"=>0,
- "remark"=>"",
- "arrivetime"=>$arrtime,
- "is_stock"=>0,
- "is_activity"=>0,
- "proof_id"=>0,
- "order_type"=>3,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'total_price'=>round($zxinfo['sale_price']*$good_num,2),
- ];
- $datainfo = Db::name('sale')->insert($data, true);
- if($datainfo>0){
- $zx['status']=5;
- $zx['updatetime']=date("Y-m-d H:i:s");
- $sa=Db::name("consult_info")->save($zx);
- if($sa==false){
- Db::rollback();
- return error_show(1002,"咨询单修改失败");
- }
- $bol=$this->createCgd($cgd);
- if($bol==false){
- Db::rollback();
- return error_show(1002,"咨询订单创建失败");
- }
- $limt=[
- "spuCode"=>$zxinfo['spuCode'],
- "good_name"=>$zxinfo['good_name'],
- "brand_id"=>$zxinfo['brand_id'],
- "good_unit"=>$zxinfo['good_name'],
- "cat_id"=>$zxinfo['cat_id'],
- "good_type"=>0,
- "moq"=>1,
- "customized"=>$zxinfo['work_day'],
- "tax"=>$zxinfo['tax'],
- "supplierNo"=>$zxinfo["supplierNo"],
- "is_auth"=>0,
- "craft_desc"=>$zxinfo['good_name'],
- "good_remark"=>"",
- "good_img"=>$zxinfo['good_img'],
- "good_thumb_img"=>"",
- "good_info_img"=>"",
- "status"=>1,
- "is_del"=>0,
- "createrid"=>$rm,
- "creater"=>$ri,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $good = Db::name("good_zixun")->insert($limt);
- if(!$good){
- Db::rollback();
- return error_show(1006,"咨询商品录入失败");
- }
- if(!empty($va)){
- $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
- ->find();
- if($order==false){
- Db::rollback();
- return error_show(1006,"采购单关联数据未找到");
- }
- foreach ($va as $value){
- $temp=[];
- $addrs=[];
- if($value['addr_code']!==''&&is_array($value['addr_code'])){
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- }else{
- $addr = isset($value['addr_code'])?$value['addr_code']:'';
- }
- $temp['orderCode']=$orderCode;
- $temp['contactor']=$value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code']=$addr;
- $temp['customer_code'] =$zxorder['khNo'];
- $temp['receipt_quantity']=$value['receipt_quantity'];
- $temp['post_fee'] =0;
- $temp['is_del'] =0;
- $temp['addtime'] =date("Y-m-d H:i:s");
- $temp['updatetime'] =date("Y-m-d H:i:s");
- $temp['arrive_time']=$arrtime;
- $vmp = Db::name('order_addr')->insert($temp,true);
- if($vmp>0){
- $outCode=makeNo("CK");
- $out=[
- "orderCode"=>$orderCode,
- "outCode"=>$outCode,
- "apply_id"=>$rm,
- "apply_name"=>$ri,
- "addrid"=>$vmp,
- "post_name"=>"",
- "post_code"=>"",
- "post_fee"=>0,
- "sendtime"=>date("Y-m-d H:i:s"),
- "send_num"=>$value['receipt_quantity'],
- "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){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- $order['send_num']+=$value['receipt_quantity'];
- $order['wsend_num']-=$value['receipt_quantity'];
- if($order['wsend_num']<0){
- Db::rollback();
- return error_show(1002,"发货数量已超出总数");
- }
- $ups = Db::name("order_num")->save($order);
- if($ups){
- $tep=[
- "cgdNo"=>$order['cgdNo'],
- "outCode"=>$outCode,
- "send_num"=>$value['receipt_quantity'],
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $sen=Db::name("order_send")->save($tep);
- if($sen==false){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- }
- }else{
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- }
- }
- Db::commit();
- return error_show(0,"咨询订单创建成功",["order_code"=>$orderCode]);
- }
- Db::rollback();
- return error_show(1002,"咨询订单创建失败");
- }catch(\Exception $e){
- Db::rollback();
- return error_show(1003,$e->getMessage());
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function projectCreate(){
- $planNo =isset($this->post['planNo'])&&$this->post['planNo']!=""?trim($this->post['planNo']):"";
- if($planNo==""){
- return error_show(1004,"参数planNo不能为空");
- }
- $plan =Db::name("project_plan")->where(["planNo"=>$planNo,"is_del"=>0])->find();
- if($plan==false){
- return error_show(1004,"未找到方案信息");
- }
- $feedbackid = Db::name("project_plan_rela")->where(["planNo"=>$planNo,"is_del"=>0])->column("feedback_id,sale_price,sale_num");
- if($feedbackid==false){
- return error_show(1004,"未找到方案反馈信息");
- }
- $project = Db::name("project")->where(["projectNo"=>$plan['projectNo'],"is_del"=>0])->find();
- if($project==false){
- return error_show(1004,"未找到方案信息");
- }
- $arrtime=isset($this->post['arrtime'])&&$this->post['arrtime']!="" ?$this->post['arrtime']:"";
- if($arrtime==""){
- return error_show(1002, "参数arrtime不能为空");
- }
- $planinfo =isset($this->post['planinfo'])&&!empty($this->post['planinfo']) ?$this->post['planinfo']:"";
- if($planinfo==""){
- return error_show(1002, "参数planinfo不能为空");
- }
- $token=isset($this->post['token'])&&$this->post['token']!=""? trim($this->post['token']):"";
- if($token==""){
- return error_show(102, "参数token不能为空");
- }
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) {
- return error_show(102, "申请人数据不存在");
- }
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $ri = isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
- Db::startTrans();
- try {
- $feedid = array_column($feedbackid,"feedback_id");
- foreach ($planinfo as $value){
- $good=[];
- $feedback = Db::name("project_feedback")->where(["id"=>$value['feedback_id'],"projectNo"=>$plan['projectNo'],
- "is_del"=>0])->find();
- if($feedback==false){
- Db::rollback();
- return error_show(1002, "反馈数据未找到");
- }
- $key =array_search($feedback['id'],$feedid);
- $price = $feedbackid[$key];
- $good['spuCode'] = $feedback['spuCode'];
- $good['skuCode'] = $feedback['skuCode'];
- $good['good_num'] = $price['sale_num'];
- $good['sendtype'] = $value['sendtype'];
- $good['sale_price']=$price['sale_price'];
- $good['origin_price']=$feedback['origin_price'];
- $good['companyNo']=$project['companyNo'];
- $good['customerNo']=$project['khNo'];
- $good['pgNo']=$feedback['pgNo'];
- $good['arrtime']=$arrtime;
- $good['rm']=$rm;
- $good['ri']=$ri;
- if($value['sendtype']==1){
- if(!isset($value['addrlist'])||empty($value['addrlist'])){
- Db::rollback();
- return error_show(1002, "订单地址不能为空");
- }
- $good['addrlist'] = $value['addrlist'];
- }
- if($feedback['data_source']==1){
- $feed=$this->project_good($good);
- }else{
- $feed=$this->project_zx($good);
- }
- if($feed==false){
- Db::rollback();
- return error_show(1002, "咨询订单生成失败");
- }
- $feedback['status']=2;
- $feedback['updatetime']=date("Y-m-d H:i:s");
- $fed =Db::name("project_feedback")->save($feedback);
- if($fed==false){
- Db::rollback();
- return error_show(1002, "项目订单生成失败");
- }
- }
- $plan['status']=2;
- $plan['updatetime']=date("Y-m-d H:i:s");
- $in =Db::name("project_plan")->save($plan);
- if($in==false){
- Db::rollback();
- return error_show(1002, "项目订单生成失败");
- }
- $project["status"]=6;
- $project['updatetime']=date("Y-m-d H:i:s");
- $pr =Db::name("project")->save($project);
- if($pr==false){
- Db::rollback();
- return error_show(1002, "项目订单生成失败");
- }
- Db::commit();
- return app_show(0, "咨询订单生成成功");
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1002, $e->getMessage());
- }
- }
- /**
- * @param $data
- * @return false
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- *
- */
- public function project_zx($data){
- $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$data['spuCode'],"is_del"=>0])->find();
- if($goodinfo==false){
- return false;
- }
- $orderCode=makeNo("QR");
- $cgd=[
- "supplierNo"=>$goodinfo['supplierNo'],
- "companyNo"=>$data['companyNo'],
- "spuCode"=>$data['spuCode'],
- "skuCode"=>"",
- "orderCode"=>$orderCode,
- "good_name"=>$goodinfo['good_name'],
- "sale_price"=>$data['origin_price'],
- "total_fee"=>$data['origin_price']*$data['good_num'],
- "pakge_fee"=>$goodinfo['pakge_fee'],
- "cert_fee"=>$goodinfo['cert_fee'],
- "open_fee"=>$goodinfo['open_fee'],
- "cost_fee"=>$goodinfo['cost_fee'],
- "mark_fee"=>$goodinfo['mark_fee'],
- "demo_fee"=>$goodinfo['demo_fee'],
- "good_num"=>$data['good_num'],
- "good_type"=>1,
- "order_type"=>4,
- ];
- $datas=[
- "orderCode"=>$orderCode,
- "good_code"=>$data['spuCode'],
- "skuCode"=>"",
- "customer_code"=>$data['customerNo'],
- "good_name"=>isset($goodinfo['good_name'])&&$goodinfo['good_name']!==''?$goodinfo['good_name']:'',
- "good_num"=>$data['good_num'],
- "cat_id"=>$goodinfo['cat_id'],
- "apply_id"=>$data['rm'],
- "apply_name"=>$data['ri'],
- "origin_price"=>$goodinfo['nake_fee'],
- "sale_price"=>$data['sale_price'],
- "post_fee"=>0,
- "status"=>0,
- "send_num"=>0,
- "wsend_num"=>$data['good_num'],
- "send_status"=>1,
- "good_type"=>1,
- "send_type"=>$data['sendtype'],
- "supplierNo"=>$data['companyNo'],
- "is_del"=>0,
- "zxNo"=>$data["pgNo"],
- "platform_order"=>"",
- "platform_id"=>0,
- "remark"=>"",
- "is_stock"=>0,
- "is_activity"=>0,
- "proof_id"=>0,
- "order_type"=>4,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'total_price'=>round($data['sale_price']*$data['good_num'],2),
- ];
- $datainfo = Db::name('sale')->insert($datas, true);
- if($datainfo>0){
- $bol = $this->createCgd($cgd);
- if ($bol == false) {
- return false;
- }
- $goodinfo['status']=6;
- $goodinfo['updatetime']=date("Y-m-d H:i:s");
- $sa=Db::name("consult_bids")->save($goodinfo);
- if($sa==false){
- return false;
- }
- if ($data['sendtype']==1&&!empty($data['addrlist'])) {
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
- ->find();
- if ($order == false) {
- return false;
- }
- foreach ($data['addrlist'] as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
- }
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] = $data['companyNo'];
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = $data['arrtime'];
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- // $outCode = makeNo("CK");
- // $out = [
- // "orderCode" => $orderCode,
- // "outCode" => $outCode,
- // "apply_id"=>$data['rm'],
- // "apply_name"=>$data['ri'],
- // "addrid" => $vmp,
- // "post_name" => "",
- // "post_code" => "",
- // "post_fee" => 0,
- // "sendtime" => date("Y-m-d H:i:s"),
- // "send_num" => $value['receipt_quantity'],
- // "check_num" => 0,
- // "error_num" => 0,
- // "wsm_code" => "",
- // "order_type" => 4,
- // "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) {
- // return false;
- // }
- // $order['send_num'] += $value['receipt_quantity'];
- // $order['wsend_num'] -= $value['receipt_quantity'];
- // if ($order['wsend_num'] < 0) {
- // return false;
- // }
- // $ups = Db::name("order_num")->save($order);
- // if ($ups) {
- // $tep = [
- // "cgdNo" => $order['cgdNo'],
- // "outCode" => $outCode,
- // "send_num" => $value['receipt_quantity'],
- // "status" => 1,
- // "addtime" => date("Y-m-d H:i:s"),
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- // $sen = Db::name("order_send")->save($tep);
- // if ($sen == false) {
- // return false;
- // }
- // }
- } else {
- return false;
- }
- }
- }
- }
- return true;
- }
- /**
- * @param $data
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function project_good($data){
- $good=Db::name('good')->alias("a")->leftJoin("good_platform b","a.spuCode=b.spuCode")->where(["b.skuCode"=>$data['skuCode'],"a.is_del"=>0,"b.is_del"=>0])->find();
- if($good==false){
- return false;
- }
- $goodlass = Db::name("good_ladder")->where(["skuCode"=>$data['skuCode'],"is_del"=>0,"status"=>1])->where([["min_num",
- "<=",$data['good_num']]])->order("min_num desc")->find();
- if($goodlass==false){
- return false;
- }
- $sale_price = $goodlass['sale_price'];
- $origin = Db::name("good_nake")->where([["spuCode","=",$data['spuCode']],["min_num","<=",$data['good_num']],
- ["is_del","=",0]])->order("min_num desc")->find();
- if($origin==false){
- return false;
- }
- $origin_price = $origin['nake_fee'];
- $orderCode=makeNo("QR");
- $datas=[
- "orderCode"=>$orderCode,
- "good_code"=>$data['spuCode'],
- "skuCode"=>$data['skuCode'],
- "customer_code"=>$data['customerNo'],
- "good_name"=>isset($good['good_name'])&&$good['good_name']!==''?$good['good_name']:'',
- "good_num"=>$data['good_num'],
- "cat_id"=>$good['cat_id'],
- "apply_id"=>$data['rm'],
- "apply_name"=>$data['ri'],
- "origin_price"=>$origin_price,
- "sale_price"=>$sale_price,
- "post_fee"=>0,
- "status"=>0,
- "send_num"=>0,
- "wsend_num"=>$data['good_num'],
- "send_status"=>1,
- "good_type"=>1,
- "send_type"=>$data['sendtype'],
- "supplierNo"=>$data['companyNo'],
- "is_del"=>0,
- "zxNo"=>$data["pgNo"],
- "platform_order"=>"",
- "platform_id"=>0,
- "remark"=>"",
- "is_stock"=>$good['is_stock'],
- "is_activity"=>0,
- "proof_id"=>0,
- "order_type"=>$good['is_stock']==1?2:4,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s"),
- 'total_price'=>round($sale_price*$data['good_num'],2),
- ];
- $datainfo = Db::name('sale')->insert($datas, true);
- if($datainfo>0) {
- $cgd=[
- "supplierNo"=>$good['supplierNo'],
- "companyNo"=>$data['companyNo'],
- "orderCode"=>$orderCode,
- "spuCode"=>$good['spuCode'],
- "skuCode"=>$good['skuCode'],
- "good_name"=>$good['good_name'],
- "sale_price"=>$origin_price,
- "total_fee"=>$origin_price*$data['good_num'],
- "pakge_fee"=>$good['packing_fee'],
- "cert_fee"=>$good['cert_fee'],
- "open_fee"=>$good['open_fee'],
- "cost_fee"=>$good['cost_fee'],
- "mark_fee"=>$good['mark_fee'],
- "demo_fee"=>$good['demo_fee'],
- "good_num"=>$data['good_num'],
- "good_type"=>1,
- "order_type"=>2,
- ];
- if($good['is_stock']==0) {
- $bol = $this->createCgd($cgd);
- if ($bol == false) {
- return false;
- }
- }
- if ($data['sendtype']==1&&!empty($data['addrlist'])) {
- $order = Db::name("order_num")->where(["orderCode" => $orderCode, "status" => 1])->where([["wsend_num", ">=", 0]])
- ->find();
- if ($order == false) {
- return false;
- }
- foreach ($data['addrlist'] as $value) {
- $temp = [];
- $addrs = [];
- if ($value['addr_code'] !== '' && is_array($value['addr_code'])) {
- $addrs['provice_code'] = $value['addr_code'][0];
- $addrs['city_code'] = $value['addr_code'][1];
- $addrs['area_code'] = $value['addr_code'][2];
- $addr = json_encode($addrs);
- } else {
- $addr = isset($value['addr_code']) ? $value['addr_code'] : '';
- }
- $temp['orderCode'] = $orderCode;
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $addr;
- $temp['customer_code'] =$data['companyNo'];
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = 0;
- $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = $data['arrtime'];
- $vmp = Db::name('order_addr')->insert($temp, true);
- if ($vmp > 0) {
- // if($good['is_stock']!=1){
- // $outCode = makeNo("CK");
- // $out = [
- // "orderCode" => $orderCode,
- // "outCode" => $outCode,
- // "apply_id"=>$data['rm'],
- // "apply_name"=>$data['ri'],
- // "addrid" => $vmp,
- // "post_name" => "",
- // "post_code" => "",
- // "post_fee" => 0,
- // "sendtime" => date("Y-m-d H:i:s"),
- // "send_num" => $value['receipt_quantity'],
- // "check_num" => 0,
- // "error_num" => 0,
- // "wsm_code" => "",
- // "order_type" => 4,
- // "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) {
- // return false;
- // }
- // $order['send_num'] += $value['receipt_quantity'];
- // $order['wsend_num'] -= $value['receipt_quantity'];
- // if ($order['wsend_num'] < 0) {
- // return false;
- // }
- // $ups = Db::name("order_num")->save($order);
- // if ($ups) {
- // $tep = [
- // "cgdNo" => $order['cgdNo'],
- // "outCode" => $outCode,
- // "send_num" => $value['receipt_quantity'],
- // "status" => 1,
- // "addtime" => date("Y-m-d H:i:s"),
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- // $sen = Db::name("order_send")->insert($tep);
- // if ($sen == false) {
- // return false;
- // }
- // }
- // }
- } else {
- return false;
- }
- }
- }
- }
- return true;
- }
- public function list()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where[] = ['is_del', "=", 0];
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode !== "") {
- $where[] = ['orderCode', "like", "%$orderCode%"];
- }
- $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name'])
- : "";
- if ($apply_name !== "") {
- $where[] = ['apply_name', "like", "%$apply_name%"];
- }
- $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name'])
- : "";
- if ($good_name !== "") {
- $where[] = ['good_name', "like", "%$good_name%"];
- }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code !== "") {
- $where[] = ['good_code', "like", "%$good_code%"];
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
- if ($customer_code !== "") {
- $where[] = ['customer_code', "like", "%$customer_code%"];
- }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo !== "") {
- $where[] = ['supplierNo', "like", "%$supplierNo%"];
- }
- $ordertype = isset($this->post['order_type']) && $this->post['order_type'] !== "" ? intval($this->post['order_type'])
- : "";
- if ($ordertype !== "") {
- $where[] = ['order_type', "=", $ordertype];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['status', "=", $status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- if ($start != "") {
- $where[] = ["addtime", '>=', $start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($end != "") {
- $where[] = ["addtime", '<=', $end];
- }
- $count = Db::name('sale')->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('sale')->where($where)->order("addtime desc")->page($page, $size)->select();
- $data = [];
- foreach ($list as $value) {
- if($value['order_type']==3|| $value['order_type']==4){
- $var = Db::name("good_zixun")->where(["spuCode"=>$value['good_code'],"is_del"=>0])->find();
- }else {
- $var = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $value['skuCode']])->find();
- }
- $value['can'] = isset($var['cat_id']) && $var['cat_id'] != 0 ? made($var['cat_id']) : [];
- $value['supplierName'] = '';
- if ($value['supplierNo'] != "") {
- $supplier = Db::name("business")->where(["companyNo" => $value['supplierNo']])->find();
- $value['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
- }
- $value['customerName'] = '';
- if ($value['customer_code'] != "") {
- $supplier = Db::name("customer_info")->where(["companyNo" => $value['customer_code']])->find();
- $value['customerName'] = isset($supplier['companyName']) ? $supplier['companyName'] : "";
- }
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- public function edit()
- {
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
- if (empty($etid)) {
- return error_show(1002, "未找到数据");
- }
- // $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- // if($orderCode==""){
- // return error_show(1002,"销售单code不能为空");
- // }
- $good_code = isset($this->post['good_code']) && $this->post['good_code'] !== "" ? trim($this->post['good_code']) : "";
- if ($good_code == "") {
- return error_show(1002, "商品code不能为空");
- }
- $ct = Db::name('good')->alias('a')->join('good_type b', 'b.good_code=a.good_code', 'left')
- ->where(['b.type_code' => $good_code])->find();
- if ($ct == "") {
- return error_show(1002, "未找到商品数据");
- }
- $customer_code = isset($this->post['customer_code']) && $this->post['customer_code'] !== "" ? trim($this->post['customer_code']) : "";
- if ($customer_code == "") {
- return error_show(1002, "客户code不能为空");
- }
- $customer = Db::name("customer_info")->where(["companyNo" => $customer_code])->find();
- if ($customer == false) {
- return error_show(1004, "未找到客户数据");
- }
- $supplierNo = $this->post['supplierNo'] && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo == "") {
- return error_show(1002, "参数supplierNo不能为空");
- }
- $supplier = Db::name("supplier")->where(["code" => $supplierNo])->find();
- if ($supplier == false) {
- return error_show(1004, "未找到平台供应商数据");
- }
- $apply_id = GetUserInfo($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'] : "";
- // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim
- //($this->post['good_name']) : "";
- // $good_num = isset($this->post['good_num']) && $this->post['good_num'] !== "" ? intval
- //($this->post['good_num']) : "";
- // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !== "" ? intval
- // ($this->post['origin_price']) : "";
- // $sale_price = isset($this->post['sale_price']) && $this->post['sale_price'] !== "" ? trim($this->post['sale_price']) : "";
- // $total_price = isset($this->post['total_price']) && $this->post['total_price'] !== "" ? trim($this->post['total_price']) : "";
- // $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? trim($this->post['post_fee']) : "";
- // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- if ($vr == "") {
- return error_show(1002, "参数order_addr不能为空");
- }
- $vi = isset($this->post['good_stock']) && $this->post['good_stock'] !== "" ? $this->post['good_stock'] : "";
- if ($vi == "") {
- return error_show(1002, "参数good_stock不能为空");
- }
- $good_num = intval(array_sum(array_column($vi, "num")));
- Db::startTrans();
- try {
- $datn = [
- "id" => $id,
- "good_code" => $good_code,
- "customer_code" => $customer_code,
- "good_num" => $good_num,
- "supplierNo" => $supplierNo,
- "apply_id" => $rm,
- "apply_name" => $ri,
- "is_del" => 0,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datninfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($datn);
- if ($datninfo > 0) {
- $stn = ["order_code"=>$etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stn,"XSQRD",$etid['status'],$datn);
- $order=["order_type"=>'XSQRD',"order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$etid['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- foreach ($vi as $ion) {
- $iten = [];
- isset($ion['id']) && $ion['id'] !== "" ? $iten['id'] = $ion['id'] : '';
- $iten['orderCode'] = $etid['orderCode'];
- $iten['wsm_code'] = $ion['wsm_code'];
- $iten['stock_id'] = 0;
- $iten['num'] = $ion['num'];
- $iten['status'] = 1;
- $iten['sale_price'] = $ct['original_price'];
- isset($ion['id']) && $ion['id'] !== "" ? '' : $iten['addtime'] = date("Y-m-d H:i:s");
- $iten['updatetime'] = date("Y-m-d H:i:s");
- $vp = Db::name('sale_info')->save($iten);
- if ($vp == false)
- {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- foreach ($vr as $value) {
- $temp = [];
- isset($value['id']) && $value['id'] !== "" ? $temp['id'] = $value['id'] : '';
- $temp['orderCode'] = $etid['orderCode'];
- $temp['contactor'] = $value['contactor'];
- $temp['mobile'] = $value['mobile'];
- $temp['addr'] = $value['addr'];
- $temp['addr_code'] = $value['addr_code'];
- $temp['customer_code'] = $customer_code;
- $temp['receipt_quantity'] = $value['receipt_quantity'];
- $temp['post_fee'] = 0;
- $temp['is_del'] = $value['is_del'];
- isset($value['id']) && $value['id'] !== "" ? '' : $temp['addtime'] = date("Y-m-d H:i:s");
- $temp['updatetime'] = date("Y-m-d H:i:s");
- $temp['arrive_time'] = date("Y-m-d H:i:s");
- $dat = Db::name('order_addr')->save($temp);
- if ($dat == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- Db::commit();
- return error_show(0, "更新成功");
- }
- Db::rollback();
- return error_show(1002, "更新失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function info()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- //->field('good_code,good_name,good_num,customer_code,orderCode')
- $einfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
- if (empty($einfo)) {
- return error_show(1002, "未找到销售订单数据");
- }
- $info = Db::name('sale_diff')->where(['orderCode' => $einfo['orderCode']])->select();
- //$de = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
- $dm = Db::name('order_return')->where(['orderCode' => $einfo['orderCode']])->select();
- $dk = Db::name('order_back')->where(['orderCode' => $einfo['orderCode']])->select();
- $sa = Db::name('sale_return')->where(['orderCode' => $einfo['orderCode']])->select();
- if($einfo['order_type']==3|| $einfo['order_type']==4){
- $goon = Db::name("good_zixun")->where(["spuCode"=>$einfo['good_code'],"is_del"=>0])->find();
- }else {
- $goon = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' => $einfo['skuCode']])->find();
- }
- if ($goon==false) {
- return error_show(1003, "未找到商品数据");
- }
- $int = isset($goon['cat_id']) && $goon['cat_id'] != 0 ? made($goon['cat_id']) : [];
- $in = Db::name('customer_info')->where(['companyNo' => $einfo['customer_code']])->field('companyName')->find();
- // ->field('addr,contactor,mobile,receipt_quantity,arrive_time')
- $einfo['supplierName'] = '';
- if ($einfo['supplierNo'] != "") {
- $supplier = Db::name("bussiness")->where(["companyNo" => $einfo['supplierNo']])->find();
- $einfo['supplierName'] = isset($supplier['company']) ? $supplier['company'] : "";
- }
- $fo = Db::name('order_addr')->where(['orderCode' => $einfo['orderCode'], 'is_del' => 0])->select();
- $bum = Db::name('order_out')->where(['orderCode' => $einfo['orderCode']])->select();
- $ins = [];
- if (!empty($bum)) {
- foreach ($bum as $stn) {
- $so = Db::name('order_addr')->where(['id' => $stn['addrid']])->find();
- $addr = GetAddr($so['addr_code']);
- $stn['addr_info'] = $addr;
- $stn['add_code'] = json_decode($so['addr_code'], true);
- $stn['addr'] = $so['addr'];
- $stn['contact'] = $so['contactor'];
- $stn['mobile'] = $so['mobile'];
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
- ->where(["a.wsm_code" => $stn['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
- $stn['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
- $stn['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- $stn['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
- $ins[] = $stn;
- }
- }
- $addrs = [];
- if (!empty($fo)) {
- foreach ($fo as $value) {
- $value['addr_info'] = "";
- $value['send_num'] = 0;
- if ($value['addr_code'] != "") {
- $addr = GetAddr($value['addr_code']);
- $value['addr_info'] = $addr;
- $value['addr_code'] = json_decode($value['addr_code'], true);
- $send = Db::name("order_out")->where(['addrid' => $value['id'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
- $value['send_num'] = $send ?? 0;
- }
- $value['wsend_num'] = $value['receipt_quantity'] - $value['send_num'];
- $addrs[] = $value;
- }
- }
- //->field('num,sale_price,wsm_code,stock_id')
- $st = Db::name('sale_info')->where(['orderCode' => $einfo['orderCode']])->select();
- $data = [];
- if (!empty($fo)) {
- foreach ($st as $value) {
- $value['wsm_name'] = "";
- $value['wsm_supplier'] = "";
- $value['wsm_supplierNo'] = "";
- $value['usable_stock'] = 0;
- $value['send_num'] = 0;
- if ($value['wsm_code'] != "") {
- $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b", "a.supplierNo=b.code")
- ->where(["a.wsm_code" => $value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
- $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
- $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
- $dn = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $einfo['good_code']])->find();
- $value['usable_stock'] = isset($dn['usable_stock']) ? $dn['usable_stock'] : "0";
- $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code'], 'orderCode' => $einfo['orderCode']])->sum("send_num");
- $value['send_num'] = $send ?? 0;
- }
- $value['wsend_num'] = $value['num'] - $value['send_num'];
- $data[] = $value;
- }
- }
- $einfo['info'] = $data;
- $einfo['companyName'] = isset($in['companyName']) ? $in['companyName'] : "";
- $einfo['addrs'] = $addrs;
- $einfo['orderout'] = $ins;
- $einfo['can'] = $int;
- $einfo['salediff'] = $info;
- //$einfo['orderout'] = $de;
- $einfo['orderreturn'] = $dm;
- $einfo['orderback'] = $dk;
- $einfo['salereturn'] = $sa;
- if (empty($einfo)) {
- return error_show(1002, "未找到销售订单数据");
- } else {
- return app_show(0, "获取成功", $einfo);
- }
- }
- public function del()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1002, "参数id不能为空");
- }
- $ed = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
- if (empty($ed)) {
- return error_show(1002, "未找到销售订单数据");
- }
- $str = Db::name('sale')->update(['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
- if ($str) {
- $stc = ["order_code"=>$id,"status"=>$ed['status'],"action_remark"=>'',"action_type"=>"delete"];
- ActionLog::logAdd($this->post['token'],$stc,"XSQRD",$ed['status'],['id' => $id, 'is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
- $order=["order_type"=>'XSQRD',"order_code"=>$ed['orderCode'],"order_id"=>$id,"order_status"=>$ed['status']];
- ProcessOrder::workdel($order);
- return error_show(0, "删除成功");
- } else {
- return error_show(1002, "删除失败");
- }
- }
- public function status()
- {
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status == "") {
- return error_show(1002, "订单状态不能为空");
- }
- $dio = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->find();
- if (empty($dio)) {
- return error_show(1002, "销售单信息未找到");
- }
- if ($status == 1 && $dio['order_type'] == 2) {
- $zxinfo = Db::name("consult")->where(["zxNo" => $dio['zxNo'], "is_del" => 0])->find();
- if ($zxinfo == false) {
- return error_show(1004, "未找到咨询单数据");
- }
- $gold['price'] = 0;
- if ($zxinfo['zx_type'] == 2) {
- if ($zxinfo['metals'] == "") {
- return error_show(1004, "未找到咨询单贵金属类型数据");
- }
- $metals = $zxinfo['metals'] == '18K' ? 1 : ($zxinfo['metals'] == '24K' ? 2 : 3);
- $gold = Db::name("gold_price")->where(["type" => $metals])->order("addtime desc")->find();
- if (empty($gold)) {
- return error_show(1004, "未找到咨询单贵金属类型数据");
- }
- $dio['gold_price'] = $gold['price'];
- }
- $wsm = Db::name("warehouse_info")->where(["supplierNo" => $zxinfo['gysNo'], "wsm_type" => 2])->find();
- if (empty($wsm)) {
- return error_show(1002, "供应商仓库未找到");
- }
- }
- $apply_id = GetUserInfo($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'] : "";
- Db::startTrans();
- try {
- $vmp =$dio['status'];
- $dio['status'] = $status;
- $dio['updatetime'] = date("Y-m-d H:i:s");
- $st = Db::name('sale')->save($dio);
- if ($st) {
- $stn = ["order_code"=>$dio['orderCode'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$stn, $dio['order_type'] == 2?"ZXQRD":"XSQRD",$dio['status'],$dio);
- $order=["order_type"=>$dio['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dio['orderCode'],"order_id"=>$id,"order_status"=>$dio['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- if ($status == 3 && $dio['order_type'] == 1) {
- $dn = Db::name('sale_info')->where(['orderCode' => $st['orderCode']])->select();
- foreach ($dn as $value) {
- $dm = Db::name('good_stock')->where(['wsm_code' => $value['wsm_code'], 'good_type_code' => $st['good_code']])->find();
- if ($dm == "") {
- Db::rollback();
- return error_show(1003, "未找到商品数据");
- }
- if ($value['num'] > $dm['usable_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $dm['usable_stock'] -= $value['num'];
- $dm['wait_out_stock'] += $value['num'];
- $send = Db::name("order_out")->where(["wsm_code" => $value['wsm_code']])->sum("send_num");
- $value['send_num'] = $send ?? 0;
- $value['wsend_num'] = $value['num'] - $value['send_num'];
- $Db = Db::name('good_stock')->update($dm);
- $Db['updatetime'] = date('Y-m-d H:i:s');
- if ($Db == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- }
- }
- if ($status == 1 && $dio['order_type'] == 2) {
- $cgd = makeNo("CG");
- $clll = [
- "cgdNo" => $cgd,
- "bkcode" => $dio['orderCode'],
- "wsm_code" => $wsm['wsm_code'],
- "cgder_id" => "0",
- "cgder" => $zxinfo['saler'],
- "good_code" => "GD-" . $zxinfo['cpNo'],
- "good_name" => $zxinfo['cpName'],
- "good_type_code" => $zxinfo['cpNo'],
- "good_num" => $dio['good_num'],
- "good_price" => $zxinfo['total_fee'],
- "total_fee" => round($zxinfo['total_fee'] * $dio['good_num'], 2),
- "pakge_fee" => $zxinfo['package_fee'],
- "cert_fee" => $zxinfo['cert_fee'],
- "open_fee" => $zxinfo['open_fee'],
- "delivery_fee" => $zxinfo['delivery_fee'],
- "mark_fee" => $zxinfo['mark_fee'],
- "teach_fee" => $zxinfo['cost_fee'],
- "demo_fee" => $zxinfo['demo_fee'],
- "nake_fee" => $zxinfo['bare_fee'],
- "weight" => isset($zxinfo['weight']) ? $zxinfo['weight'] : 0,
- "supplierNo" => $zxinfo['gysNo'],
- "supplier_name" => $zxinfo['gysname'],
- "gold_price" => $gold['price'],
- "send_num" => 0,
- "wsend_num" => $dio['good_num'],
- "remark" => '',
- "lasttime" => date("Y-m-d H:i:s"),
- "is_del" => 0,
- "status" => $dio['send_type'] == 1 ? 3 : 0,
- "order_type" => 2,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $cgin = Db::name("purchease_order")->insert($clll);
- // var_dump(Db::name("purchease_order")->getLastSql(),$clll);
- if ($cgin == false) {
- $stb = ["order_code"=>$cgd,"status"=> $clll['status'],"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stb,"xsd", $clll['status'],$stb);
- Db::rollback();
- return error_show(1002, "咨询采购单创建商品失败");
- }
- if ($dio['send_type'] == 1) {
- $addr = Db::name('order_addr')->where(["orderCode" => $dio['orderCode'], 'is_del' => 0])->select();
- foreach ($addr as $value) {
- $outCode = makeNo("CK");
- $data = [
- "wsm_code" => $wsm['wsm_code'],
- "orderCode" => $dio['orderCode'],
- "outCode" => $outCode,
- "order_type" => $dio['order_type'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $value['id'],
- "post_name" => '',
- "post_code" => '',
- "post_fee" => '',
- "sendtime" => date("Y-m-d H:i:s"),
- "send_num" => $value['receipt_quantity'],
- "check_num" => 0,
- "error_num" => 0,
- "status" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insert($data);
- if (!$datainfo) {
- $sti = ["order_code"=>$dio['orderCode'],"status"=> 0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$sti,"xsd",0,$sti);
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- }
- $wsm_in_code = makeNo("IC");
- $orin = [
- "wsm_in_code" => $wsm_in_code,
- "cgdNo" => $cgd,
- "wsm_code" => $wsm['wsm_code'],
- "wsm_reaper" => "",
- "send_num" => $dio['good_num'],
- "post_company" => '',
- "post_code" => '',
- "post_fee" => '',
- "sendtime" => date("Y-m-d H:i:s"),
- "apply_id" => $rm,
- "apply_name" => $ri,
- "wait_num" => 0,
- "status" => 4,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $win = Db::name("purchease_in")->insert($orin);
- if (!$win){
- $stv = ["order_code"=>$wsm_in_code,"status"=>4,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stv,"xsd",4,$stv);
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- $good = Db::name("good_stock")->where(["wsm_code" => $wsm['wsm_code'], "good_type_code" => $zxinfo['cpNo'], "is_del" => 0])->find();
- if (empty($good)) {
- $good = [
- "good_type_code" => $zxinfo['cpNo'],
- "wsm_code" => $wsm['wsm_code'],
- "usable_stock" => 0,
- "wait_out_stock" => 0,
- "total_stock" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s"),
- ];
- }
- $good['wait_out_stock'] += $dio['good_num'];
- $good['total_stock'] = $good['usable_stock'] + $good['wait_out_stock'];
- $good['updatetime'] = date("Y-m-d H:i:s");
- $upd = Db::name("good_stock")->save($good);
- if (!$upd) {
- $ste = ["order_code"=> $zxinfo['cpNo'],"status"=>0,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$ste,"xsd",0,$ste);
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- }
- }
- }
- Db::commit();
- return error_show(0, "订单状态更新成功");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function fee()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
- if ($id == "") {
- return error_show(1002, "参数id不能为空");
- }
- $etid = Db::name("sale")->where(["id" => $id, "is_del" => 0])->find();
- if (empty($etid)) {
- return error_show(1002, "未找到数据");
- }
- $vr = isset($this->post['order_addr']) && $this->post['order_addr'] !== "" ? $this->post['order_addr'] : "";
- if ($vr == "") {
- return error_show(1002, "参数order_addr不能为空");
- }
- Db::startTrans();
- try {
- $data = [
- "id" => $id,
- "status" => 2,
- "is_del" => 0,
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('sale')->where(['id' => $id, 'is_del' => 0])->save($data);
- if ($datainfo) {
- $stx = ["order_code"=> $etid['orderCode'],"status"=>$etid['status'],"action_remark"=>'',
- "action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stx,$etid['order_type'] == 2?"ZXQRD":"XSQRD",2,$data);
- $order=["order_type"=>$etid['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$etid['orderCode'],"order_id"=>$id,"order_status"=>$data['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- foreach ($vr as $value) {
- $tm = [];
- $tm['id'] = $value['id'];
- $tm['orderCode'] = $etid['orderCode'];
- $tm['post_fee'] = $value['post_fee'];
- $tm['updatetime'] = date("Y-m-d H:i:s");
- $dn = Db::name('order_addr')->save($tm);
- if ($dn == false) {
- Db::rollback();
- return error_show(1002, "更新失败");
- }
- }
- Db::commit();
- return error_show(0, "更新成功");
- }
- Db::rollback();
- return error_show(1003, "更新失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function out()
- {
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $outCode = makeNo("CK");
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode == "") {
- return error_show(1002, "参数orderCoder不能为空");
- }
- $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
- if ($der == "") {
- return error_show(1002, "未找到出库订单单号");
- }
- // $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
- // if ($wsm_code == "") {
- // return error_show(1002, "参数wsm_code不能为空");
- // }
- // $wsm = Db::name('sale_info')->where(['wsm_code' => $wsm_code, 'orderCode' => $der['orderCode']])->find();
- // if ($wsm == "") {
- // return error_show(1002, "未找到仓库编码");
- // }
- $post_name = isset($this->post['post_name']) && $this->post['post_name'] !== "" ? trim($this->post['post_name']) : "";
- if ($post_name == "") {
- return error_show(1002, "物流公司不能为空");
- }
- $post_code = isset($this->post['post_code']) && $this->post['post_code'] !== "" ? trim($this->post['post_code']) : "";
- if ($post_code == "") {
- return error_show(1002, "物流单号不能为空");
- }
- $post_fee = isset($this->post['post_fee']) && $this->post['post_fee'] !== "" ? intval($this->post['post_fee']) : "";
- if ($post_fee == "") {
- return error_show(1002, "物流费不能为空");
- }
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
- if ($send_num == "") {
- return error_show(1002, "发货数量不能为空");
- }
- if ($send_num > $der['wsend_num']) {
- return error_show(1002, "超出可发货数量");
- }
- $apply_id = GetUserInfo($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'] : "";
- $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
- $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
- if (empty($dr)) {
- return error_show(1003, "收货人信息未找到");
- }
- if ($dr['orderCode'] !== $orderCode) {
- return error_show(1002, "订单code不存在");
- }
- $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
- // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
- // $error_num = isset($this->post['error_num']) && $this->post['error_num'] !=="" ? $this->post['error_num'] :"";
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "1";
- //$order_type = isset($this->post['order_type']) && $this->post['order_type'] !=="" ? $this->post['order_type'] :"1";
- //$dn=Db::name('sale_info')->where(['wsm_code'=>$outCode])->find();
- Db::startTrans();
- try {
- $data = [
- "wsm_code" => "",
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "order_type" => $der['order_type'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $dr['id'],
- "post_name" => $post_name,
- "post_code" => $post_code,
- "post_fee" => $post_fee,
- "sendtime" => $sendtime,
- "send_num" => $send_num,
- "check_num" => 0,
- "error_num" => 0,
- "status" => $status,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insert($data,true);
- if ($datainfo>0) {
- $stx = ["order_code"=>$outCode,"status"=>$status,"action_remark"=>'',"action_type"=>"create"];
- ActionLog::logAdd($this->post['token'],$stx,$der['order_type']==1?"CKD":'ZXCKD',$status,$data);
- $order=["order_type"=>$der['order_type']==1?"CKD":'ZXCKD',"order_code"=>$outCode,"order_id"=>$datainfo,"order_status"=>$data['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- if ($status == 1) {
- $var = Db::name('sale_info')->where(['orderCode' => $orderCode, 'wsm_code' => $wsm_code])->find();
- if ($var == "") {
- return error_show(1002, "未找到数据");
- }
- // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
- //("send_num");
- $item =$der['status'];
- $der['send_num'] += $send_num;
- $der['wsend_num'] -= $send_num;//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
- $der['send_status'] = $der['send_num'] == 0 ? 1 : $der['wsend_num'] == 0 ? 3 : 2;
- $der['status'] = $der['send_num'] == 0 ? 3 : $der['wsend_num'] == 0 ? 5 : 4;
- $der['updatetime'] = date("Y-m-d H:i:s");
- $si = Db::name('sale')->save($der);
- if ($si == false) {
- Db::rollback();
- return error_show(1003, "更新失败");
- }
- $stx = ["order_code"=>$orderCode,"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stx,$der['order_type'] == 2?"ZXQRD":"XSQRD",$der['status'],$der);
- $order=["order_type"=>$der['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$orderCode,"order_id"=>$der['id'],"order_status"=>$data['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- $str = Db::name('good_stock')->where(['wsm_code' => $var['wsm_code'], 'good_type_code' => $der['good_code']])->find();
- if ($str == false) {
- Db::rollback();
- return error_show(1002, "商品数据未找到");
- }
- if ($send_num > $str['wait_out_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $str['wait_out_stock'] -= $send_num;
- $str['intra_stock'] += $send_num;
- $str['updatetime'] = date("Y-m-d H:i:s");
- $stre = Db::name('good_stock')->save($str);
- if ($stre == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- $good_data[]= ["stock_id"=>$str['id'],"type"=>2,'stock'=>$send_num,"stock_name"=>"wait_out_stock"];
- $good_data[]= ["stock_id"=>$str['id'],"type"=>1,'stock'=>$send_num,"stock_name"=>"intra_stock"];
- GoodLog::LogAdd($this->post['token'],$good_data,$der['order_type'] == 2?"ZXQRD":"XSQRD");
- }
- Db::commit();
- return error_show(0, "创建成功");
- } else {
- Db::rollback();
- return error_show(1003, "创建失败");
- }
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function customer()
- {
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
- if (empty($outCode)) {
- return error_show(1002, "销售订单编号不能为空");
- }
- $codeinfo = Db::name('order_out')->where(['outCode' => $outCode])->find();
- if ($codeinfo == "") {
- return error_show(1003, "未找到订单数据");
- }
- // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode']) :"";
- // if($orderCode==""){
- // return error_show(1002,"参数orderCoder不能为空");
- // }
- $dr = Db::name('sale')->where(['orderCode' => $codeinfo['orderCode']])->find();
- if ($dr == "") {
- return error_show(1002, "未找到销售订单");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? $this->post['status'] : "";
- if ($status == "") {
- return error_show(10002, "状态不能为空");
- }
- Db::startTrans();
- try {
- $time = $codeinfo['status'];
- $codeinfo['status'] = $status;
- $codeinfo['updatetime'] = date("Y-m-d H:i:s");
- $cust = Db::name('order_out')->save($codeinfo);
- if ($cust) {
- $stx = ["order_code"=>$outCode,"status"=>$time,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$stx,$codeinfo['order_type'] == 2?"ZXCKD":"CKD",$codeinfo['status'],$codeinfo);
- $order=["order_type"=>$codeinfo['order_type'] == 2?"ZXCKD":"CKD","order_code"=>$outCode,
- "order_id"=>$codeinfo['id'],"order_status"=>$codeinfo['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- if ($status == 1) {
- $stokc =Db::name("good_stock")->where(['spuCode'=>$codeinfo['spuCode'],"wsm_code"=>$codeinfo['wsm_code'],
- "is_del"=>0])->find();
- if($stokc==false){
- Db::rollback();
- return error_show(1002, "未找库存到数据");
- }else{
- if ($codeinfo['send_num'] > $stokc['usable_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $stokc['wait_out_stock']+=$codeinfo['send_num'];
- $stokc['usable_stock']-=$codeinfo['send_num'];
- $stokc['updatetime']=date("Y-m-d H:i:s");
- }
- $stoc= Db::name("good_stock")->save($stokc);
- if($stoc==false){
- Db::rollback();
- return error_show(1002, "库存更新失败");
- }
- // $send = Db::name("order_out")->where(["wsm_code" => $wsm_code, 'orderCode' => $orderCode])->sum
- //("send_num");
- $item =$dr['status'];
- $dr['send_num'] +=$codeinfo['send_num'];
- $dr['wsend_num'] -= $codeinfo['send_num'];//($der['send_num'])?$der['wsend_num'] =="" ? $der['send']
- $dr['send_status'] = $dr['send_num'] == 0 ? 1 : $dr['wsend_num'] == 0 ? 3 : 2;
- $dr['status'] = $dr['send_num'] == 0 ? 3 : $dr['wsend_num'] == 0 ? 5 : 4;
- $dr['updatetime'] = date("Y-m-d H:i:s");
- $si = Db::name('sale')->save($dr);
- if ($si == false) {
- Db::rollback();
- return error_show(1003, "更新失败");
- }
- $stx = ["order_code"=>$dr['orderCode'],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stx,$dr['order_type'] == 2?"ZXQRD":"XSQRD",$dr['status'],
- $dr);
- $order=["order_type"=>$dr['order_type'] == 2?"ZXQRD":"XSQRD","order_code"=>$dr['orderCode'],"order_id"=>$dr['id'],"order_status"=>$dr['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- $good_data[]= ["stock_id"=>$stoc['id'],"type"=>1,'stock'=>$codeinfo['send_num'],"stock_name"=>"wait_out_stock"];
- $good_data[]= ["stock_id"=>$stoc['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"usable_stock"];
- GoodLog::LogAdd($this->post['token'],$good_data,'CKD');
- }
- if ($status == 3) {
- $var = Db::name('good_stock')->where(['wsm_code' => $codeinfo['wsm_code'], 'good_type_code' => $dr['good_code']])->find();
- if ($var == false) {
- Db::rollback();
- return error_show(1002, "未找到商品数据");
- }
- if ($codeinfo['send_num'] > $var['intra_stock']) {
- Db::rollback();
- return error_show(1003, "超出在途库存数量");
- }
- $var['intra_stock'] -= $codeinfo['send_num'];
- $var['updatetime'] = date("Y-m-d H:i:s");
- $stre = Db::name('good_stock')->save($var);
- $good_data[]= ["stock_id"=>$var['id'],"type"=>2,'stock'=>$codeinfo['send_num'],"stock_name"=>"intra_stock"];
- GoodLog::LogAdd($this->post['token'],$good_data,$codeinfo['order_type'] == 2?"ZXCKD":"CKD");
- if ($stre == false) {
- Db::rollback();
- return error_show(1002, "状态更新失败");
- }
- }
- Db::commit();
- return error_show(0, "出库订单更新成功");
- } else {
- Db::rollback();
- return error_show(1003, "出库订单更新失败");
- }
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function difflist()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [];
- $cgdNo = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? trim($this->post['orderCode']) : "";
- if ($cgdNo != "") {
- $where[] = ['a.orderCode', "like", "%$cgdNo%"];
- }
- $diffNo = isset($this->post['diffCode']) && $this->post['diffCode'] != "" ? trim($this->post['diffCode']) : "";
- if ($diffNo != "") {
- $where[] = ['a.diffCode', "like", "%$diffNo%"];
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($status !== "") {
- $where[] = ['a.status', "=", $status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- if ($start != "") {
- $where[] = ["a.addtime", '>=', $start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($end != "") {
- $where[] = ["a.addtime", '<=', $end];
- }
- // $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !==""? intval($this->post['apply_name']):"";
- // if($apply_name!==""){
- // $where[]=['a.apply_name',"like","%$apply_name%"];
- // }
- $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
- if ($supplierNo != "") {
- $supplier = Db::name("supplier")->where([['code', "like", "%$supplierNo%"]])->column('code');
- // if(empty($supplier)){
- // return error_show(1004,"未找到供应商信息");
- // }
- $wsmcode = Db::name("sale")->where([
- "is_del" => 0, "supplierNo" => $supplier])->column("orderCode");
- $where[] = ['a.orderCode', "in", $wsmcode];
- }
- $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
- if($companyNo!=""){
- $where[]=['c.customer_code',"like","%$companyNo%"];
- }
- $count = Db::name('sale_diff')->alias('a')
- ->join("sale c", "c.orderCode=a.orderCode", "left")
- ->join("customer_info v", "v.companyNo=c.customer_code", "left")
- ->join("good b", "b.good_code=a.good_code", "left")
- ->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- //var_dump( Db::name('sale_diff')->getLastSql());
- $list = Db::name('sale_diff')->alias('a')
- ->join("sale c", "c.orderCode=a.orderCode", "left")
- ->join("customer_info v", "v.companyNo=c.customer_code", "left")
- ->join("good b", "b.good_code=a.good_kode", "left")
- ->where($where)->page($page, $size)->field("a.*,b.cat_id,c.customer_code,v.companyName")
- ->order("a.addtime desc")->select();
- $data = [];
- foreach ($list as $value) {
- $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
- $wsm = Db::name("sale")->alias("a")->Join("supplier b", "a.supplierNo=b.code", "left")->where
- (['a.orderCode' => $value['orderCode'], "a.is_del" => 0])->field("b.code,b.name")->find();
- $value['supplierNo'] = isset($wsm['code']) ? $wsm['code'] : "";
- $value['supplierName'] = isset($wsm['name']) ? $wsm['name'] : "";
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffcheck()
- {
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1004, "参数id不能为空");
- }
- $info = Db::name("sale_diff")->where(["id" => $id])->find();
- if (empty($info)) {
- return error_show(1004, "订单数据未找到");
- }
- $is_act = isset($this->post['is_act']) && $this->post['is_act'] !== "" ? intval($this->post['is_act']) : "";
- if ($is_act === '') {
- return error_show(1004, "参数is_act不能为空");
- }
- $customer_remark = isset($this->post['customer_remark']) && $this->post['customer_remark'] !== "" ? trim($this->post['customer_remark']) : "";
- if ($customer_remark === '') {
- return error_show(1004, "参数customer_remark不能为空");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "2";
- $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
- $item = $info['status'];
- $info['is_act'] = $is_act;
- $info['customer_remark'] = $customer_remark;
- $info['status'] = $status;
- $info['remark'] = $remark;
- $info['updatetime'] = date("Y-m-d H:i:s");
- $up = Db::name("sale_diff")->save($info);
- if ($up) {
- $stx = ["order_code"=>$info["orderCode"],"status"=>$item,"action_remark"=>'',"action_type"=>"edit"];
- ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
- $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- return app_show(0, "更新成功");
- } else {
- return error_show(1003, "更新失败");
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffstatus()
- {
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1004, "参数id不能为空");
- }
- $info = Db::name("sale_diff")->where(["id" => $id])->find();
- if (empty($info)) {
- return error_show(1004, "订单数据未找到");
- }
- $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "3";
- $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
- $ite=$info['status'];
- $info['status'] = $status;
- $info['remark'] = $remark;
- $info['updatetime'] = date("Y-m-d H:i:s");
- $up = Db::name("sale_diff")->save($info);
- if ($up) {
- $stx = ["order_code"=>$info["orderCode"],"status"=>$ite,"action_remark"=>'',"action_type"=>"status"];
- ActionLog::logAdd($this->post['token'],$stx,"QRGCD",$info['status'],$info);
- $order=["order_type"=>"QRGCD","order_code"=>$info["orderCode"],"order_id"=>$info['id'],"order_status"=>$info['status']];
- ProcessOrder::AddProcess($this->post['token'],$order);
- return app_show(0, "更新成功");
- } else {
- return error_show(1003, "更新失败");
- }
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function diffinfo()
- {
- $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- if ($id === "") {
- return error_show(1004, "参数id不能为空");
- }
- $info = Db::name('sale_diff')->alias('a')->join("good b", "b.good_code=a.good_kode", "left")->where
- (["a.id" => $id])->field("a.*,b.cat_id")->find();
- if (empty($info)) {
- return error_show(1004, "订单数据未找到");
- }
- $info['can'] = isset($info['cat_id']) && $info['cat_id'] !== 0 ? made($info['cat_id']) : [];
- return app_show(0, "获取成功", $info);
- }
- public function saleout(){
- $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
- $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
- $where= [];
- $orderCode=isset($this->post['orderCode']) && $this->post['orderCode'] !=="" ? trim($this->post['orderCode'])
- :"";
- if($orderCode !==""){
- $where[]=['a.orderCode',"like","%$orderCode%"];
- }
- $order_type=isset($this->post['order_type']) && $this->post['order_type'] !=="" ? trim($this->post['order_type'])
- :"";
- if($order_type !==""){
- $where[]=['a.order_type',"=",$order_type];
- }
- $outCode=isset($this->post['outCode']) && $this->post['outCode'] !=="" ? trim($this->post['outCode'])
- :"";
- if($outCode !==""){
- $where[]=['a.outCode',"like","%$outCode%"];
- }
- $apply_name=isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name'])
- :"";
- if($apply_name !==""){
- $where[]=['a.apply_name',"like","%$apply_name%"];
- }
- $good_code=isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code'])
- :"";
- if($good_code !==""){
- $where[]=['b.good_code',"like","%$good_code%"];
- }
- $good_name=isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name'])
- :"";
- if($good_name !==""){
- $where[]=['b.good_name',"like","%$good_name%"];
- }
- $status=isset($this->post['status']) && $this->post['status'] !=="" ? trim($this->post['status']):"";
- if($status !==""){
- $where[]=['a.status',"=",$status];
- }
- $start = isset($this->post['start']) && $this->post['start'] !=="" ? $this->post['start'] :"";
- if($start !=""){
- $where[]= ["a.addtime",'>=',$start];
- }
- $end = isset($this->post['end']) && $this->post['end'] !=="" ? $this->post['end'] :"";
- if($end !=""){
- $where[]= ["a.addtime",'<=',$end];
- }
- $companyNo =isset($this->post['companyNo']) &&$this->post['companyNo'] !=="" ? trim($this->post['companyNo']):"";
- if($companyNo!=""){
- $where[]=['b.customer_code',"like","%$companyNo%"];
- }
- $count = Db::name('order_out')->alias('a')
- ->join("sale b", "b.orderCode=a.orderCode", "left")
- ->join("customer_info v", "v.companyNo=b.customer_code", "left")
- //->join("good n","n.good_code=b.good_code","left")
- ->where($where)->count();
- $total = ceil($count / $size);
- $page = $page >= $total ? $total : $page;
- $list = Db::name('order_out')->alias('a')->join("sale b", "b.orderCode=a.orderCode", "left")
- ->join("customer_info v", "v.companyNo=b.customer_code", "left")
- //->join("good n","n.good_code=b.good_code","left")
- ->field("a.*,b.good_name,b.good_code,b.supplierNo,b.customer_code,v.companyName,b.origin_price,b.sale_price,b.total_price")
- ->where($where)->order("addtime desc")->page($page, $size)->select();
- $data=[];
- foreach ($list as $value) {
- $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
- ->where(["k.wsm_code" => $value['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
- $addr = Db::name("order_addr")->where(["id" => $value['addrid']])->find();
- $good = Db::name("good_type")->alias("b")->join("good a", "a.good_code = b.good_code", "left")
- ->where(["type_code" => $value['good_code']])->field('cat_id')->find();
- $value['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
- $value['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- $value['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
- $value['addr'] = isset($addr['addr']) ? $addr['addr'] : "";
- $value['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
- $value['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
- $value['can'] = isset($good['cat_id']) && $good['cat_id'] != 0 ? made($good['cat_id']) : [];
- $data[] = $value;
- }
- return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
- }
- public function outinfo()
- {
- $outCode = isset($this->post['outCode']) && $this->post['outCode'] !== "" ? trim($this->post['outCode']) : "";
- if ($outCode == "") {
- return error_show(1002, "参数outcode不能为空");
- }
- $codeinfo = Db::name("order_out")->where(['outCode' => $outCode])->find();
- if (empty($codeinfo)) {
- return error_show(1002, "未找到出库数据");
- }
- $item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
- if($item['order_type']==3|| $item['order_type']==4){
- // $good=Db::name("good_zixun")->where(["spuCode"=>$good_code])->find();
- // if($good==false){
- // return error_show(1004,"未找到商品数据");
- // }
- $goodinfo = Db::name("consult_bids")->where(["spuCode"=>$item['good_code'],"is_del"=>0])->find();
- if($goodinfo==false){
- return error_show(1004,"未找到商品数据");
- }
- }else{
- $goodinfo = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' =>$item['skuCode']])->find();
- if ($goodinfo == false) {
- return error_show(1002, "未找到商品数据");
- }
- }
- $int = isset($goodinfo['cat_id']) && $goodinfo['cat_id'] != 0 ? made($goodinfo['cat_id']) : [];
- // $wsmcode = Db::name("warehouse_info")->alias("k")->leftJoin("supplier c", "k.supplierNo=c.code")
- // ->where(["k.wsm_code" => $codeinfo['wsm_code']])->field("k.name as wsm_name,c.name,c.code")->find();
- $addr = Db::name("order_addr")->where(["id" => $codeinfo['addrid']])->find();
- //$item = Db::name("sale")->where(['orderCode' => $codeinfo['orderCode']])->find();
- $codeinfo['good_name'] = isset($item['good_name']) ? $item['good_name'] : "";
- $codeinfo['good_num'] = isset($item['good_num']) ? $item['good_num'] : "";
- $codeinfo['good_code'] = isset($item['good_code']) ? $item['good_code'] : "";
- $codeinfo['origin_price'] = isset($item['origin_price']) ? $item['origin_price'] : "";
- $codeinfo['sale_price'] = isset($item['sale_price']) ? $item['sale_price'] : "";
- $codeinfo['total_price'] = isset($item['total_price']) ? $item['total_price'] : "";
- // $codeinfo['wsm_name'] = isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name'] : "";
- // $codeinfo['wsm_supplier'] = isset($wsmcode['name']) ? $wsmcode['name'] : "";
- // $codeinfo['wsm_supplierNo'] = isset($wsmcode['code']) ? $wsmcode['code'] : "";
- $codeinfo['addr'] = GetAddr($addr['addr_code']);
- $codeinfo['addr'] .= isset($addr['addr']) ? $addr['addr'] : "";
- $codeinfo['addr_code'] = isset($addr['addr_code']) ? $addr['addr_code'] : "";
- $codeinfo['contactor'] = isset($addr['contactor']) ? $addr['contactor'] : "";
- $codeinfo['mobile'] = isset($addr['mobile']) ? $addr['mobile'] : "";
- $codeinfo['can'] = $int;
- return app_show(0, "获取成功", $codeinfo);
- }
- public function outadd(){
- $token = isset($this->post['token']) && $this->post['token'] !== "" ? trim($this->post['token']) : "";
- $outCode = makeNo("CK");
- $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] !== "" ? trim($this->post['orderCode']) : "";
- if ($orderCode == "") {
- return error_show(1002, "参数orderCoder不能为空");
- }
- $der = Db::name('sale')->where(['orderCode' => $orderCode])->find();
- if ($der == "") {
- return error_show(1002, "未找到出库订单单号");
- }
- $send_num = isset($this->post['send_num']) && $this->post['send_num'] !== "" ? $this->post['send_num'] : "";
- if ($send_num == "") {
- return error_show(1002, "发货数量不能为空");
- }
- if ($send_num > $der['wsend_num']) {
- return error_show(1002, "超出可发货数量");
- }
- $contactor = isset($this->post['contactor'])&&$this->post['contactor']!="" ? trim($this->post['contactor']):"";
- if($contactor==""){
- return error_show(1002, "参数contactor不能为空");
- }
- $mobile = isset($this->post['mobile'])&&$this->post['mobile']!="" ? trim($this->post['mobile']):"";
- if($mobile==""){
- return error_show(1002, "参数mobile不能为空");
- }
- $addr = isset($this->post['addr'])&&$this->post['addr']!="" ? trim($this->post['addr']):"";
- if($addr==""){
- return error_show(1002, "参数addr不能为空");
- }
- $addr_code = isset($this->post['addr_code'])&&$this->post['addr_code']!="" ? trim($this->post['addr_code']):"";
- if($addr_code==""){
- return error_show(1002, "参数addr_code不能为空");
- }
- $apply_id = GetUserInfo($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'] : "";
- // $addrid = isset($this->post['addrid']) && $this->post['addrid'] !== "" ? intval($this->post['addrid']) : "";
- // $dr = Db::name('order_addr')->where(['id' => $addrid, 'is_del' => 0])->find();
- // if (empty($dr)) {
- // return error_show(1003, "收货人信息未找到");
- // }
- // if ($dr['orderCode'] !== $orderCode) {
- // return error_show(1002, "订单code不存在");
- // }
- $sendtime = isset($this->post['sendtime']) && $this->post['sendtime'] !== "" ? $this->post['sendtime'] : date("Y-m-d H:i:s");
- $order =Db::name("order_num")->where(["orderCode"=>$orderCode,"status"=>1])->where([["wsend_num",">=",0]])
- ->select()->toArray();
- if(empty($order)){
- return error_show(1004,"未找到可以发货得采购单数据");
- }
- Db::startTrans();
- try {
- $addrlst =[
- "orderCode"=>$orderCode,
- "addr"=>$addr,
- "addr_code"=>json_encode($addr_code),
- "contactor"=>$contactor,
- "mobile"=>$mobile,
- "customer_code"=>$der['customer_code'],
- "post_fee"=>$der['post_fee'],
- "arrive_time"=>$sendtime,
- "receipt_quantity"=>$send_num,
- "is_del"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $addrid = Db::name("order_addr")->insert($addrlst,true);
- if($addrid>0){
- $data = [
- "wsm_code" => "",
- "orderCode" => $orderCode,
- "outCode" => $outCode,
- "order_type" => $der['order_type'],
- "apply_id" => $rm,
- "apply_name" => $ri,
- "addrid" => $addrid,
- "post_name" => "",
- "post_code" =>"",
- "post_fee" => "",
- "sendtime" => $sendtime,
- "send_num" => $send_num,
- "check_num" => 0,
- "error_num" => 0,
- "status" => 1,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ];
- $datainfo = Db::name('order_out')->insert($data,true);
- if($datainfo>0){
- $num = $send_num;
- foreach ($order as $val){
- $tep=[];
- $ornum=0;
- if($val['wsend_num']>=$num){
- $val['wsend_num']-=$num;
- $val['send_num']+=$num;
- $ornum =$num;
- $num=0;
- }else{
- $num-=$val['wsend_num'];
- $val['send_num']+=$val['wsend_num'];
- $ornum =$val['wsend_num'];
- $val['wsend_num']=0;
- }
- $or =Db::name("order_num")->save($val);
- if($or==false){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- $tep=[
- "cgdNo"=>$val['cgdNo'],
- "outCode"=>$outCode,
- "send_num"=>$ornum,
- "status"=>1,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $sen=Db::name("order_send")->save($tep);
- if($sen==false){
- Db::rollback();
- return error_show(1002,"发货地址添加创建失败");
- }
- if($num==0){
- break;
- }
- }
- Db::commit();
- return app_show(0,"出库单新建成功",["outCode"=>$outCode]);
- }
- }
- Db::rollback();
- return error_show(1004,"出库单新建失败");
- } catch (Exception $e) {
- Db::rollback();
- return error_show(1005, $e->getMessage());
- }
- }
- public function outSend(){
- $outCode=isset($this->post['outCode'])&& $this->post['outCode']!=""? trim($this->post['outCode']):"";
- if($outCode==""){
- return error_show(1004,"参数outCode不能为空");
- }
- $outinfo = Db::name("order_out")->where(["outCode"=>$outCode])->find();
- if($outinfo==false){
- return error_show(1004,"发货数据未找到");
- }
- $post_name = isset($this->post['post_name']) &&$this->post['post_name']!="" ? trim($this->post['post_name']):"";
- if($post_name==""){
- return error_show(1004,"参数post_name不能为空");
- }
- $post_code = isset($this->post['post_code']) &&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
- if($post_code==""){
- return error_show(1004,"参数post_code不能为空");
- }
- $post_fee = isset($this->post['post_fee']) && $this->post['post_fee']!="" ? floatval($this->post['post_fee']):"";
- $outinfo['post_name'] = $post_name;
- $outinfo['post_code'] = $post_code;
- $outinfo['post_fee'] = $post_fee;
- $outinfo['sendtime'] = date("Y-m-d H:i:s");
- $outinfo['status'] = 2;
- $outinfo['updatetime'] = date("Y-m-d H:i:s");
- try{
- $up =Db::name("order_out")->save($outinfo);
- if($up){
- $stokc =Db::name("good_stock")->where(['spuCode'=>$outinfo['spuCode'],"wsm_code"=>$outinfo['wsm_code'],
- "is_del"=>0])->find();
- if($stokc==false){
- Db::rollback();
- return error_show(1002, "未找库存到数据");
- }else{
- if ($outinfo['send_num'] > $stokc['wait_out_stock']) {
- Db::rollback();
- return error_show(1002, "超出库存数量");
- }
- $stokc['wait_out_stock']-=$outinfo['send_num'];
- $stokc['intra_stock']+=$outinfo['send_num'];
- $stokc['updatetime']=date("Y-m-d H:i:s");
- }
- $stoc= Db::name("good_stock")->save($stokc);
- if($stoc==false){
- Db::rollback();
- return error_show(1002, "库存更新失败");
- }
- Db::commit();
- return app_show(0,"发货成功");
- }else{
- Db::rollback();
- return error_show(1004,"发货失败");
- }
- }catch (\Exception $e){
- Db::rollback();
- return error_show(1004,$e->getMessage());
- }
- }
- public function RelaCgd($outinfo){
- $der = Db::name('sale')->where(['orderCode' => $outinfo['orderCode']])->find();
- if ($der == "") {
- return false;
- }
- if($der['is_stock']==1){
- $cgd = Db::name("order_bk")->where([["spuCode","=",$der['spuCode']],["is_del","=",0],["balance_num",">",0]])
- ->select()->toArray();
- if(empty($cgd)){
- return false;
- }
- $send =$outinfo['send_num'];
- $outsend=[];
- foreach ($cgd as $value){
- $temp=[];
- if($value['balance_num']>=$send){
- $value['balance_num']-=$send;
- $value['merge_num']+=$send;
- $send=0;
- $temp['send_num'] =$send;
- }else{
- $value['balance_num'] =0;
- $value['merge_num']+=$value['balance_num'];
- $send -= $value['balance_num'];
- $temp['send_num'] =$value['balance_num'];
- }
- $value['status'] = $value['balance_num']==0 ?2:$value['merge_num']==0?0:1 ;
- $value['updatetime'] = date("Y-m-d H:i:s");
- $bk = Db::name("order_bk")->save($value);
- if($bk==false){
- return false;
- }
- $temp['cgdNo'] = $value['cgdNo'];
- $temp['outCode'] = $outinfo['outCode'];
- $temp['status'] = 1;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $outsend[]=$temp;
- $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"cgdNo"=>$value['cgdNo'],"spuCode"=>$der['spuCode'],"status"=>1])->find();
- if($order==false){
- $order=[
- "orderCode"=>$der['orderCode'],
- "cgdNo"=>$value['cgdNo'],
- "spuCode"=>$der['spuCode'],
- "good_num"=>$der['good_num'],
- "wsend_num"=>$der['good_num']-$temp['send_num'],
- "send_num"=>$temp['send_num'],
- "status"=>1,
- "source"=>1
- ];
- }else{
- $order['wsend_num']-=$temp['send_num'];
- $order['send_num']+=$temp['send_num'];
- }
- if($order['wsend_num']<0){
- return false;
- }
- $up =Db::name("order_num")->save($order);
- if($up==false){
- return false;
- }
- if($send==0){
- break;
- }
- }
- if(empty($temp)){
- return false;
- }
- $insert = Db::name("order_send")->insertAll($outsend);
- if($insert){
- return true;
- }else{
- return false;
- }
- }else{
- $order = Db::name("order_num")->where(["orderCode"=>$der['orderCode'],"spuCode"=>$der['spuCode'],
- "status"=>1])->find();
- if($order==false){
- return false;
- }else{
- if($outinfo['send_num']> $order['wsend_num']){
- return false;
- }
- $order['wsend_num']-=$outinfo['send_num'];
- $order['send_num']+=$outinfo['send_num'];
- if($order['wsend_num']<0){
- return false;
- }
- $up =Db::name("order_num")->save($order);
- if($up==false){
- return false;
- }
- $temp=[];
- $temp['cgdNo'] = $order['cgdNo'];
- $temp['outCode'] = $outinfo['outCode'];
- $temp['send_num'] =$outinfo['send_num'];
- $temp['status'] = 1;
- $temp['addtime']=date("Y-m-d H:i:s");
- $temp['updatetime']=date("Y-m-d H:i:s");
- $insert = Db::name("order_send")->insert($temp);
- if($insert){
- return true;
- }else{
- return false;
- }
- }
- }
- }
- public function addother(){
- $orderCode =isset($this->post['orderCode']) && $this->post['orderCode']!=""?trim($this->post['orderCode']):"";
- if($orderCode==""){
- return error_show(1004,"参数orderCode不能为空");
- }
- $order =Db::name("sale")->where(["orderCode"=>$orderCode,"is_del"=>0])->find();
- if($order==false){
- return error_show(1004,"未找到订单数据");
- }
- $paytime =isset($this->post['paytime'])&&$this->post['paytime']!=""? $this->post['paytime']:"";
- $workNo =isset($this->post['workNo'])&&$this->post['workNo']!=""? trim($this->post['workNo']):"";
- $platform_order =isset($this->post['platform_order'])&&$this->post['platform_order']!=""? trim($this->post['platform_order']):"";
- $paytime==""?"":$order['paytime']=$paytime;
- $order['workNo']=$workNo;
- $order['platform_order']=$platform_order;
- $order['updatetime']=date("Y-m-d H:i:s");
- $sa=Db::name("sale")->save($order);
- if($sa){
- return app_show(0,"更新成功");
- }else{
- return error_show(1004,"更新失败");
- }
- }
- public function getPrice(){
- $skuCode=isset($this->post['skuCode'])&&$this->post['skuCode']!=""?trim($this->post['skuCode']):"";
- if($skuCode===""){
- return error_show(1003,"参数skuCode不能为空");
- }
- $is_activity=isset($this->post['is_activity'])&&$this->post['is_activity']!==""?intval($this->post['is_activity'])
- :"";
- if($is_activity===""){
- return error_show(1003,"参数is_activity不能为空");
- }
- $sale_num=isset($this->post['sale_num'])&&$this->post['sale_num']!==""?intval($this->post['sale_num']):"";
- if($sale_num===""){
- return error_show(1003,"参数sale_num不能为空");
- }
- $ct = Db::name('good_platform')->alias('a')->join('good b', 'b.spuCode=a.spuCode', 'left')
- ->where(['a.skuCode' =>$skuCode])->find();
- if ($ct == false) {
- return error_show(1002, "未找到商品数据");
- }
- $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["min_num","<=", $sale_num],["is_del","=",
- 0]])->order("min_num desc")->find();
- if($origin==false){
- $origin = Db::name("good_nake")->where([["spuCode","=",$ct['spuCode']],["is_del","=",
- 0]])->order("min_num asc")->find();
- return error_show(1003,"不满足成本最低阶梯数量{$origin['min_num']}");
- }
- 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.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']>$sale_num){
- return error_show(1003,"商品不满足活动价起订量{$act['moq_num']}");
- }
- if($act['activity_stock']<$sale_num){
- return error_show(1003,"商品活动库存剩余{$act['moq_num']}");
- }
- return app_show(0,"获取成功",['sale_price'=>$act['activity_price']]);
- }else{
- $good = Db::name("good_ladder")->where(["skuCode"=>$skuCode,"is_del"=>0,"status"=>1])->order("min_num desc")
- ->select()->toArray();
- if(empty($good)){
- return error_show(1003,"未找到相关阶梯价格");
- }
- $lastnum=0;
- $lastprice=0;
- foreach ($good as $value){
- if($value['min_num']>$sale_num){
- $lastnum=$value['min_num'];
- $lastprice=0;
- continue;
- }else{
- $lastnum=0;
- $lastprice=$value['sale_price'];
- break;
- }
- }
- if($lastnum==0){
- return app_show(0,"获取成功",['sale_price'=>$lastprice]);
- }else{
- return error_show(1003,"商品不满足起订量{$lastnum}");
- }
- }
- }
- }
|