Goodup.php 179 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ChangeLog;
  5. use app\admin\model\DataGroup as DataGroupModel;
  6. use app\admin\model\GoodBasic;use app\admin\model\GoodCombind;use app\admin\model\GoodStock;use app\admin\model\ProcessOrder;
  7. use app\youzan\model\PlatformYouzan;
  8. use think\App;
  9. use think\Exception;
  10. use think\facade\Cache;
  11. use think\facade\Config;
  12. use think\facade\Db;
  13. use think\facade\Validate;
  14. //商品基础库
  15. class Goodup extends Base
  16. {
  17. public $noble=[];
  18. public function __construct(App $app)
  19. {
  20. parent::__construct($app);
  21. $this->noble=\think\facade\Config::get("noble");
  22. }
  23. public function list(){
  24. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  25. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  26. $where =[["gb.is_del","=",0]];
  27. $condit =[["a.is_del","=",0]];
  28. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):"";
  29. if($cat_id!==""){
  30. $cat_ids=catChild($cat_id);
  31. $where[]=['gb.cat_id',"in",$cat_ids];
  32. $condit[]=['a.cat_id',"in",$cat_ids];
  33. }
  34. $is_combind = isset($this->post['is_combind']) && $this->post['is_combind'] !=='' ? intval($this->post['is_combind']):'';
  35. if($is_combind!==''){
  36. $where[]=['gb.is_combind','=',$is_combind];
  37. }
  38. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  39. if($good_name!==""){
  40. $where[]=['gb.good_name',"like","%$good_name%"];
  41. $condit[]=['a.good_name',"like","%$good_name%"];
  42. }
  43. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode']) :"";
  44. if($spucode!==""){
  45. $where[]=['gb.spuCode',"like","%$spucode%"];
  46. $condit[]=['a.spuCode',"like","%$spucode%"];
  47. }
  48. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type']) :"";
  49. if($good_type!==""){
  50. $where[]=['gb.good_type',"=",$good_type];
  51. $condit[]=['a.good_type',"=",$good_type];
  52. }
  53. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  54. if($companyNo!==""){
  55. $where[]=['gb.companyNo',"like","%$companyNo%"];
  56. $condit[]=['a.companyNo',"like","%$companyNo%"];
  57. }
  58. $userCommon = \app\admin\common\User::getIns();
  59. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']) :"";
  60. if($supplierNo!==""){
  61. $where[]=['gb.supplierNo',"like","%$supplierNo%"];
  62. $condit[]=['a.supplierNo',"like","%$supplierNo%"];
  63. }
  64. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !=="" ? trim($this->post['supplier']) :"";
  65. if($supplier!==""){
  66. // $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  67. $tmp = $userCommon->handle('sGetList',['name'=>$supplier]);
  68. if(isset($tmp['data']['list']) && !empty($tmp['data']['list'])){
  69. $suppliernos = array_column($tmp['data']['list'],'companyNo');
  70. $where[]=['gb.supplierNo',"in",$suppliernos];
  71. $condit[]=['a.supplierNo',"in",$suppliernos];
  72. }
  73. }
  74. $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company']) :"";
  75. if($company!==""){
  76. // $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  77. $tmp = $userCommon->handle('bGetList',['company'=>$company]);
  78. if(isset($tmp['data']['list']) && !empty($tmp['data']['list'])){
  79. $companyNos = array_column($tmp['data']['list'],'companyNo');
  80. $where[]=['gb.companyNo',"in",$companyNos];
  81. $condit[]=['a.companyNo',"in",$companyNos];
  82. }
  83. }
  84. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid']) :"";
  85. if($brandid!==""){
  86. $where[]=['gb.brand_id',"=",$brandid];
  87. $condit[]=['a.brand_id',"=",$brandid];
  88. }
  89. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  90. if($status!==""){
  91. $where[]=['gb.status',"=",$status];
  92. $condit[]=['a.status',"=",$status];
  93. }
  94. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
  95. if ($is_stock!=='') {
  96. $where[] = ['gb.is_stock', "=", $is_stock];
  97. }
  98. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  99. if($start!==""){
  100. $where[]=['gb.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  101. $condit[]=['a.addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  102. }
  103. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  104. if($end!==""){
  105. $where[]=['gb.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  106. $condit[]=['a.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  107. }
  108. $isonline = isset($this->post['isonline']) && $this->post['isonline']!=="" ? $this->post['isonline']:"";
  109. if($isonline!==""){
  110. $condit[] =['b.exam_status',"=",3];
  111. $sta =Db::name("good_basic")
  112. ->alias("a")
  113. ->leftJoin("good_platform b","a.spuCode=b.spuCode")
  114. ->where($condit)
  115. ->group("a.spuCode")
  116. ->column('a.spuCode');
  117. if($isonline==1) $where[]=["gb.spuCode","in",$sta];
  118. else $where[]=["gb.spuCode","not in",$sta];
  119. }
  120. // //只有level2的账号过滤数据权限
  121. // if ($this->level == 2) {
  122. // $role = $this->checkDataShare();
  123. // $hand = resign_hand_user($this->uid, 0);
  124. // if (!empty($role[DataGroupModel::$type_全部])) {
  125. // $arr = array_unique(array_merge($hand, $role[DataGroupModel::$type_全部]));
  126. // $supplierNos = Db::connect('mysql_sys')
  127. // ->name('supplier')
  128. // ->where(['is_del' => 0, 'personid' => $arr])
  129. // ->column('code');
  130. // array_push($supplierNos,'');
  131. // $where[] = ['gb.supplierNo', 'in', $supplierNos];
  132. // }
  133. // }
  134. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  135. if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)];
  136. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  137. if($relaComNo!="") $where[]=['gb.companyNo','=', $relaComNo];
  138. $count = Db::name('good_basic')
  139. ->alias('gb')
  140. ->where($where)
  141. ->count('gb.id');
  142. $total = ceil($count / $size);
  143. $page = $page >= $total ? $total : $page;
  144. $list = Db::name('good_basic')
  145. ->alias('gb')
  146. ->where($where)
  147. ->page($page, $size)
  148. ->order("addtime desc")
  149. ->select()
  150. ->toArray();
  151. $data=[];
  152. $all_createrid = array_column($list,'chargerid');
  153. $item = get_company_name_by_uid($all_createrid);
  154. //查询一下这些spucode是否在平台上成功上线
  155. $exam_statuss = Db::name('good_platform')
  156. ->whereIn('spuCode',array_column($list,'spuCode'))
  157. ->where(['is_del'=>0,'exam_status'=>3])//exam_status==6表示上线审核成功
  158. ->column('id','spuCode');
  159. $exam_status_yz = Db::name('platform_youzan')
  160. ->whereIn('spuCode', array_column($list, 'spuCode'))
  161. ->where(['is_del' => 0, 'exam_status' => 6])//exam_status==6表示上线审核成功
  162. ->column('id', 'spuCode');
  163. $account = checkHasAccountBySupplierNos(array_column($list, 'supplierNo'));
  164. $brand = Db::name('brand')
  165. ->where(['id'=>array_column($list,'brand_id')])
  166. ->column('brand_name','id');
  167. $unit = Db::name('unit')
  168. ->where(['id'=>array_column($list,'good_unit')])
  169. ->column('unit','id');
  170. // $supplierInfo = $userCommon->handle('getCodeAndName',['code'=>array_merge(array_column($list,'companyNo'),array_column($list,'supplierNo'))]);
  171. foreach ($list as $value){
  172. $value["cat_info"]= made($value['cat_id'],[]);
  173. // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  174. $value["brand_name"]=$brand[$value['brand_id']]??'';//isset($brand['brand_name'])?$brand['brand_name']:"";
  175. // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  176. $value['unit'] =$unit[$value['good_unit']]??'';//isset($unit['unit'])?$unit['unit']:"";
  177. // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  178. $value['company'] = $value['companyName'];//$supplierInfo['data'][$value['companyNo']]??'';//isset($company['company'])?$company['company']:"";
  179. // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  180. $value['supplier_name']=$value['supplierName'];//$supplierInfo['data'][$value['supplierNo']]??'';//isset($supplier['name'])?$supplier['name']:"";
  181. $value['exclusive']=makeExcluse($value['is_exclusive']);
  182. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  183. //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1
  184. if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1;
  185. $value['charger_company_name'] = $item[$value['chargerid']]??'';
  186. $value['has_account'] = (int)isset($account[$value['supplierNo']]);
  187. //是否具有编辑权限
  188. $value['is_allow_update'] = 1;
  189. // if ($this->level == 2) {
  190. // if (in_array($this->roleid, [1, 33]) || in_array($value['chargerid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  191. // } elseif ($this->level == 3) $value['is_allow_update'] = 1;
  192. $data[] = $value;
  193. }
  194. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  195. }
  196. //商品成本列表,不受数据权限控制
  197. public function list_copy()
  198. {
  199. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  200. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  201. $where = [["gb.is_del", "=", 0]];
  202. $condit = [["a.is_del", "=", 0]];
  203. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !== "" ? intval($this->post['cat_id']) : "";
  204. if ($cat_id !== "") {
  205. $cat_ids = catChild($cat_id);
  206. $where[] = ['gb.cat_id', "in", $cat_ids];
  207. $condit[] = ['a.cat_id', "in", $cat_ids];
  208. }
  209. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  210. if ($good_name !== "") {
  211. $where[] = ['gb.good_name', "like", "%$good_name%"];
  212. $condit[] = ['a.good_name', "like", "%$good_name%"];
  213. }
  214. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !== "" ? trim($this->post['spucode']) : "";
  215. if ($spucode !== "") {
  216. $where[] = ['gb.spuCode', "like", "%$spucode%"];
  217. $condit[] = ['a.spuCode', "like", "%$spucode%"];
  218. }
  219. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !== "" ? trim($this->post['good_type']) : "";
  220. if ($good_type !== "") {
  221. $where[] = ['gb.good_type', "=", $good_type];
  222. $condit[] = ['a.good_type', "=", $good_type];
  223. }
  224. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  225. if ($companyNo !== "") {
  226. $where[] = ['gb.companyNo', "like", "%$companyNo%"];
  227. $condit[] = ['a.companyNo', "like", "%$companyNo%"];
  228. }
  229. $userCommon = \app\admin\common\User::getIns();
  230. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !== "" ? trim($this->post['supplierNo']) : "";
  231. if ($supplierNo !== "") {
  232. $where[] = ['gb.supplierNo', "like", "%$supplierNo%"];
  233. $condit[] = ['a.supplierNo', "like", "%$supplierNo%"];
  234. }
  235. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !== "" ? trim($this->post['supplier']) : "";
  236. if ($supplier !== "") {
  237. // $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  238. $tmp = $userCommon->handle('sGetList', ['name' => $supplier]);
  239. if (isset($tmp['data']['list']) && !empty($tmp['data']['list'])) {
  240. $suppliernos = array_column($tmp['data']['list'], 'companyNo');
  241. $where[] = ['gb.supplierNo', "in", $suppliernos];
  242. $condit[] = ['a.supplierNo', "in", $suppliernos];
  243. }
  244. }
  245. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  246. if ($company !== "") {
  247. // $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  248. $tmp = $userCommon->handle('bGetList', ['company' => $company]);
  249. if (isset($tmp['data']['list']) && !empty($tmp['data']['list'])) {
  250. $companyNos = array_column($tmp['data']['list'], 'companyNo');
  251. $where[] = ['gb.companyNo', "in", $companyNos];
  252. $condit[] = ['a.companyNo', "in", $companyNos];
  253. }
  254. }
  255. $is_combind = isset($this->post['is_combind']) && $this->post['is_combind'] !=='' ? intval($this->post['is_combind']):'';
  256. if($is_combind!==''){
  257. $where[]=['gb.is_combind','=',$is_combind];
  258. }
  259. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !== "" ? intval($this->post['brandid']) : "";
  260. if ($brandid !== "") {
  261. $where[] = ['gb.brand_id', "=", $brandid];
  262. $condit[] = ['a.brand_id', "=", $brandid];
  263. }
  264. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  265. if ($status !== "") {
  266. $where[] = ['gb.status', "=", $status];
  267. $condit[] = ['a.status', "=", $status];
  268. }
  269. $is_stock = isset($this->post['is_stock']) && $this->post['is_stock'] !== "" ? intval($this->post['is_stock']) : '';
  270. if ($is_stock !== '') {
  271. $where[] = ['gb.is_stock', "=", $is_stock];
  272. }
  273. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  274. if ($start !== "") {
  275. $where[] = ['gb.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  276. $condit[] = ['a.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  277. }
  278. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  279. if ($end !== "") {
  280. $where[] = ['gb.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  281. $condit[] = ['a.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  282. }
  283. $isonline = isset($this->post['isonline']) && $this->post['isonline'] !== "" ? $this->post['isonline'] : "";
  284. if ($isonline !== "") {
  285. $condit[] = ['b.exam_status', "=", 3];
  286. // if($isonline==1){
  287. // $condit[] =['b.exam_status',"=",6];
  288. // }else{
  289. // $condit[] =['b.exam_status',"<>",6];
  290. // }
  291. $sta = Db::name("good_basic")
  292. ->alias("a")
  293. ->leftJoin("good_platform b", "a.spuCode=b.spuCode")
  294. ->where($condit)
  295. ->group("a.spuCode")
  296. ->column('a.spuCode');
  297. if ($isonline == 1) $where[] = ["gb.spuCode", "in", $sta];
  298. else $where[] = ["gb.spuCode", "not in", $sta];
  299. }
  300. // $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  301. // if($token==""){
  302. // return error_show(101,'token不能为空');
  303. // }
  304. // $apply_id =GetUserInfo($token);
  305. // if(empty($apply_id)||$apply_id['code']!=0){
  306. // return error_show(102,"申请人数据不存在");
  307. // }
  308. // $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  309. // if($rm!=''){
  310. // $useinfo = Db::name("user_role")->where(['uid'=>$rm,"status"=>1,"is_del"=>0])->find();
  311. // if($useinfo==false){
  312. // return error_show(1002,"未找到用户角色权限");
  313. // }
  314. // $check = checkRole($useinfo['roleid'],115);
  315. // if($check){
  316. // $where[]=['gb.createrid', "=" ,$rm];
  317. // }
  318. // }
  319. // $role=$this->checkRole();
  320. // $wheror=[];
  321. // $role = $this->checkDataShare();//取负责人字段
  322. // if(!empty($role[DataGroupModel::$type_全部])) $wheror[]=["gb.chargerid","in",$role[DataGroupModel::$type_全部]];
  323. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  324. if ($company_name !== "") $where[] = ["gb.createrid", 'in', get_company_item_user_by_name($company_name)];
  325. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  326. if($relaComNo!="") $where[]=['gb.companyNo','=', $relaComNo];
  327. $count = Db::name('good_basic')
  328. ->alias('gb')
  329. ->where($where)
  330. // ->where(function ($Query) use ($wheror) {
  331. // return $Query->whereOr($wheror);
  332. // })
  333. ->count('gb.id');
  334. $total = ceil($count / $size);
  335. $page = $page >= $total ? $total : $page;
  336. $list = Db::name('good_basic')
  337. ->alias('gb')
  338. ->where($where)
  339. ->page($page, $size)
  340. ->order("addtime desc")
  341. ->select()
  342. ->toArray();
  343. $data = [];
  344. $all_createrid = array_column($list, 'chargerid');
  345. $item = get_company_name_by_uid($all_createrid);
  346. //查询一下这些spucode是否在平台上成功上线
  347. $exam_statuss = Db::name('good_platform')
  348. ->whereIn('spuCode', array_column($list, 'spuCode'))
  349. ->where(['is_del' => 0, 'exam_status' => 3])//exam_status==3表示上线审核成功
  350. ->column('id', 'spuCode');
  351. $exam_status_yz = Db::name('platform_youzan')
  352. ->whereIn('spuCode', array_column($list, 'spuCode'))
  353. ->where(['is_del' => 0, 'exam_status' => 6])//exam_status==3表示上线审核成功
  354. ->column('id', 'spuCode');
  355. $account = checkHasAccountBySupplierNos(array_column($list, 'supplierNo'));
  356. $brand = Db::name('brand')
  357. ->where(['id' => array_column($list, 'brand_id')])
  358. ->column('brand_name', 'id');
  359. $unit = Db::name('unit')
  360. ->where(['id' => array_column($list, 'good_unit')])
  361. ->column('unit', 'id');
  362. $supplierInfo = $userCommon->handle('getCodeAndName', ['code' => array_merge(array_column($list, 'companyNo'), array_column($list, 'supplierNo'))]);
  363. foreach ($list as $value) {
  364. $value["cat_info"] = made($value['cat_id'], []);
  365. // $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  366. $value["brand_name"] = $brand[$value['brand_id']] ?? '';//isset($brand['brand_name'])?$brand['brand_name']:"";
  367. // $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  368. $value['unit'] = $unit[$value['good_unit']] ?? '';//isset($unit['unit'])?$unit['unit']:"";
  369. // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  370. $value['company'] = $supplierInfo['data'][$value['companyNo']] ?? '';//isset($company['company'])?$company['company']:"";
  371. // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  372. $value['supplier_name'] = $supplierInfo['data'][$value['supplierNo']] ?? '';//isset($supplier['name'])?$supplier['name']:"";
  373. $value['exclusive'] = makeExcluse($value['is_exclusive']);
  374. $value['noble_name'] = isset($value['noble_metal']) && $value['noble_metal'] != 0 ? $this->noble[$value['noble_metal']] : "";
  375. //如果一个spucode在任意平台上线,那么就视为它上线,即手动把它的is_online值改为1
  376. if (isset($exam_statuss[$value['spuCode']]) || isset($exam_status_yz[$value['spuCode']])) $value['is_online'] = 1;
  377. $value['charger_company_name'] = $item[$value['chargerid']] ?? '';
  378. $value['has_account'] = (int)isset($account[$value['supplierNo']]);
  379. // //是否具有编辑权限
  380. // $value['is_allow_update'] = 0;
  381. // if ($this->level == 2) {
  382. // if (in_array($this->roleid, [1, 33]) || in_array($value['chargerid'], $role[DataGroupModel::$type_可编辑])) $value['is_allow_update'] = 1;
  383. // } elseif ($this->level == 3) $value['is_allow_update'] = 1;
  384. $data[] = $value;
  385. }
  386. return app_show(0, "获取成功", ['list' => $data, 'count' => $count]);
  387. }
  388. public function create(){
  389. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  390. if($good_name==""){
  391. return error_show(1004,"商品名称不能为空");
  392. }
  393. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  394. if($cat_id==''){
  395. return error_show(1004,"商品分类不能为空");
  396. }
  397. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  398. if($brandid==''){
  399. return error_show(1004,"商品品牌不能为空");
  400. }
  401. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  402. if($unit==''){
  403. return error_show(1004,"商品单位不能为空");
  404. }
  405. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  406. if($good_type===''){
  407. return error_show(1004,"参数good_type不能为空");
  408. }
  409. $moq=0;
  410. $customized=0;
  411. if($good_type==1){
  412. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  413. if($moq===''){
  414. return error_show(1004,"定制商品起订量不能为空");
  415. }
  416. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  417. if($customized===''){
  418. return error_show(1004,"参数customized不能为空");
  419. }
  420. }
  421. $isCombind= $this->post['is_combind']??0;
  422. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  423. if($is_exclusive===''){
  424. return error_show(1004,"参数is_exclusive不能为空");
  425. }
  426. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  427. if($tax===''){
  428. return error_show(1004,"参数tax不能为空");
  429. }
  430. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=''? trim($this->post['supplierNo']):'';
  431. $supplierArr=[];
  432. $supplier=[];
  433. $userCommon= \app\admin\common\User::getIns();
  434. if($supplierNo==''){
  435. return error_show(1004,'参数supplierNo不能为空');
  436. }
  437. $supplier_temp =$userCommon->handle('hqInfo',['code'=>$supplierNo]);
  438. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,'供应商信息未找到');
  439. $supplierArr=$supplier_temp['data']??[];
  440. $supplier=$supplierArr['child']??[];
  441. if ($this->level == 2) {
  442. $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
  443. if (isset($supplier_account[$supplierNo])) return json_show(1004, '该供应商已开通账号,不允许操作');
  444. }
  445. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
  446. if($good_size==''){
  447. return error_show(1004,"参数good_size不能为空");
  448. }
  449. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
  450. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
  451. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :"";
  452. if($company_id==''){
  453. return error_show(1004,"参数company_id不能为空");
  454. }
  455. $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]);
  456. if(isset($supplierArr['relation_code'])&&$supplierArr['relation_code']==$company_id){
  457. return error_show(1004,"业务公司与供应商属于同一家公司");
  458. }
  459. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  460. if($is_auth===''){
  461. return error_show(1004,"参数is_auth不能为空");
  462. }
  463. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  464. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  465. if($after_sales==""){
  466. return error_show(1004,"参数after_sales不能为空");
  467. }
  468. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  469. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  470. if($good_remark===""){
  471. return error_show(1004,"参数good_remark不能为空");
  472. }
  473. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  474. if($weight===""){
  475. return error_show(1004,"参数weight不能为空");
  476. }
  477. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  478. if($packing_way===""){
  479. return error_show(1004,"参数packing_way不能为空");
  480. }
  481. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  482. if($packing_size===""){
  483. return error_show(1004,"参数packing_size不能为空");
  484. }
  485. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  486. if($packing_spec===""){
  487. return error_show(1004,"参数packing_spec不能为空");
  488. }
  489. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  490. if($packing_weight===""){
  491. return error_show(1004,"参数packing_weight不能为空");
  492. }
  493. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  494. if($packing_list===""){
  495. return error_show(1004,"参数packing_list不能为空");
  496. }
  497. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  498. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  499. if($supply_area===""){
  500. return error_show(1004,"参数supply_area不能为空");
  501. }
  502. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  503. if($delivery_place===""){
  504. return error_show(1004,"参数delivery_place不能为空");
  505. }
  506. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  507. if($origin_place===""){
  508. return error_show(1004,"参数origin_place不能为空");
  509. }
  510. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  511. if($delivery_day===""){
  512. return error_show(1004,"参数delivery_day不能为空");
  513. }
  514. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  515. $cgd_gold_price =isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""?floatval($this->post['cgd_gold_price']):"0";
  516. // if($lead_time===""){
  517. // return error_show(1004,"参数lead_time不能为空");
  518. // }
  519. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  520. // if($sample_day===""){
  521. // return error_show(1004,"参数sample_day不能为空");
  522. // }
  523. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  524. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  525. if($is_stock===""){
  526. return error_show(1004,"参数is_stock不能为空");
  527. }
  528. // $stock_moq=0 ;//库存品备库起订量; 如果是0 表示无限制;
  529. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  530. if($is_stock==1 && $stock_moq ==0){
  531. return error_show(1004,"库存品备库起订量不能为零");
  532. }
  533. if($is_stock==0 && $isCombind==1) return error_show(1004,'非库存品不支持组合商品类型');
  534. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  535. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  536. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  537. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  538. if($good_img===""){
  539. return error_show(1004,"参数good_img不能为空");
  540. }
  541. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  542. if($good_thumb_img===""){
  543. return error_show(1004,"参数good_thumb_img不能为空");
  544. }
  545. $good_info_img = isset($this->post['good_info_img'])&&$this->post['good_info_img']!=""? trim($this->post['good_info_img']):"";
  546. if($good_info_img===""){
  547. return error_show(1004,"参数good_info_img不能为空");
  548. }
  549. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  550. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  551. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  552. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  553. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  554. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  555. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  556. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  557. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  558. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  559. if($market_price===""){
  560. return error_show(1004,"参数market_price不能为空");
  561. }
  562. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  563. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  564. // if($is_step===""){
  565. // return error_show(1004,"参数is_step不能为空");
  566. // }
  567. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  568. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  569. // if($is_step==1 && $good_ladder==""){
  570. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  571. // }
  572. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  573. $combindList = $this->post["combind_list"]??[];
  574. $createrid= $this->uid;
  575. $creater= $this->uname;
  576. $spucode=makeNo("SKU");
  577. if($isCombind==1){
  578. if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
  579. $spucode=makeNo("SSU");
  580. $dchild=[];
  581. $valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
  582. foreach ($combindList as $value){
  583. if($valid->check($value)==false)return error_show(1004,$valid->getError());
  584. $value['spuCode'] = $spucode;
  585. $value['good_name'] =$good_name;
  586. $dchild[]=$value;
  587. }
  588. }
  589. Db::startTrans();
  590. try {
  591. $data=[
  592. "spuCode"=>$spucode,
  593. "good_code"=>'',
  594. "good_name"=>$good_name,
  595. "cat_id"=>$cat_id,
  596. 'brand_id'=>$brandid,
  597. "good_unit"=>$unit,
  598. "good_type"=>$good_type,
  599. "moq"=>$moq,
  600. "is_exclusive"=>$is_exclusive,
  601. "customized"=>$customized,
  602. "companyNo"=>$company_id,
  603. "companyName"=>$companyinfo['data'][$company_id]??"",
  604. "tax"=>$tax,
  605. "supplierNo"=>$supplierNo,
  606. "supplierName"=>$supplierArr['name']??"",
  607. "good_size"=>$good_size,
  608. "is_auth"=>$is_auth,
  609. "is_stock"=>$is_stock,
  610. "auth_img"=>$auth_img,
  611. "after_sales"=>$after_sales,
  612. "craft_desc"=>$craft_desc,
  613. "good_remark"=>$good_remark,
  614. "weight"=>$weight,
  615. "packing_way"=>$packing_way,
  616. "packing_size"=>$packing_size,
  617. "packing_spec"=>$packing_spec,
  618. "packing_list"=>$packing_list,
  619. "packing_weight"=>$packing_weight,
  620. "good_bar"=>$good_bar,
  621. "supply_area"=>$supply_area,
  622. "delivery_place"=>$delivery_place,
  623. "origin_place"=>$origin_place,
  624. "delivery_day"=>$delivery_day,
  625. "lead_time"=>$lead_time,
  626. "sample_day"=>$sample_day,
  627. "sample_fee"=>$sample_fee,
  628. "good_img"=>$good_img,
  629. "good_thumb_img"=>$good_thumb_img,
  630. "good_info_img"=>$good_info_img,
  631. "cert_fee"=>$cert_fee,
  632. "packing_fee"=>$packing_fee,
  633. "cost_fee"=>$cost_fee,
  634. "mark_fee"=>$mark_fee,
  635. "demo_fee"=>$demo_fee,
  636. "open_fee"=>$open_fee,
  637. "noble_metal"=>$noble_metal,
  638. "cgd_gold_price"=>$cgd_gold_price,
  639. "noble_weight"=>$noble_weight,
  640. "is_gold_price"=>$is_gold_price,
  641. "market_price"=>$market_price,
  642. "nake_price"=>$nake_price,
  643. "is_diff"=>$is_diff,
  644. "config"=>$config,
  645. "other_config"=>$other_config,
  646. "field_change"=>'',
  647. "is_step" => count($good_ladder) > 1 ? 1 : 0,//如果阶梯价个数大于1,说明启用阶梯价
  648. "is_online"=>0,
  649. "stock_moq"=>$stock_moq,
  650. "status"=>0,
  651. "createrid"=>$createrid,
  652. "creater"=>$creater,
  653. "addtime"=>date("Y-m-d H:i:s"),
  654. "updatetime"=>date("Y-m-d H:i:s"),
  655. 'is_support_barter'=>$is_support_barter,
  656. 'is_combind'=>$isCombind,
  657. 'chargerid'=>$supplier['personid']??$createrid,
  658. 'charger'=>$supplier['person']??$creater,//负责人跟创建人一致
  659. ];
  660. $in = Db::name("good_basic")->insertGetId($data);
  661. if($in){
  662. if($speclist!=="" && !empty($speclist)){
  663. $temp=[];
  664. foreach ($speclist as $value){
  665. $lemp=[];
  666. $lemp['spuCode']=$spucode;
  667. $lemp['spec_id'] = $value['spec_id'];
  668. $lemp['spec_value_id'] = $value['spec_value_id'];
  669. $lemp['addtime'] = date("Y-m-d H:i:s");
  670. $lemp['updatetime'] =date("Y-m-d H:i:s");
  671. $temp[]=$lemp;
  672. }
  673. $count = Db::name("good_spec")->insertAll($temp);
  674. if($count==0){
  675. throw new \Exception("商品规格值创建失败");
  676. }
  677. }
  678. if($proof_url!==''){
  679. $proof=[
  680. 'spuCode'=>$spucode,
  681. 'proof_type'=>$proof_type,
  682. 'proof_url'=>$proof_url,
  683. 'is_del'=>0,
  684. "creater"=>$creater,
  685. "createrid"=>$createrid,
  686. "addtime"=>date("Y-m-d H:i:s"),
  687. "updatetime"=>date("Y-m-d H:i:s")
  688. ];
  689. $inproof = Db::name("good_proof")->insert($proof);
  690. if($inproof==false)throw new \Exception("商品凭证新建失败");
  691. }
  692. $top_cat_id = made($cat_id);//获取所有分类
  693. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  694. if($good_ladder!=="" && !empty($good_ladder)){
  695. $temp=[];
  696. foreach ($good_ladder as $value){
  697. $lemp=[];
  698. $lemp['spuCode']=$spucode;
  699. $lemp['min_num'] = $value['min_num'];
  700. $lemp['nake_fee'] = $value['nake_fee'];
  701. $lemp['cost_fee'] = $value['cost_fee'];
  702. $lemp['delivery_fee'] = $value['delivery_fee'];
  703. $lemp['cert_fee'] = $value['cert_fee'];
  704. $lemp['mark_fee'] = $value['mark_fee'];
  705. $lemp['package_fee'] = $value['package_fee'];
  706. $lemp['other_fee'] = $value['other_fee'];
  707. if($is_gold_price==1 && $top_cat_id==6){
  708. //$is_gold_price==1 表示启用实时金价,cat_id==6表示贵金属
  709. $gold = Db::name("gold_price1")->where(["type" => $noble_metal, "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  710. //$lemp['nake_total'] = $noble_weight * $gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  711. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  712. //成本总计启用实时金价时,采用供应商实时金价
  713. $lemp['nake_total'] = $noble_weight *$gold['price'] + $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  714. }else{
  715. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  716. }
  717. $lemp['creater_id'] = $createrid;
  718. $lemp['creater'] = $creater;
  719. $lemp['is_del'] = 0;
  720. $lemp['addtime'] = date("Y-m-d H:i:s");
  721. $lemp['updatetime'] =date("Y-m-d H:i:s");
  722. $temp[]=$lemp;
  723. }
  724. $count = Db::name("good_nake")->insertAll($temp);
  725. if($count==0){
  726. throw new \Exception("商品成本创建失败");
  727. }
  728. }
  729. if($isCombind==1 && !empty($dchild)){
  730. (new GoodCombind())->saveAll($dchild);
  731. }
  732. //修改状态,添加待办
  733. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  734. "order_code" =>$spucode,//咨询单详情编号
  735. "status" => 0,//这里的status是之前的值
  736. "action_remark" => '',//备注
  737. "action_type" => "create"//新建create,编辑edit,更改状态status
  738. ], "SPCB", 0,$data);
  739. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  740. "order_type" => 'SPCB',
  741. "order_code" => $spucode,//咨询单详情编号
  742. "order_id" => $in,
  743. "order_status" => 0,
  744. "before_status" => 0,
  745. 'holder_id'=>$data['createrid'],
  746. ]);
  747. Db::commit();
  748. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  749. }else{
  750. throw new \Exception("商品创建失败");
  751. }
  752. }catch (\Exception $e){
  753. Db::rollback();
  754. return app_show(1004,$e->getMessage());
  755. }
  756. }
  757. public function editinfo(){
  758. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  759. if($supcode==""){
  760. return error_show(1004,"参数spuCode不能为空");
  761. }
  762. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  763. if($data==false){
  764. return error_show(1004,"未找到商品数据");
  765. }
  766. $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",5)
  767. ->find();
  768. if($is_down!=false){
  769. return error_show(1004,"存在未下线商品数据");
  770. }
  771. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  772. if($good_name==""){
  773. return error_show(1004,"商品名称不能为空");
  774. }
  775. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  776. if($cat_id==''){
  777. return error_show(1004,"商品分类不能为空");
  778. }
  779. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  780. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  781. if($unit==''){
  782. return error_show(1004,"商品单位不能为空");
  783. }
  784. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  785. if($good_type===''){
  786. return error_show(1004,"参数good_type不能为空");
  787. }
  788. $moq=0;
  789. $customized=0;
  790. if($good_type==1){
  791. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  792. if($moq===''){
  793. return error_show(1004,"定制商品起订量不能为空");
  794. }
  795. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  796. if($customized===''){
  797. return error_show(1004,"参数customized不能为空");
  798. }
  799. }
  800. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  801. if($is_exclusive===''){
  802. return error_show(1004,"参数is_exclusive不能为空");
  803. }
  804. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  805. if($tax===''){
  806. return error_show(1004,"参数tax不能为空");
  807. }
  808. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  809. $isCombind= $this->post['is_combind']??0;
  810. $supplierArr=[];
  811. $supplier=[];
  812. $userCommon= \app\admin\common\User::getIns();
  813. if($supplierNo=='')return error_show(1004,'参数supplierNo不能为空');
  814. $supplier_temp =$userCommon->handle('hqInfo',['code'=>$supplierNo]);
  815. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,'供应商信息未找到');
  816. $supplierArr=$supplier_temp['data']??[];
  817. $supplier=$supplierArr['child']??[];
  818. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
  819. if($good_size==''){
  820. return error_show(1004,"参数good_size不能为空");
  821. }
  822. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id']) :"";
  823. if($company_id==''){
  824. return error_show(1004,"参数company_id不能为空");
  825. }
  826. $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]);
  827. if(isset($supplierArr['relation_code'])&&$supplierArr['relation_code']==$company_id){
  828. return error_show(1004,"业务公司与供应商属于同一家公司");
  829. }
  830. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  831. if($is_auth===''){
  832. return error_show(1004,"参数is_auth不能为空");
  833. }
  834. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  835. // if($auth_img==''){
  836. // return error_show(1004,"商品不能为空");
  837. // }
  838. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  839. if($after_sales==""){
  840. return error_show(1004,"参数after_sales不能为空");
  841. }
  842. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  843. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  844. if($good_remark===""){
  845. return error_show(1004,"参数good_remark不能为空");
  846. }
  847. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  848. if($weight===""){
  849. return error_show(1004,"参数weight不能为空");
  850. }
  851. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  852. if($packing_way===""){
  853. return error_show(1004,"参数packing_way不能为空");
  854. }
  855. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  856. if($packing_size===""){
  857. return error_show(1004,"参数packing_size不能为空");
  858. }
  859. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  860. if($packing_spec===""){
  861. return error_show(1004,"参数packing_spec不能为空");
  862. }
  863. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  864. if($packing_weight===""){
  865. return error_show(1004,"参数packing_weight不能为空");
  866. }
  867. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  868. if($packing_list===""){
  869. return error_show(1004,"参数packing_list不能为空");
  870. }
  871. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  872. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  873. if($supply_area===""){
  874. return error_show(1004,"参数supply_area不能为空");
  875. }
  876. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  877. if($delivery_place===""){
  878. return error_show(1004,"参数delivery_place不能为空");
  879. }
  880. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  881. if($origin_place===""){
  882. return error_show(1004,"参数origin_place不能为空");
  883. }
  884. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  885. if($delivery_day===""){
  886. return error_show(1004,"参数delivery_day不能为空");
  887. }
  888. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  889. // if($lead_time===""){
  890. // return error_show(1004,"参数lead_time不能为空");
  891. // }
  892. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  893. // if($sample_day===""){
  894. // return error_show(1004,"参数sample_day不能为空");
  895. // }
  896. // $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval
  897. //($this->post['sample_fee']):"0";
  898. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  899. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  900. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  901. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  902. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  903. if($is_stock==1 && $stock_moq ==0){
  904. return error_show(1004,"库存品备库起订量不能为零");
  905. }
  906. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  907. if($good_img===""){
  908. return error_show(1004,"参数good_img不能为空");
  909. }
  910. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  911. if($good_thumb_img===""){
  912. return error_show(1004,"参数good_thumb_img不能为空");
  913. }
  914. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  915. if($good_info_img===""){
  916. return error_show(1004,"参数good_info_img不能为空");
  917. }
  918. $count = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->count();
  919. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  920. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
  921. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
  922. $combindList = $this->post['combind_list']??[];
  923. if($isCombind==1){
  924. if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
  925. $dchild=[];
  926. $valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
  927. foreach ($combindList as $value){
  928. if($valid->check($value)==false)return error_show(1004,$valid->getError());
  929. $value['spuCode'] = $data['spuCode'];
  930. $value['good_name'] =$good_name;
  931. $value['updatetime'] =date("Y-m-d H:i:s");
  932. if($value['is_del']==1){
  933. $usable_stock = Db::name("good")->where(["spuCode"=>$data['spuCode']])->value("usable_stock",0);
  934. if($usable_stock>0) return error_show(1004,'组合商品库存未处理完不可删除子商品');
  935. }
  936. $dchild[]=$value;
  937. }
  938. }
  939. Db::startTrans();
  940. try {
  941. $temp=[
  942. "good_name"=>$good_name,
  943. "cat_id"=>$cat_id,
  944. 'brand_id'=>$brandid,
  945. "good_unit"=>$unit,
  946. "good_type"=>$good_type,
  947. "companyNo"=>$company_id,
  948. "companyName"=>$companyinfo['data'][$company_id]??'',
  949. "supplierName"=>$supplierArr['name']??"",
  950. "moq"=>$moq,
  951. "is_exclusive"=>$is_exclusive,
  952. "customized"=>$customized,
  953. "tax"=>$tax,
  954. "supplierNo"=>$supplierNo,
  955. "is_auth"=>$is_auth,
  956. "good_size"=>$good_size,
  957. "auth_img"=>$auth_img,
  958. "after_sales"=>$after_sales,
  959. "craft_desc"=>$craft_desc,
  960. "good_remark"=>$good_remark,
  961. "weight"=>$weight,
  962. "packing_way"=>$packing_way,
  963. "packing_size"=>$packing_size,
  964. "packing_spec"=>$packing_spec,
  965. "packing_list"=>$packing_list,
  966. "packing_weight"=>$packing_weight,
  967. "good_bar"=>$good_bar,
  968. "supply_area"=>$supply_area,
  969. "delivery_place"=>$delivery_place,
  970. "origin_place"=>$origin_place,
  971. "delivery_day"=>$delivery_day,
  972. "lead_time"=>$lead_time,
  973. "sample_day"=>$sample_day,
  974. "is_diff"=>$is_diff,
  975. 'is_stock'=>$is_stock,
  976. "config"=>$config,
  977. "other_config"=>$other_config,
  978. "good_img" => $good_img,
  979. "stock_moq" => $stock_moq,
  980. "good_thumb_img"=>$good_thumb_img,
  981. "good_info_img"=>$good_info_img,
  982. "status"=>$count>0?2:1,
  983. "updatetime" => date("Y-m-d H:i:s"),
  984. 'is_combind'=>$isCombind,
  985. 'chargerid' => $supplier['personid'] ?? $this->uid,
  986. 'charger' => $supplier['person'] ?? $this->uname,//负责人跟创建人一致
  987. ];
  988. $field = array_diff_assoc($temp,$data);
  989. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  990. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  991. $timp = array_diff($temp,$data);
  992. $json = json_encode($timp,JSON_UNESCAPED_UNICODE);
  993. $jsp = json_encode($data,JSON_UNESCAPED_UNICODE);
  994. if($up){
  995. ChangeLog::logAdd(3,$data['spuCode'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  996. if($speclist!=="" && !empty($speclist)){
  997. foreach ($speclist as $value){
  998. $lemp=[];
  999. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1000. $lemp['spuCode']=$supcode;
  1001. $lemp['spec_id'] = $value['spec_id'];
  1002. $lemp['spec_value_id'] = $value['spec_value_id'];
  1003. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1004. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1005. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1006. $count = Db::name("good_spec")->save($lemp);
  1007. if($count==false){
  1008. Db::rollback();
  1009. return app_show(1004,"商品规格值修改失败");
  1010. }
  1011. }
  1012. }
  1013. if($proof_url!=''){
  1014. $proof=[
  1015. 'spuCode'=>$supcode,
  1016. 'proof_type'=>$proof_type,
  1017. 'proof_url'=>$proof_url,
  1018. 'is_del'=>0,
  1019. "creater"=>$this->uname,
  1020. "createrid"=>$this->uid,
  1021. "addtime"=>date("Y-m-d H:i:s"),
  1022. "updatetime"=>date("Y-m-d H:i:s")
  1023. ];
  1024. $inproof = Db::name("good_proof")->insert($proof);
  1025. if($inproof==false)throw new \Exception("商品凭证新建失败");
  1026. }
  1027. if($isCombind==1 && !empty($dchild)){
  1028. (new GoodCombind())->saveAll($dchild);
  1029. }
  1030. //修改状态,添加待办
  1031. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  1032. "order_code" =>$supcode,//咨询单详情编号
  1033. "status" => $data['status'],//这里的status是之前的值
  1034. "action_remark" => '',//备注
  1035. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1036. ], "SPCB",$temp['status'] ,$data);
  1037. ProcessOrder::AddProcess(['id' => $this->uid, 'nickname' => $this->uname], [
  1038. "order_type" => 'SPCB',
  1039. "order_code" => $supcode,//咨询单详情编号
  1040. "order_id" => $data['id'],
  1041. "order_status" =>$temp['status'],
  1042. "before_status"=>$data['status'],
  1043. 'holder_id'=>$data['createrid'],
  1044. ]);
  1045. Db::commit();
  1046. return app_show(0,"更新成功");
  1047. }else{
  1048. Db::rollback();
  1049. return error_show(1005,"更新失败");
  1050. }
  1051. }catch (\Exception $e){
  1052. Db::rollback();
  1053. return error_show(1004,$e->getMessage());
  1054. }
  1055. }
  1056. public function editfee(){
  1057. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1058. if($supcode==""){
  1059. return error_show(1004,"参数spuCode不能为空");
  1060. }
  1061. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1062. if($datas==false){
  1063. return error_show(1004,"未找到商品数据");
  1064. }
  1065. $is_down = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->where("exam_status","<>",5)
  1066. ->find();
  1067. if($is_down!=false){
  1068. return error_show(1004,"存在未下线商品数据");
  1069. }
  1070. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1071. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1072. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1073. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1074. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1075. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1076. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1077. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1078. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1079. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1080. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1081. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  1082. if($market_price===""){
  1083. return error_show(1004,"参数market_price不能为空");
  1084. }
  1085. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  1086. // $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1087. // if($is_step===""){
  1088. // return error_show(1004,"参数is_step不能为空");
  1089. // }
  1090. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1091. // if($is_step==1 && $good_ladder==""){
  1092. // return error_show(1004,"启用阶梯,阶梯价不能为空");
  1093. // }
  1094. $data=[
  1095. "cert_fee"=>$cert_fee,
  1096. "packing_fee"=>$packing_fee,
  1097. "cost_fee"=>$cost_fee,
  1098. "mark_fee"=>$mark_fee,
  1099. "demo_fee"=>$demo_fee,
  1100. "open_fee"=>$open_fee,
  1101. "sample_fee"=>$sample_fee,
  1102. "noble_metal"=>$noble_metal,
  1103. "noble_weight"=>$noble_weight,
  1104. "is_gold_price"=>$is_gold_price,
  1105. "market_price"=>$market_price,
  1106. "nake_price"=>$nake_price,
  1107. "cgd_gold_price"=>$cgd_gold_price,
  1108. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  1109. "status"=>"3",
  1110. "updatetime"=>date("Y-m-d H:i:s")
  1111. ];
  1112. $field = array_diff_assoc($data,$datas);
  1113. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1114. Db::startTrans();
  1115. try{
  1116. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  1117. $temp = array_diff($data,$datas);
  1118. $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  1119. $jsp = json_encode($datas,JSON_UNESCAPED_UNICODE);
  1120. if($up){
  1121. ChangeLog::logAdd(3,$datas['spuCode'],$jsp,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  1122. //修改状态,添加待办
  1123. ActionLog::logAdd($this->post['token'], [
  1124. "order_code" =>$supcode,//咨询单详情编号
  1125. "status" => $datas['status'],//这里的status是之前的值
  1126. "action_remark" => '',//备注
  1127. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1128. ], "SPCB",$data['status'] ,$data);
  1129. ProcessOrder::AddProcess($this->post['token'], [
  1130. "order_type" => 'SPCB',
  1131. "order_code" => $supcode,//咨询单详情编号
  1132. "order_id" => $datas['id'],
  1133. "order_status" =>$data['status'],
  1134. "before_status"=>$datas['status'],
  1135. 'holder_id'=>$datas['createrid'],
  1136. ]);
  1137. // $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1138. // if($online){
  1139. // $onup = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save
  1140. // (["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  1141. // if($onup==false){
  1142. // Db::rollback();
  1143. // return app_show(1004,"商品规成本修改失败");
  1144. // }
  1145. // //修改状态,添加待办
  1146. // ActionLog::logAdd($this->post['token'], [
  1147. // "order_code" =>$online['skuCode'],//咨询单详情编号
  1148. // "status" => $online['exam_status'],//这里的status是之前的值
  1149. // "action_remark" => '',//备注
  1150. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  1151. // ], "SPSX",2,["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  1152. //
  1153. // ProcessOrder::AddProcess($this->post['token'], [
  1154. // "order_type" => 'SPSX',
  1155. // "order_code" => $online['skuCode'],//咨询单详情编号
  1156. // "order_id" => $online['id'],
  1157. // "order_status" =>2,"before_status"=>$online['exam_status']
  1158. // ]);
  1159. // }
  1160. if($good_ladder!=="" && !empty($good_ladder)){
  1161. $user =GetUserInfo($this->post['token']);
  1162. foreach ($good_ladder as $value){
  1163. $lemp=[];
  1164. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1165. $lemp['spuCode']=$supcode;
  1166. $lemp['min_num'] = $value['min_num'];
  1167. $lemp['nake_fee'] = $value['nake_fee'];
  1168. $lemp['cost_fee'] = $value['cost_fee'];
  1169. $lemp['delivery_fee'] = $value['delivery_fee'];
  1170. $lemp['cert_fee'] = $value['cert_fee'];
  1171. $lemp['mark_fee'] = $value['mark_fee'];
  1172. $lemp['package_fee'] = $value['package_fee'];
  1173. $lemp['other_fee'] = $value['other_fee'];
  1174. $top_cat_id = made($datas['cat_id']);//获取所有分类
  1175. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1176. if($is_gold_price==1 && $top_cat_id==6){
  1177. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  1178. //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  1179. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1180. //成本总计启用实时金价时,采用供应商实时金价
  1181. $lemp['nake_total'] = $noble_weight * $gold['price']+ $value['cost_fee'] * $noble_weight + $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  1182. }else{
  1183. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1184. }
  1185. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1186. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1187. $lemp['creater'] =isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1188. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1189. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1190. $count = Db::name("good_nake")->save($lemp);
  1191. if($count==false){
  1192. Db::rollback();
  1193. return app_show(1004,"商品规成本修改失败");
  1194. }
  1195. }
  1196. }
  1197. Db::commit();
  1198. return app_show(0,"更新成功");
  1199. }else{
  1200. Db::rollback();
  1201. return error_show(1005,"更新失败");
  1202. }
  1203. }catch (\Exception $e){
  1204. Db::rollback();
  1205. return error_show(1005,$e->getMessage());
  1206. }
  1207. }
  1208. public function exam(){
  1209. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1210. if($supcode==""){
  1211. return error_show(1004,"参数spuCode不能为空");
  1212. }
  1213. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1214. if($data==false){
  1215. return error_show(1004,"未找到商品数据");
  1216. }
  1217. $isupdate = $this->isUpdate($supcode);
  1218. if($isupdate==0){
  1219. return error_show(1004,"存在上线进行中的商品");
  1220. }
  1221. if($data['status']==1){
  1222. return error_show(1004,"商品已审核通过");
  1223. }
  1224. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  1225. // if($status===""){
  1226. // return error_show(1004,"参数status不能为空");
  1227. // }
  1228. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  1229. // if($remark===""){
  1230. // return error_show(1004,"参数remark不能为空");
  1231. // }
  1232. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1233. if($token==''){
  1234. return error_show(105,"参数token不能为空");
  1235. }
  1236. $createrid=$this->uid;
  1237. $creater= $this->uname;
  1238. Db::startTrans();
  1239. try {
  1240. if($status==1){
  1241. //区分是否是对接平台
  1242. $platform_info=Db::name('platform')
  1243. ->field('id,platform_type')
  1244. ->where(['is_del'=>0,'platform_type'=>1])
  1245. ->column("id");
  1246. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->whereNotIn("platform_code",$platform_info)->find();
  1247. if($online) {
  1248. $onl= Db::name("good_platform")->where(["spuCode" => $supcode, "is_del" => 0])->whereNotIn("platform_code",$platform_info)->save(["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1249. if ($onl == false) {
  1250. Db::rollback();
  1251. return error_show(1004, "审核失败");
  1252. }
  1253. ActionLog::logAdd($this->post['token'], [
  1254. "order_code" =>$online['skuCode'],//咨询单详情编号
  1255. "status" => $online['exam_status'],//这里的status是之前的值
  1256. "action_remark" => '',//备注
  1257. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1258. ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1259. ProcessOrder::AddProcess($this->post['token'], [
  1260. "order_type" => 'SPSX',
  1261. "order_code" =>$online['skuCode'],//咨询单详情编号
  1262. "order_id" => $online['id'],
  1263. "order_status" => 2,
  1264. "before_status"=>$online['exam_status'],
  1265. 'holder_id' => $online['createrid'],
  1266. ]);
  1267. }
  1268. }
  1269. // if ($status == 1) {
  1270. // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
  1271. // Db::name('good')
  1272. // ->where(['is_del' => 0, 'status' => 1])
  1273. // ->whereIn('spuCode', $supcode)
  1274. // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  1275. // }
  1276. $old_status = $data['status'];
  1277. $data['status']=$status;
  1278. $data['updatetime']=date("Y-m-d H:i:s");
  1279. $up= Db::name("good_basic")->save($data);
  1280. if($up){
  1281. //修改状态,添加待办
  1282. ActionLog::logAdd($this->post['token'], [
  1283. "order_code" =>$supcode,//咨询单详情编号
  1284. "status" => $status,//这里的status是之前的值
  1285. "action_remark" => '',//备注
  1286. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1287. ], "SPCB",$data['status'] ,$data);
  1288. ProcessOrder::AddProcess($this->post['token'], [
  1289. "order_type" => 'SPCB',
  1290. "order_code" => $supcode,//咨询单详情编号
  1291. "order_id" => $data['id'],
  1292. "order_status" =>$data['status'],
  1293. "before_status"=>$old_status,
  1294. 'holder_id'=>$data['createrid'],
  1295. ]);
  1296. $data=[
  1297. "code"=>$supcode,
  1298. "exam_status"=>$status,
  1299. "type"=>1,
  1300. "exam_id"=>$createrid,
  1301. "exam_name"=>$creater,
  1302. "exam_remark"=>$remark,
  1303. "addtime"=>date("Y-m-d H:i:s")
  1304. ];
  1305. $inr=Db::name("good_exam")->insert($data);
  1306. if($inr){
  1307. Db::commit();
  1308. return app_show(0,"审核成功");
  1309. }else{
  1310. Db::rollback();
  1311. return error_show(1004,"审核失败");
  1312. }
  1313. }else{
  1314. Db::rollback();
  1315. return error_show(1004,"审核失败");
  1316. }
  1317. }catch (\Exception $e){
  1318. Db::rollback();
  1319. return error_show(1004,$e->getMessage());
  1320. }
  1321. }
  1322. public function info(){
  1323. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1324. if($supcode==""){
  1325. return error_show(1004,"参数spuCode不能为空");
  1326. }
  1327. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1328. if($data==false){
  1329. return error_show(1004,"未找到商品数据");
  1330. }
  1331. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  1332. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1333. $data['cat_info'] = made($data['cat_id'],[]);
  1334. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1335. $userCommon = \app\admin\common\User::getIns();
  1336. $sinfo = $userCommon->handle('sInfo',['code'=>$data['supplierNo']]);
  1337. $data['cgderid'] = $sinfo['data']['personid'] ?? '';
  1338. $data['cgder'] = $sinfo['data']['person'] ?? '';
  1339. $data['combind_list'] =[];
  1340. $data['wsm_list']=[];
  1341. $data['usable_stock']=(new GoodStock())->withJoin(['wsminfo'],'left')
  1342. ->where(['spuCode' => $supcode, 'wsm_type'=>[2,5]])
  1343. ->sum('usable_stock');
  1344. if($data['is_combind']==1){
  1345. $data['combind_list'] = (new GoodCombind())->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1346. foreach ($data['combind_list'] as &$item){
  1347. $item['stock'] =bcmul($item['child_num'],$data['usable_stock']);
  1348. }
  1349. $data['wsm_list']=(new GoodStock())->withJoin(['wsminfo'] , 'left')
  1350. ->where(['spuCode'=>$supcode , 'wsm_type'=>[2 , 5]])
  1351. ->column('good_stock.id stock_id,name,good_stock.wsm_code,usable_stock');
  1352. }
  1353. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  1354. if($data['brand_id']!=0){
  1355. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  1356. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1357. }else{
  1358. $data["brand_name"]="";
  1359. $data["brand_id"]="";
  1360. }
  1361. $excluse = makeExcluse($data['is_exclusive']);
  1362. $data['exclusive']=$excluse;
  1363. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  1364. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:'';
  1365. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  1366. $gold=[];
  1367. if ($data['is_gold_price'] == 1) {
  1368. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1369. }
  1370. $data['cgd_price'] = 0;
  1371. if($data['create_source']==1){
  1372. $data['cgd_price'] = Db::name("purchease_order")->where(["spuCode"=>$supcode,"order_type"=>3])->value
  1373. ("good_price",0);
  1374. }
  1375. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1376. $speclist=[];
  1377. if(!empty($spec)){
  1378. foreach ($spec as $value){
  1379. $temp=[];
  1380. $temp['id']=$value['id'];
  1381. $temp['spuCode']=$value['spuCode'];
  1382. $temp['spec_id']=$value['spec_id'];
  1383. $temp['spec_value_id']=$value['spec_value_id'];
  1384. $temp['is_del']=$value['is_del'];
  1385. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1386. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1387. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1388. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1389. $speclist[]=$temp;
  1390. }
  1391. }
  1392. $data["speclist"]=empty($speclist)?[]:$speclist;
  1393. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  1394. $nakearry=[];
  1395. if(!empty($nakelist)){
  1396. foreach ($nakelist as $value) {
  1397. $nakearry[] = $value;
  1398. }
  1399. }
  1400. $data["nakelist"]=$nakearry;
  1401. return app_show(0,"获取成功",$data);
  1402. }
  1403. //删除商品成本
  1404. public function delall()
  1405. {
  1406. $supcode = $this->request->post('codes', '', 'trim');
  1407. if ($supcode == "") {
  1408. return error_show(1004, "参数codes不能为空");
  1409. }
  1410. Db::startTrans();
  1411. try {
  1412. $good_basic = Db::name("good_basic")
  1413. ->field('id,spuCode,status')
  1414. ->where(["spuCode" => $supcode, "is_del" => 0])
  1415. ->select()->toArray();
  1416. if (empty($good_basic)) throw new Exception('该记录不存在或已删除');
  1417. $good = Db::name('good')
  1418. ->alias('g')
  1419. ->field('gp.id,gp.exam_status,gp.skuCode')
  1420. ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode AND gp.is_del=0')
  1421. ->where(['g.spuCode' => $supcode, 'g.is_del' => 0])
  1422. ->where('gp.exam_status',"<>",5)
  1423. ->select()->toArray();
  1424. if (!empty($good)) throw new Exception('该商品需要下线之后才能删除');
  1425. Db::name("good_basic")
  1426. ->where(["spuCode" => $supcode, 'is_del' => 0])
  1427. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1428. Db::name("good")
  1429. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1430. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1431. Db::name("good_platform")
  1432. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1433. ->where('exam_status', "<>",5)
  1434. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1435. Db::name("good_ladder")->where(["skuCode"=>array_column($good,"skuCode"),"is_del"=>0])->update(['is_del'
  1436. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1437. Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->update(['is_del'
  1438. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1439. ProcessOrder::workdel(["order_type" => "SPCB", "order_code" => $supcode]);
  1440. ProcessOrder::workdel(["order_type" => "SPSX", "order_code" => array_column($good,"skuCode")]);
  1441. Db::commit();
  1442. app_show(0, "删除成功");
  1443. } catch (Exception $exception) {
  1444. Db::rollback();
  1445. return error_show(1005, "删除失败," . $exception->getMessage());
  1446. }
  1447. }
  1448. //添加上线商品
  1449. public function online(){
  1450. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  1451. if($platform==""){
  1452. return error_show(1004,"参数platform不能为空");
  1453. }
  1454. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1455. if($spuCode===''){
  1456. return error_show(1004,"参数codes不能为空");
  1457. }
  1458. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  1459. if(empty($datas)){
  1460. return error_show(1004,"未找到商品数据");
  1461. }
  1462. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  1463. if($online_reason===""){
  1464. return error_show(1004,"参数online_reason不能为空");
  1465. }
  1466. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  1467. if($online_remark===""){
  1468. return error_show(1004,"参数online_remark不能为空");
  1469. }
  1470. $market_url= isset($this->post['market_url'])&&$this->post['market_url']!==''? trim($this->post['market_url']):'';
  1471. if($market_url===''){
  1472. return error_show(1004,'参数market_url不能为空');
  1473. }
  1474. $fixed = isset($this->post['is_fixed'])&&$this->post['is_fixed']!==''? intval($this->post['is_fixed']):1;
  1475. if($fixed==1){
  1476. //使用实时金价
  1477. $nake=Db::name('good_nake')->where(['spuCode'=> $spuCode,'is_del'=>0,"nake_fee"=>0])->findOrEmpty();
  1478. if(!empty($nake)) return error_show(1004,'一口价商品请先完善商品成本单价');
  1479. }
  1480. $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1481. $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1482. //区分是否是对接平台
  1483. $platform_info=Db::name('platform')
  1484. ->field('id,platform_type,is_select_pay_rate,status')
  1485. ->where(['is_del'=>0,'id'=>$platform])
  1486. ->findOrEmpty();
  1487. if(empty($platform_info)) return error_show(1005,'所选的平台不存在');
  1488. if($platform_info['status']!=1) return error_show(1005,'所选的平台已禁用');
  1489. if($platform_info['is_select_pay_rate']==1){
  1490. foreach ($datas as $ite){
  1491. if(channel_is_company($platform,$ite['companyNo'])) return error_show(1004, "商品{$ite['spuCode']}平台渠道含有业务公司{$ite['companyName']}");
  1492. }
  1493. }
  1494. if($platform_info['platform_type']==1){
  1495. if($fixed==0) return error_show(1005,'有赞平台商品不可使用实时金价');
  1496. return \app\youzan\logic\Goodup::create([
  1497. 'platform_id'=>$platform,
  1498. 'online_reason'=>$online_reason,
  1499. 'online_remark'=>$online_remark,
  1500. 'market_url'=>$market_url,
  1501. 'good_data'=>$datas,
  1502. 'createrid'=>$createrid,
  1503. 'creater'=>$creater,
  1504. ]);
  1505. }
  1506. $data=[];
  1507. $isonline=[];
  1508. $i=0;
  1509. Db::startTrans();
  1510. try{
  1511. foreach ($datas as $value){
  1512. $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count();
  1513. $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find();
  1514. if($ist){
  1515. $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1516. if($god){
  1517. $tp=[];
  1518. $tp['spuCode']=$value['spuCode'];
  1519. $tp['good_name']=$god['good_name'];
  1520. $tp['good_img']=$god['good_thumb_img'];
  1521. $tp['exam_status']=$ist['exam_status'];
  1522. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  1523. $speclist=[];
  1524. if(!empty($spec)){
  1525. foreach ($spec as $val){
  1526. $temp=[];
  1527. $temp['id']=$val['id'];
  1528. $temp['spuCode']=$val['spuCode'];
  1529. $temp['spec_id']=$val['spec_id'];
  1530. $temp['spec_value_id']=$val['spec_value_id'];
  1531. $temp['is_del']=$val['is_del'];
  1532. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1533. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1534. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1535. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1536. $speclist[]=$temp;
  1537. }
  1538. }
  1539. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1540. $isonline[]=$tp;
  1541. }
  1542. }
  1543. if(!empty($isonline)){
  1544. return app_show(1009,"存在已上线产品",$isonline);
  1545. }
  1546. //改变编码规则,将原来的skuCode后两位换成序列号
  1547. //str_pad字符串填充
  1548. $skuCode = makeNo("SN");
  1549. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1550. $tmp=[
  1551. "spuCode"=>$value['spuCode'],
  1552. "skuCode"=>$skuCode,
  1553. "platform_code"=>$platform,
  1554. "online_reason"=>$online_reason,
  1555. "online_remark"=>$online_remark,
  1556. "exam_status"=>$count>0 ?2:1,
  1557. "is_online"=>0,
  1558. "is_fixed"=>$fixed,
  1559. 'market_url'=>$market_url,
  1560. "status"=>1,
  1561. "is_del"=>0,
  1562. "creater"=>$creater,
  1563. "createrid"=>$createrid,
  1564. "addtime"=>date("Y-m-d H:i:s"),
  1565. "updatetime"=>date("Y-m-d H:i:s")
  1566. ];
  1567. $i++;
  1568. $create =Db::name("good_platform")->insert($tmp,true);
  1569. if($create>0){
  1570. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->findOrEmpty();
  1571. if(empty($iso)){
  1572. unset($value['id']);
  1573. $stock_num = Db::name('good_stock')->alias("a")
  1574. ->leftJoin("warehouse_info b","a.wsm_code=b.wsm_code")
  1575. ->where(['a.is_del' => 0, 'a.spuCode' =>$value['spuCode'],"b.wsm_type"=>[2,5]])->sum('usable_stock');
  1576. $value['usable_stock'] =$stock_num;
  1577. $value['addtime']=date("Y-m-d H:i:s");
  1578. $value['updatetime']=date("Y-m-d H:i:s");
  1579. }else{
  1580. $value['id']=$iso['id'];
  1581. $value['updatetime']=date("Y-m-d H:i:s");
  1582. }
  1583. $up = Db::name("good")->strict(false)->save($value);
  1584. if(!$up){
  1585. Db::rollback();
  1586. return error_show(1004,"提交失败");
  1587. }
  1588. //修改状态,添加待办
  1589. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1590. "order_code" => $skuCode,//编号
  1591. "status" => 0,
  1592. "action_remark" => '',//备注
  1593. "action_type" => 'create'//新建create,编辑edit,更改状态status
  1594. ], "SPSX", $tmp['exam_status'], $platform);
  1595. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1596. "order_type" => 'SPSX',
  1597. "order_code" => $skuCode,//咨询单详情编号
  1598. "order_id" => $create,
  1599. "order_status" => $tmp['exam_status'],
  1600. "before_status" => 0,
  1601. 'holder_id' => $createrid,
  1602. ]);
  1603. }else{
  1604. Db::rollback();
  1605. return error_show(1004,"提交失败");
  1606. }
  1607. }
  1608. Db::commit();
  1609. return app_show(0,"提交成功");
  1610. }catch (\Exception $e){
  1611. Db::rollback();
  1612. return error_show(1004, $e->getMessage());
  1613. }
  1614. }
  1615. //审核
  1616. public function online_exam(){
  1617. $post =$this->request->only([
  1618. "skuCode"=>"", //商品成本编号
  1619. "exam_status"=>"", //审核状态 1 提交待完善成本 2待审核 3上线完成 4 审核驳回 5 下线完成
  1620. "offline_reason"=>"", //下线原因
  1621. "offline_remark"=>"", //下线备注
  1622. "plat_code"=>"", //平台订单号
  1623. 'exam_remark'=>"", //审核备注
  1624. 'good_ladder'=>[], //售价阶梯
  1625. 'proof_type'=>"", // 售价凭证类型
  1626. 'proof_url'=>"", // 售价凭证
  1627. ],"post","trim");
  1628. $valide = Validate::rule([
  1629. "skuCode|商品编号"=>"require|max:255",
  1630. "exam_status|审核状态"=>"require|number|in:0,1,2,3,4,5",
  1631. "offline_reason|线下原因"=>"requireIf:exam_status,5|max:255",
  1632. "offline_remark|下线备注"=>"requireIf:exam_status,5|max:255",
  1633. "plat_code|平台商品编码"=>"requireIf:exam_status,3|max:255",
  1634. 'exam_remark|审核备注'=>"max:255",
  1635. 'good_ladder|售价阶梯'=>"requireIf:exam_status,3|array",
  1636. 'proof_type|售价凭证类型'=>"requireIf:exam_status,3|number|gt:0",
  1637. 'proof_url|售价凭证'=>"requireIf:exam_status,3|max:255",
  1638. ]);
  1639. if($valide->check($post)==false) return error_show(1004,$valide->getError());
  1640. $platform = Db::name("good_platform")->where(["skuCode"=>$post['skuCode'],"is_del"=>0])->find();
  1641. if($platform==false){
  1642. return error_show(1004,"未找到数据");
  1643. }
  1644. if($platform['is_fixed']==1){
  1645. //使用实时金价
  1646. $nake=Db::name('good_nake')->where(['spuCode'=> $platform['spuCode'],'is_del'=>0,'nake_fee'=>0])
  1647. ->findOrEmpty();
  1648. if(!empty($nake)) return error_show(1004,'一口价商品请先完善商品成本单价');
  1649. }
  1650. if($post['exam_status']==3){
  1651. $is_exit = Db::name("good_platform")
  1652. ->where(["plat_code" =>$post['plat_code'], "platform_code" => $platform['platform_code'], "is_del" =>0, 'exam_status' =>3])//exam_status==3已上线
  1653. ->where("id", "<>", $platform['id'])
  1654. ->find();
  1655. if($is_exit==false){
  1656. $platform['plat_code']=$post['plat_code'];
  1657. }else{
  1658. return error_show(1004,"平台商品编码 {$post['plat_code']} 已存在");
  1659. }
  1660. }
  1661. if($post['exam_status']==5){
  1662. $platform['is_compliance']=0;
  1663. $platform['compliance_remark']='';
  1664. }
  1665. $before = $platform['exam_status'];
  1666. $platform['exam_status']=$post['exam_status'];
  1667. $platform['updatetime']=date("Y-m-d H:i:s");
  1668. $createrid= $this->uid;
  1669. $creater= $this->uname;
  1670. Db::startTrans();
  1671. try {
  1672. $up = Db::name("good_platform")->save($platform);
  1673. if($up){
  1674. $data=[
  1675. "code"=>$platform['skuCode'],
  1676. "exam_status"=>$post['exam_status'],//$exam_status,
  1677. "type"=>2,
  1678. "exam_id"=>$createrid,
  1679. "exam_name"=>$creater,
  1680. "exam_remark"=>$post['exam_remark'],
  1681. "addtime"=>date("Y-m-d H:i:s")
  1682. ];
  1683. $inr=Db::name("good_exam")->insert($data);
  1684. if($inr){
  1685. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  1686. "order_code" => $platform['skuCode'],//编号
  1687. "status" => $before,
  1688. "action_remark" => '',//备注
  1689. "action_type" => "status"//新建create,编辑edit,更改状态status
  1690. ], "SPSX", $post['exam_status'], $platform);
  1691. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  1692. "order_type" => 'SPSX',
  1693. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1694. "order_id" => $platform['id'],
  1695. "order_status" => $post['exam_status'],
  1696. "before_status" => $before,
  1697. 'holder_id' => $platform['createrid'],
  1698. ]);
  1699. //如果是商品下线的话,记入商品下线记录表
  1700. if ($post['exam_status'] == 5) {
  1701. $offline_id = Db::name("good_offline_log")->insertGetId([
  1702. 'spuCode' => $platform['spuCode'],
  1703. 'skuCodes' => $platform['skuCode'],
  1704. 'good_name' => Db::name("good_basic")->where('spuCode', $platform['spuCode'])->value('good_name', ''),
  1705. 'offline_reason' => $post['offline_reason'],
  1706. 'offline_remark' => $post['offline_remark'],
  1707. 'createrid' => $createrid,
  1708. 'creater' => $creater,
  1709. 'addtime' => date('Y-m-d H:i:s'),
  1710. ]);
  1711. //根据权限查询应该接收商品下线通知的人员
  1712. $all_uid_name = Db::name('role_action')
  1713. ->whereFindInSet('action_conllect','877')//数据写死的,要注意各个环境数据是否一致
  1714. ->field('role_id')
  1715. ->buildSql();
  1716. $all_user = Db::name('user_role')
  1717. ->alias('ur')
  1718. ->where('ur.roleid IN '.$all_uid_name)
  1719. ->leftJoin('depart_user du','du.uid = ur.uid AND du.is_del=0')
  1720. ->column('ur.uid,du.nickName');
  1721. $insert_order_msg_data=[];
  1722. foreach ($all_user as $itemitem) {
  1723. $insert_order_msg_data[] = [
  1724. 'content' => '商品下线:' . $platform['spuCode'] . '由' . $creater . '操作下线',
  1725. 'orderCode' => $platform['skuCode'],
  1726. 'order_type' => 'GOL',
  1727. 'order_status' => 5,
  1728. 'order_id' => $offline_id,
  1729. 'apply_id' => $createrid,
  1730. 'apply_name' => $creater,
  1731. 'uid' => $itemitem['uid'],
  1732. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  1733. 'is_read' => 0,
  1734. 'addtime' => date('Y-m-d H:i:s'),
  1735. 'updatetime' => date('Y-m-d H:i:s'),
  1736. ];
  1737. }
  1738. //消息表
  1739. Db::name('order_msg')->insertAll($insert_order_msg_data);
  1740. }
  1741. if ($post['exam_status'] == 3) {
  1742. //todo::需要去掉;
  1743. $proof=[
  1744. 'spuCode'=>$platform['spuCode'],
  1745. 'proof_type'=>$post['proof_type'],
  1746. 'proof_url'=>$post['proof_url'],
  1747. 'is_del'=>0,
  1748. "creater"=>$this->uname,
  1749. "createrid"=>$this->uid,
  1750. "addtime"=>date("Y-m-d H:i:s"),
  1751. "updatetime"=>date("Y-m-d H:i:s")
  1752. ];
  1753. $inproof = Db::name("good_proof")->insert($proof);
  1754. if($inproof==false)throw new \Exception("商品凭证新建失败");
  1755. if(empty($post['good_ladder']))throw new \Exception("商品阶梯价不能为空");
  1756. foreach ($post['good_ladder'] as $value){
  1757. $lemp=[];
  1758. isset($value["id"])?$lemp['id']=$value['id']:$lemp['addtime'] = date("Y-m-d H:i:s");
  1759. $lemp['skuCode']=$platform['skuCode'];
  1760. $lemp['min_num'] = $value['min_num'];
  1761. $lemp['max_num'] = 0;
  1762. $lemp['sale_price'] = $value['sale_price'];
  1763. $lemp['market_price'] = $value['market_price'];
  1764. $lemp['market_platform'] = $value['market_platform'];
  1765. $lemp['cost_fee'] = $value['cost_fee'];
  1766. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1767. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1768. //$value["id"]?'':$lemp['addtime'] = date("Y-m-d H:i:s");$lemp['updatetime'] =date("Y-m-d H:i:s");
  1769. $ladderUp = Db::name("good_ladder")->save($lemp);
  1770. if($ladderUp==false) throw new \Exception("商品起订价修改失败");
  1771. }
  1772. }
  1773. Db::commit();
  1774. return app_show(0,"审核成功");
  1775. }else{
  1776. Db::rollback();
  1777. return error_show(1004,"审核失败");
  1778. }
  1779. }else{
  1780. Db::rollback();
  1781. return error_show(1004,"审核失败");
  1782. }
  1783. }catch (\Exception $e){
  1784. Db::rollback();
  1785. return error_show(1004,$e->getMessage());
  1786. }
  1787. }
  1788. //财务定价 废弃
  1789. public function editladder(){
  1790. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1791. if($skuCode===""){
  1792. return error_show(1004,"参数skuCode不能为空");
  1793. }
  1794. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1795. if($platform==false){
  1796. return error_show(1004,"未找到数据");
  1797. }
  1798. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1799. if($good_ladder==""){
  1800. return error_show(1004,"参数good_ladder不能为空");
  1801. }
  1802. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1803. if($proof_type===""){
  1804. return error_show(1004,"参数proof_type不能为空");
  1805. }
  1806. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1807. if($proof_url===""){
  1808. return error_show(1004,"参数proof_url不能为空");
  1809. }
  1810. $exam_remark = isset($this->post['exam_remark'])&& $this->post['exam_remark']!='' ? trim($this->post['exam_remark']):"";
  1811. $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1812. $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1813. $bifore=$platform['exam_status'];
  1814. $platform['exam_status']=4;
  1815. $platform['updatetime']=date("Y-m-d H:i:s");
  1816. Db::startTrans();
  1817. try {
  1818. foreach ($good_ladder as $value){
  1819. $lemp=[];
  1820. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1821. $lemp['skuCode']=$skuCode;
  1822. $lemp['min_num'] = $value['min_num'];
  1823. $lemp['max_num'] = 0;
  1824. $lemp['sale_price'] = $value['sale_price'];
  1825. $lemp['market_price'] = $value['market_price'];
  1826. $lemp['market_platform'] = $value['market_platform'];
  1827. $lemp['cost_fee'] = $value['cost_fee'];
  1828. $lemp['status'] = $value['status'];
  1829. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1830. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1831. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1832. $count = Db::name("good_ladder")->save($lemp);
  1833. if($count==false){
  1834. Db::rollback();
  1835. return app_show(1004,"商品起订价修改失败");
  1836. }
  1837. }
  1838. $up = Db::name("good_platform")->save($platform);
  1839. if($up){
  1840. // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1841. // "order_code" =>$platform['skuCode'],//咨询单详情编号
  1842. // "status" =>$bifore,//这里的status是之前的值
  1843. // "action_remark" => '',//备注
  1844. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  1845. // ], "SPSX", $platform['exam_status'],$platform);
  1846. //
  1847. // ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1848. // "order_type" => 'SPSX',
  1849. // "order_code" =>$platform['skuCode'],//咨询单详情编号
  1850. // "order_id" => $platform['id'],
  1851. // "order_status" => $platform['exam_status'],
  1852. // "before_status"=>$bifore,
  1853. // 'holder_id' => $platform['createrid'],
  1854. // ]);
  1855. $proof=[
  1856. 'spuCode'=>$platform['spuCode'],
  1857. 'proof_type'=>$proof_type,
  1858. 'proof_url'=>$proof_url,
  1859. 'is_del'=>0,
  1860. "creater"=>$creater,
  1861. "createrid"=>$createrid,
  1862. "addtime"=>date("Y-m-d H:i:s"),
  1863. "updatetime"=>date("Y-m-d H:i:s")
  1864. ];
  1865. $inproof = Db::name("good_proof")->insert($proof);
  1866. if($inproof==false){
  1867. Db::rollback();
  1868. return app_show(1004,"商品凭证新建失败");
  1869. }
  1870. $data=[
  1871. "code"=>$platform['skuCode'],
  1872. "type"=>2,
  1873. "exam_status"=>$bifore,//4,
  1874. "exam_id"=>$createrid,
  1875. "exam_name"=>$creater,
  1876. "exam_remark"=>$exam_remark,
  1877. "addtime"=>date("Y-m-d H:i:s")
  1878. ];
  1879. $inr=Db::name("good_exam")->insert($data);
  1880. if($inr){
  1881. Db::commit();
  1882. return app_show(0,"审核成功");
  1883. }else{
  1884. Db::rollback();
  1885. return error_show(1004,"审核失败");
  1886. }
  1887. }else{
  1888. Db::rollback();
  1889. return error_show(1004,"审核失败");
  1890. }
  1891. }catch (\Exception $e){
  1892. Db::rollback();
  1893. return error_show(1004,$e->getMessage());
  1894. }
  1895. }
  1896. public function prooflist(){
  1897. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1898. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1899. $where =[["is_del","=",0]];
  1900. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1901. if($spuCode!==""){
  1902. $where[]=["spuCode","like","%$spuCode%"];
  1903. }
  1904. $count = Db::name("good_proof")->where($where)->count();
  1905. $total = ceil($count / $size);
  1906. $page = $page >= $total ? $total : $page;
  1907. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1908. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1909. }
  1910. /**
  1911. * 已下线商品重新发起上线流程
  1912. */
  1913. public function againOnline(){
  1914. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1915. if($skuCode===""){
  1916. return error_show(1004,"参数skuCode不能为空");
  1917. }
  1918. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1919. if($platform==false){
  1920. return error_show(1004,"未找到数据");
  1921. }
  1922. if(!in_array($platform["exam_status"],[4,5])){
  1923. return error_show(1004,"商品状态有误");
  1924. }
  1925. //判断平台商品编码是否重复
  1926. // $rs = Db::name("good_platform")
  1927. // ->field('id')
  1928. // ->where(["plat_code" => $platform['plat_code'],"platform_code" => $platform['platform_code'], 'exam_status' => 6, "is_del" => 0])//exam_status==6已上线
  1929. // ->where('id', '<>', $platform['id'])
  1930. // ->find();
  1931. // if (!empty($rs)) return error_show(1005, '该商品的平台商品编码已被使用');
  1932. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1933. $bifore=$platform['exam_status'];
  1934. $platform['exam_status'] = empty($nake)?1:2;
  1935. $platform['updatetime'] = date("Y-m-d H:i:s");
  1936. $createrid= $this->uid;
  1937. $creater= $this->uname;
  1938. Db::startTrans();
  1939. try {
  1940. $save =Db::name("good_platform")->save($platform);
  1941. if($save){
  1942. ActionLog::logAdd(['id'=>$createrid,'nickname'=>$creater], [
  1943. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1944. "status" =>$bifore,//这里的status是之前的值
  1945. "action_remark" => '',//备注
  1946. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1947. ], "SPSX", $platform['exam_status'],$platform);
  1948. ProcessOrder::AddProcess(['id'=>$createrid,'nickname'=>$creater], [
  1949. "order_type" => 'SPSX',
  1950. "order_code" =>$platform['skuCode'],//咨询单详情编号
  1951. "order_id" => $platform['id'],
  1952. "order_status" => $platform['exam_status'],
  1953. "before_status"=>$bifore,
  1954. 'holder_id' => $platform['createrid'],
  1955. ]);
  1956. $data=[
  1957. "code"=>$platform['skuCode'],
  1958. "type"=>2,
  1959. "exam_status"=>$platform['exam_status'],//$platform['exam_status'] ,
  1960. "exam_id"=>$createrid,
  1961. "exam_name"=>$creater,
  1962. "exam_remark"=>'',
  1963. "addtime"=>date("Y-m-d H:i:s")
  1964. ];
  1965. $inr=Db::name("good_exam")->insert($data);
  1966. //修改状态,添加待办
  1967. if($inr){
  1968. //将good_basic数据同步到good表
  1969. $good_basic = Db::name('good_basic')
  1970. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1971. ->find();
  1972. if (!empty($good_basic)) {
  1973. unset($good_basic['id']);
  1974. unset($good_basic['addtime']);
  1975. $good_basic['updatetime'] = date('Y-m-d H:i:s');
  1976. Db::name('good')
  1977. ->strict(false)
  1978. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1979. ->update($good_basic);
  1980. }
  1981. Db::commit();
  1982. return app_show(0,"审核成功");
  1983. }
  1984. }
  1985. Db::rollback();
  1986. return error_show(1004,"审核失败");
  1987. }catch (\Exception $e){
  1988. Db::rollback();
  1989. return error_show(1004,$e->getMessage());
  1990. }
  1991. }
  1992. public function copy(){
  1993. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1994. if($supcode==""){
  1995. return error_show(1004,"参数spuCode不能为空");
  1996. }
  1997. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1998. if($data==false){
  1999. return error_show(1004,"未找到商品数据");
  2000. }
  2001. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  2002. if($token==''){
  2003. return error_show(105,"参数token不能为空");
  2004. }
  2005. $createrid= $this->uid;
  2006. $creater= $this->uname;
  2007. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  2008. $ladd=[];
  2009. $newCode =makeNo("SKU");
  2010. if($data['is_combind']==1){
  2011. $newCode =makeNo('SSU');
  2012. $combindList = (new GoodCombind())->where(["spuCode"=>$supcode,"is_del"=>0])->hidden(["id"])
  2013. ->select()->toArray();
  2014. if(!empty($combindList)){
  2015. foreach ($combindList as &$item){
  2016. $item['spuCode']=$newCode;
  2017. $item['good_name']=$data['good_name'];
  2018. }
  2019. }
  2020. }
  2021. if(!empty($nake)){
  2022. foreach ($nake as $value){
  2023. $tmp=[];
  2024. $tmp['spuCode']=$newCode;
  2025. $tmp['min_num']=$value['min_num'];
  2026. $tmp['nake_fee'] = $value['nake_fee'];
  2027. $tmp['cost_fee'] = $value['cost_fee'];
  2028. $tmp['delivery_fee'] = $value['delivery_fee'];
  2029. $tmp['cert_fee'] = $value['cert_fee'];
  2030. $tmp['mark_fee'] = $value['mark_fee'];
  2031. $tmp['package_fee'] = $value['package_fee'];
  2032. $tmp['other_fee'] = $value['other_fee'];
  2033. $tmp['nake_total'] =$value['nake_total'];
  2034. $tmp['creater_id']=$createrid;
  2035. $tmp['creater']=$creater;
  2036. $tmp['is_del']=$value['is_del'];
  2037. $tmp['addtime']=date("Y-m-d H:i:s");
  2038. $tmp['updatetime']=date("Y-m-d H:i:s");
  2039. $ladd[]=$tmp;
  2040. }
  2041. }
  2042. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  2043. $specArr=[];
  2044. if(!empty($spec)){
  2045. foreach ($spec as $value){
  2046. $tmp=[];
  2047. $tmp['spuCode']=$newCode;
  2048. $tmp['spec_id']=$value['spec_id'];
  2049. $tmp['spec_value_id']=$value['spec_value_id'];
  2050. $tmp['is_del']=$value['is_del'];
  2051. $tmp['addtime']=date("Y-m-d H:i:s");
  2052. $tmp['updatetime']=date("Y-m-d H:i:s");
  2053. $specArr[]=$tmp;
  2054. }
  2055. }
  2056. Db::startTrans();
  2057. try {
  2058. unset($data['id']);
  2059. $data['spuCode']=$newCode;
  2060. $data['createrid']=$createrid;
  2061. $data['creater']=$creater;
  2062. $data['status']=7;
  2063. $data['addtime']=date("Y-m-d H:i:s");
  2064. $data['updatetime']=date("Y-m-d H:i:s");
  2065. $cre = Db::name("good_basic")->insertGetId($data);
  2066. if($cre){
  2067. //修改状态,添加待办
  2068. ActionLog::logAdd($this->post['token'], [
  2069. "order_code" =>$newCode,//咨询单详情编号
  2070. "status" => 0,//这里的status是之前的值
  2071. "action_remark" => '',//备注
  2072. "action_type" => "create"//新建create,编辑edit,更改状态status
  2073. ], "SPCB", 7,$data);
  2074. ProcessOrder::AddProcess($this->post['token'], [
  2075. "order_type" => 'SPCB',
  2076. "order_code" =>$newCode,//咨询单详情编号
  2077. "order_id" => $cre,
  2078. "order_status" =>7,
  2079. "before_status"=>0,
  2080. 'holder_id'=>$data['createrid'],
  2081. ]);
  2082. if(!empty($ladd)){
  2083. $na = Db::name("good_nake")->insertAll($ladd);
  2084. if($na==0){
  2085. throw new \Exception('成本数据复制失败');
  2086. }
  2087. }
  2088. if(!empty($specArr)){
  2089. $sp = Db::name("good_spec")->insertAll($specArr);
  2090. if($sp==0){
  2091. throw new \Exception('规格数据复制失败');
  2092. }
  2093. }
  2094. if(!empty($combindList)){
  2095. $in =(new GoodCombind())->saveAll($combindList);
  2096. if($in->isEmpty()){
  2097. throw new \Exception("组合商子商品品信息复制失败");
  2098. }
  2099. }
  2100. Db::commit();
  2101. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  2102. }else{
  2103. throw new \Exception('数据复制失败');
  2104. }
  2105. }catch (\Exception $e){
  2106. Db::rollback();
  2107. return error_show(1004,$e->getMessage());
  2108. }
  2109. }
  2110. public function edit(){
  2111. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  2112. if($supcode==""){
  2113. return error_show(1004,"参数spuCode不能为空");
  2114. }
  2115. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  2116. if($data==false){
  2117. return error_show(1004,"未找到商品数据");
  2118. }
  2119. $is_down = Db::name("good_platform")
  2120. ->where(["spuCode"=>$supcode,"is_del"=>0])
  2121. ->where("exam_status", "not in", [1, 5])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑
  2122. ->find();
  2123. if($is_down!=false){
  2124. return error_show(1004,"存在未下线商品数据");
  2125. }
  2126. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  2127. return error_show(1004,"商品状态有误");
  2128. }
  2129. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  2130. if($good_name==""){
  2131. return error_show(1004,"商品名称不能为空");
  2132. }
  2133. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  2134. if($cat_id==''){
  2135. return error_show(1004,"商品分类不能为空");
  2136. }
  2137. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  2138. // if($brandid==''){
  2139. // return error_show(1004,"商品品牌不能为空");
  2140. // }
  2141. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  2142. if($unit==''){
  2143. return error_show(1004,"商品单位不能为空");
  2144. }
  2145. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  2146. if($good_type===''){
  2147. return error_show(1004,"参数good_type不能为空");
  2148. }
  2149. $moq=0;
  2150. $customized=0;
  2151. if($good_type==1){
  2152. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  2153. if($moq===''){
  2154. return error_show(1004,"定制商品起订量不能为空");
  2155. }
  2156. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  2157. if($customized===''){
  2158. return error_show(1004,"参数customized不能为空");
  2159. }
  2160. }
  2161. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  2162. if($is_exclusive===''){
  2163. return error_show(1004,"参数is_exclusive不能为空");
  2164. }
  2165. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  2166. // if($customized===''){
  2167. // return error_show(1004,"参数customized不能为空");
  2168. // }
  2169. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  2170. if($tax===''){
  2171. return error_show(1004,"参数tax不能为空");
  2172. }
  2173. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=''? trim($this->post['companyNo']) :'';
  2174. if($company_id==''){
  2175. return error_show(1004,'参数companyNo不能为空');
  2176. }
  2177. $userCommon= \app\admin\common\User::getIns();
  2178. $companyinfo =$userCommon->handle('getCodeAndName',['code'=>$company_id]);
  2179. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  2180. $isCombind= $data['is_combind'];
  2181. $supplierArr=[];
  2182. $supplier=[];
  2183. if($supplierNo==''){
  2184. return error_show(1004,"参数supplierNo不能为空");
  2185. }
  2186. if (($this->level == 2) && ($supplierNo != $data['supplierNo'])) {
  2187. $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
  2188. if (isset($supplier_account[$supplierNo])) return json_show(1004, '该供应商已开通账号,不允许操作');
  2189. if (isset($supplier_account[$data['supplierNo']])) return json_show(1004, '原供应商已开通账号,不允许操作');
  2190. }
  2191. $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
  2192. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
  2193. $supplierArr=$supplier_temp['data']??[];
  2194. $supplier=$supplierArr['child']??[];
  2195. if($supplierArr['relation_code']==$company_id){
  2196. return error_show(1004,'业务公司与供应商属于同一家公司');
  2197. }
  2198. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
  2199. if($good_size==''){
  2200. return error_show(1004,"参数good_size不能为空");
  2201. }
  2202. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  2203. if($is_auth===''){
  2204. return error_show(1004,"参数is_auth不能为空");
  2205. }
  2206. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  2207. // if($auth_img==''){
  2208. // return error_show(1004,"商品不能为空");
  2209. // }
  2210. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  2211. if($after_sales==""){
  2212. return error_show(1004,"参数after_sales不能为空");
  2213. }
  2214. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  2215. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  2216. if($good_remark===""){
  2217. return error_show(1004,"参数good_remark不能为空");
  2218. }
  2219. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  2220. if($weight===""){
  2221. return error_show(1004,"参数weight不能为空");
  2222. }
  2223. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  2224. if($packing_way===""){
  2225. return error_show(1004,"参数packing_way不能为空");
  2226. }
  2227. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  2228. if($packing_size===""){
  2229. return error_show(1004,"参数packing_size不能为空");
  2230. }
  2231. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  2232. if($packing_spec===""){
  2233. return error_show(1004,"参数packing_spec不能为空");
  2234. }
  2235. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  2236. if($packing_weight===""){
  2237. return error_show(1004,"参数packing_weight不能为空");
  2238. }
  2239. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  2240. if($packing_list===""){
  2241. return error_show(1004,"参数packing_list不能为空");
  2242. }
  2243. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  2244. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  2245. if($supply_area===""){
  2246. return error_show(1004,"参数supply_area不能为空");
  2247. }
  2248. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  2249. if($delivery_place===""){
  2250. return error_show(1004,"参数delivery_place不能为空");
  2251. }
  2252. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  2253. if($origin_place===""){
  2254. return error_show(1004,"参数origin_place不能为空");
  2255. }
  2256. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  2257. if($delivery_day===""){
  2258. return error_show(1004,"参数delivery_day不能为空");
  2259. }
  2260. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  2261. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  2262. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  2263. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  2264. if($good_img===""){
  2265. return error_show(1004,"参数good_img不能为空");
  2266. }
  2267. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  2268. if($good_thumb_img===""){
  2269. return error_show(1004,"参数good_thumb_img不能为空");
  2270. }
  2271. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  2272. if($good_info_img===""){
  2273. return error_show(1004,"参数good_info_img不能为空");
  2274. }
  2275. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  2276. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  2277. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  2278. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  2279. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  2280. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  2281. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  2282. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  2283. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  2284. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  2285. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  2286. if($market_price===""){
  2287. return error_show(1004,"参数market_price不能为空");
  2288. }
  2289. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  2290. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  2291. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  2292. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  2293. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  2294. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  2295. if($is_stock==1 && $stock_moq ==0){
  2296. return error_show(1004,"库存品备库起订量不能为零");
  2297. }
  2298. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  2299. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  2300. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  2301. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!=""? trim($this->post['proof_type']):"";
  2302. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!=""? trim($this->post['proof_url']):"";
  2303. $combindList = $this->post['combind_list']??[];
  2304. if($isCombind==1){
  2305. if(empty($combindList)) return error_show(1004,'组合商品子商品信息不能为空');
  2306. $dchild=[];
  2307. $valid = Validate::rule(['childCode|子商品成本编号'=>'require','child_name|子商品名称'=>'require','child_num|组合比例'=>'require|number|gt:0']);
  2308. foreach ($combindList as $value){
  2309. if($valid->check($value)==false)return error_show(1004,$valid->getError());
  2310. $value['spuCode'] = $data['spuCode'];
  2311. $value['good_name'] =$good_name;
  2312. $value['updatetime'] =date('Y-m-d H:i:s');
  2313. if($value['is_del']==1){
  2314. $usable_stock = Db::name('good')->where(['spuCode'=>$data['spuCode']])->value('usable_stock',0);
  2315. if($usable_stock>0) return error_show(1004,'组合商品库存未处理完不可删除子商品');
  2316. }
  2317. $dchild[]=$value;
  2318. }
  2319. }
  2320. Db::startTrans();
  2321. try {
  2322. $temp=[
  2323. "good_name"=>$good_name,
  2324. "cat_id"=>$cat_id,
  2325. 'brand_id'=>$brandid,
  2326. "good_unit"=>$unit,
  2327. "good_type"=>$good_type,
  2328. "companyNo"=>$company_id,
  2329. "companyName"=>$companyinfo['data'][$company_id]??"",
  2330. "moq"=>$moq,
  2331. "is_exclusive"=>$is_exclusive,
  2332. "customized"=>$customized,
  2333. "tax"=>$tax,
  2334. "supplierNo"=>$supplierNo,
  2335. "supplierName"=>$supplierArr['name']??"",
  2336. "is_auth"=>$is_auth,
  2337. "good_size"=>$good_size,
  2338. "auth_img"=>$auth_img,
  2339. "after_sales"=>$after_sales,
  2340. "craft_desc"=>$craft_desc,
  2341. "good_remark"=>$good_remark,
  2342. "weight"=>$weight,
  2343. "packing_way"=>$packing_way,
  2344. "packing_size"=>$packing_size,
  2345. "packing_spec"=>$packing_spec,
  2346. "packing_list"=>$packing_list,
  2347. "packing_weight"=>$packing_weight,
  2348. "good_bar"=>$good_bar,
  2349. "supply_area"=>$supply_area,
  2350. "delivery_place"=>$delivery_place,
  2351. "origin_place"=>$origin_place,
  2352. "delivery_day"=>$delivery_day,
  2353. "lead_time"=>$lead_time,
  2354. "sample_day"=>$sample_day,
  2355. "sample_fee"=>$sample_fee,
  2356. "good_img"=>$good_img,
  2357. "good_thumb_img"=>$good_thumb_img,
  2358. "good_info_img"=>$good_info_img,
  2359. "cert_fee"=>$cert_fee,
  2360. "packing_fee"=>$packing_fee,
  2361. "is_diff"=>$is_diff,
  2362. "config"=>$config,
  2363. "other_config"=>$other_config,
  2364. "is_stock"=>$is_stock,
  2365. "cost_fee"=>$cost_fee,
  2366. "mark_fee"=>$mark_fee,
  2367. "demo_fee"=>$demo_fee,
  2368. "open_fee"=>$open_fee,
  2369. "noble_metal"=>$noble_metal,
  2370. "noble_weight"=>$noble_weight,
  2371. "is_gold_price"=>$is_gold_price,
  2372. "market_price"=>$market_price,
  2373. "nake_price"=>$nake_price,
  2374. "cgd_gold_price"=>$cgd_gold_price,
  2375. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  2376. "stock_moq"=>$stock_moq,
  2377. "status"=>"0",
  2378. 'is_combind'=>$isCombind,
  2379. "updatetime"=>date("Y-m-d H:i:s"),
  2380. 'is_support_barter'=>$is_support_barter,
  2381. 'chargerid' => $supplier['personid'] ?? $this->uid,
  2382. 'charger' => $supplier['person'] ?? $this->uname,
  2383. ];
  2384. $field = array_diff_assoc($temp,$data);
  2385. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  2386. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  2387. $var = array_diff($temp,$data);
  2388. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  2389. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  2390. if($up){
  2391. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  2392. // //修改状态,添加待办
  2393. // ActionLog::logAdd($this->post['token'], [
  2394. // "order_code" =>$supcode,//咨询单详情编号
  2395. // "status" => $data['status'],//这里的status是之前的值
  2396. // "action_remark" => '',//备注
  2397. // "action_type" => "create"//新建create,编辑edit,更改状态status
  2398. // ], "SPCB", 0,$temp);
  2399. //
  2400. // ProcessOrder::AddProcess($this->post['token'], [
  2401. // "order_type" => 'SPCB',
  2402. // "order_code" =>$supcode,//咨询单详情编号
  2403. // "order_id" => $data['id'],
  2404. // "order_status" =>0,
  2405. // "before_status"=>0,
  2406. // 'holder_id'=>$data['createrid'],
  2407. // ]);
  2408. if($speclist!=="" && !empty($speclist)){
  2409. foreach ($speclist as $value){
  2410. $lemp=[];
  2411. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2412. $lemp['spuCode']=$supcode;
  2413. $lemp['spec_id'] = $value['spec_id'];
  2414. $lemp['spec_value_id'] = $value['spec_value_id'];
  2415. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2416. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2417. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2418. $count = Db::name("good_spec")->save($lemp);
  2419. if($count==false){
  2420. Db::rollback();
  2421. return app_show(1004,"商品规格值修改失败");
  2422. }
  2423. }
  2424. }
  2425. if($proof_url!=''){
  2426. $proof=[
  2427. 'spuCode'=>$supcode,
  2428. 'proof_type'=>$proof_type,
  2429. 'proof_url'=>$proof_url,
  2430. 'is_del'=>0,
  2431. "creater"=>$this->uname,
  2432. "createrid"=>$this->uid,
  2433. "addtime"=>date("Y-m-d H:i:s"),
  2434. "updatetime"=>date("Y-m-d H:i:s")
  2435. ];
  2436. $inproof = Db::name("good_proof")->insert($proof);
  2437. if($inproof==false)throw new \Exception("商品凭证新建失败");
  2438. }
  2439. if($good_ladder!=="" && !empty($good_ladder)){
  2440. // $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  2441. $top_cat_id = made($cat_id);//获取所有分类
  2442. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2443. foreach ($good_ladder as $value){
  2444. $lemp=[];
  2445. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2446. $lemp['spuCode']=$supcode;
  2447. $lemp['min_num'] = $value['min_num'];
  2448. $lemp['nake_fee'] = $value['nake_fee'];
  2449. $lemp['cost_fee'] = $value['cost_fee'];
  2450. $lemp['delivery_fee'] = $value['delivery_fee'];
  2451. $lemp['cert_fee'] = $value['cert_fee'];
  2452. $lemp['mark_fee'] = $value['mark_fee'];
  2453. $lemp['package_fee'] = $value['package_fee'];
  2454. $lemp['other_fee'] = $value['other_fee'];
  2455. if ($is_gold_price == 1 && $top_cat_id == 6) {
  2456. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  2457. //$lemp['nake_total'] =$noble_weight*$gold['price'] + $value['cost_fee']*$noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  2458. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  2459. //成本总计启用实时金价时,采用供应商实时金价
  2460. $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight +
  2461. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  2462. }else{
  2463. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  2464. }
  2465. $lemp['creater_id'] = $this->uid;
  2466. $lemp['creater'] = $this->uname;
  2467. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2468. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2469. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2470. $count = Db::name("good_nake")->save($lemp);
  2471. if($count==false){
  2472. Db::rollback();
  2473. return app_show(1004,"商品规成本修改失败");
  2474. }
  2475. }
  2476. }
  2477. if($isCombind==1 && !empty($dchild)){
  2478. (new GoodCombind())->saveAll($dchild);
  2479. }
  2480. Db::commit();
  2481. return app_show(0,"更新成功");
  2482. }else{
  2483. Db::rollback();
  2484. return error_show(1005,"更新失败");
  2485. }
  2486. }catch (\Exception $e){
  2487. Db::rollback();
  2488. return error_show(1004,$e->getMessage());
  2489. }
  2490. }
  2491. public function checkPrice(){
  2492. $param = $this->request->only(['spuCode', 'min_num', 'platform_id', 'relaComNo',"is_fixed"], 'post', 'trim');
  2493. $val = Validate::rule([
  2494. 'spuCode|商品成本编码' => 'require',
  2495. 'min_num|起订量' => 'require|number|gt:0',
  2496. 'platform_id|上线平台ID' => 'require|number|gt:0',
  2497. 'is_fixed|定价模式' => 'require|number|in:0,1',
  2498. 'relaComNo'=>'require'
  2499. ]);
  2500. if($val->check($param) == false) return json_show(1005,$val->getError());
  2501. $good =Db::name("good_basic")
  2502. ->field('id,is_stock,cat_id,is_gold_price,noble_weight,cgd_gold_price')
  2503. ->where(["spuCode"=>$param['spuCode'],"is_del"=>0])
  2504. ->findOrEmpty();
  2505. if(empty($good)) return json_show(1005,"商品数据未找到");
  2506. // $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  2507. // if($num==""){
  2508. // return error_show(1005,"参数min_num不能为空");
  2509. // }
  2510. $nakelist = Db::name("good_nake")
  2511. ->where(['spuCode'=>$param['spuCode'],"is_del"=>0])
  2512. ->where([["min_num","<=",$param['min_num']]])
  2513. ->order("min_num desc")
  2514. ->find();
  2515. if($nakelist==false){
  2516. $nakelist = Db::name("good_nake")
  2517. ->where(['spuCode'=>$param['spuCode'],"is_del"=>0])
  2518. ->order("min_num asc")
  2519. ->find();
  2520. //非库存品的话,继续校验最小起订量
  2521. //库存品的话,不足采购起订量的时候,取采购最小起订量
  2522. if ($good['is_stock'] == 0) return error_show(1010, "起订量不足{$nakelist['min_num']}");
  2523. }
  2524. //计算毛利率
  2525. $budget = get_budget($good['cat_id'],$param['relaComNo'],$param['platform_id']);
  2526. $top_cat_id = made($good['cat_id']);//获取所有分类
  2527. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2528. $sale_cost_fee = 0;
  2529. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  2530. // $saleprice = $good['noble_weight']*$good["cgd_gold_price"] + $nakelist['cost_fee']/(1-$budget)*$good['noble_weight']+$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['nake_fee']+$nakelist['delivery_fee'];
  2531. if($param['is_fixed']==0) $nakelist['nake_fee']=0;
  2532. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  2533. $saleprice = ($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee']) / (1 - $budget);
  2534. //计算工艺费
  2535. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  2536. $sale_cost_fee = (($good['noble_weight'] * $good["cgd_gold_price"] + $nakelist['cost_fee'] * $good['noble_weight'] + $nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['other_fee'] + $nakelist['delivery_fee']) / (1 - $budget) - ($nakelist['package_fee'] + $nakelist['mark_fee'] + $nakelist['cert_fee'] + $nakelist['nake_fee'] + $nakelist['delivery_fee'] + $nakelist['other_fee'])) / $good['noble_weight'] - $good["cgd_gold_price"];
  2537. }else{
  2538. // $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  2539. // (加标费+包装费+证书费+成本裸价+运费)/(1-成本售价/100)=系统售价
  2540. // $saleprice = (加标费 + 包装费 + 证书费 + 运费 + 成本裸价+其他费用) / (1 - $budget);
  2541. $saleprice = $nakelist['nake_total'] / (1 - $budget);
  2542. }
  2543. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  2544. }
  2545. //咨询成交商品池 添加上线商品
  2546. public function onlineZixunGoods()
  2547. {
  2548. $param = $this->request->only([
  2549. 'platform',
  2550. "is_fixed",
  2551. 'codes',
  2552. 'online_reason',
  2553. 'online_remark',
  2554. 'token'], 'post', 'trim');
  2555. $val = Validate::rule([
  2556. 'platform|所选上线平台' => 'require|number|gt:0',
  2557. 'codes|所选上线商品编号' => 'require',
  2558. 'is_fixed|是否一口价' => 'require|number|in:0,1',
  2559. 'online_reason|上线原因' => 'require',
  2560. 'online_remark|上线备注' => 'require',
  2561. 'token' => 'require',
  2562. ]);
  2563. if (!$val->check($param)) return error_show(1004, $val->getError());
  2564. $good_zixun_list = Db::name("good_zixun")
  2565. ->where(["is_del" => 0])
  2566. ->whereIn('spuCode', $param['codes'])
  2567. ->column('*', 'spuCode');
  2568. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  2569. $a = array_diff($param['codes'], array_keys($good_zixun_list));
  2570. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  2571. $isonline = Db::name("good_platform")
  2572. ->alias('gp')
  2573. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  2574. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  2575. ->whereIn('gp.spuCode', $param['codes'])
  2576. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  2577. ->select()
  2578. ->toArray();
  2579. if (!empty($isonline)) {
  2580. foreach ($isonline as &$v) {
  2581. $spec = Db::name("good_spec")
  2582. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  2583. ->select()
  2584. ->toArray();
  2585. $speclist = [];
  2586. if (!empty($spec)) {
  2587. foreach ($spec as $val) {
  2588. $temp = [];
  2589. $temp['id'] = $val['id'];
  2590. $temp['spuCode'] = $val['spuCode'];
  2591. $temp['spec_id'] = $val['spec_id'];
  2592. $temp['spec_value_id'] = $val['spec_value_id'];
  2593. $temp['is_del'] = $val['is_del'];
  2594. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2595. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2596. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2597. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2598. $speclist[] = $temp;
  2599. }
  2600. }
  2601. $v["speclist"] = empty($speclist) ? [] : $speclist;
  2602. }
  2603. return app_show(1009, "存在已上线产品", $isonline);
  2604. }
  2605. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  2606. $user = GetUserInfo($param['token']);
  2607. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  2608. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  2609. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2610. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  2611. $i = 0;
  2612. $all_nakes = Db::name("good_nake")
  2613. ->where(["is_del" => 0])->fetchSql()
  2614. ->whereIn('spuCode', $param['codes'])
  2615. ->group('spuCode')
  2616. ->column('count(`id`) total', 'spuCode');
  2617. $all_good = Db::name('good')
  2618. ->where('is_del', 0)
  2619. ->whereIn('spuCode', $param['codes'])
  2620. ->column('id', 'spuCode');
  2621. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  2622. $all_good_basic = Db::name('good_basic')
  2623. ->where('is_del', 0)
  2624. ->whereIn('spuCode', $param['codes'])
  2625. ->column('id', 'spuCode');
  2626. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  2627. foreach ($param['codes'] as $value) {
  2628. if($good_zixun_list[$value]['is_gold_price']==1&&$param['is_fixed']==1){
  2629. return error_show(1004," {$good_zixun_list[$value]['good_name']}商品使用实时金价,不可使用一口价!");
  2630. }
  2631. //改变编码规则,将原来的skuCode后两位换成序列号
  2632. //str_pad字符串填充
  2633. $skuCode = makeNo("SN");
  2634. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2635. $data[] = [
  2636. "spuCode" => $value,
  2637. "skuCode" => $skuCode,
  2638. "platform_code" => $param['platform'],
  2639. "online_reason" => $param['online_reason'],
  2640. "online_remark" => $param['online_remark'],
  2641. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  2642. "is_online" => 0,
  2643. "is_fixed" =>$param['is_fixed'],
  2644. "status" => 0,
  2645. "is_del" => 0,
  2646. "creater" => $creater,
  2647. "createrid" => $createrid,
  2648. "addtime" => date("Y-m-d H:i:s"),
  2649. "updatetime" => date("Y-m-d H:i:s")
  2650. ];
  2651. //good表
  2652. if (!isset($all_good[$value])) {
  2653. $good_insert_data[] = [
  2654. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2655. 'good_code' => $good_zixun_list[$value]['good_code'],
  2656. 'good_name' => $good_zixun_list[$value]['good_name'],
  2657. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2658. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2659. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2660. 'good_type' => $good_zixun_list[$value]['good_type'],
  2661. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2662. 'companyName' => $good_zixun_list[$value]['companyName'],
  2663. 'moq' => $good_zixun_list[$value]['moq'],
  2664. 'customized' => $good_zixun_list[$value]['customized'],
  2665. 'tax' => $good_zixun_list[$value]['tax'],
  2666. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2667. 'supplierName' => $good_zixun_list[$value]['supplierName'],
  2668. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2669. 'is_stock' => '',
  2670. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2671. 'after_sales' => '',
  2672. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2673. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2674. 'good_size' => '',
  2675. 'weight' => $good_zixun_list[$value]['weight'],
  2676. 'packing_way' => '',
  2677. 'packing_size' => '',
  2678. 'packing_spec' => '',
  2679. 'packing_list' => '',
  2680. 'packing_weight' => '',
  2681. 'good_bar' => '',
  2682. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2683. 'delivery_place' => '',
  2684. 'origin_place' => '',
  2685. 'delivery_day' => 0,
  2686. 'lead_time' => '',
  2687. 'sample_day' => '',
  2688. 'sample_fee' => '',
  2689. 'good_img' => $good_zixun_list[$value]['good_img'],
  2690. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2691. 'good_info_img' => $good_zixun_list[$value]['good_info_img'],
  2692. 'cert_fee' => '',
  2693. 'packing_fee' => '',
  2694. 'cost_fee' => '',
  2695. 'mark_fee' => '',
  2696. 'demo_fee' => '',
  2697. 'open_fee' => '',
  2698. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2699. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2700. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2701. 'cgd_gold_price' => '',
  2702. 'market_price' => '',
  2703. 'nake_price' => '',
  2704. 'is_step' => '',
  2705. 'is_online' => '',
  2706. 'status' => 1,//待完善成本
  2707. 'createrid' => $createrid,
  2708. 'creater' => $creater,
  2709. 'create_source' => 1,
  2710. 'is_del' => 0,
  2711. 'field_change' => '',
  2712. 'addtime' => date('Y-m-d H:i:s'),
  2713. 'updatetime' => date('Y-m-d H:i:s'),
  2714. 'is_exclusive' => '',
  2715. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2716. 'config' => $good_zixun_list[$value]['config'],
  2717. 'other_config' => $good_zixun_list[$value]['other_config'],
  2718. ];
  2719. }
  2720. //good_basic表
  2721. if (!isset($all_good_basic[$value])) {
  2722. $good_basic_insert_data[] = [
  2723. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2724. 'good_code' => $good_zixun_list[$value]['good_code'],
  2725. 'good_name' => $good_zixun_list[$value]['good_name'],
  2726. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2727. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2728. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2729. 'companyName' => $good_zixun_list[$value]['companyName'],
  2730. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2731. 'good_type' => $good_zixun_list[$value]['good_type'],
  2732. 'moq' => $good_zixun_list[$value]['moq'],
  2733. 'customized' => $good_zixun_list[$value]['customized'],
  2734. 'tax' => $good_zixun_list[$value]['tax'],
  2735. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2736. 'supplierName' => $good_zixun_list[$value]['supplierName'],
  2737. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2738. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2739. 'after_sales' => '',
  2740. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2741. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2742. 'weight' => $good_zixun_list[$value]['weight'],
  2743. 'packing_way' => '',
  2744. 'packing_size' => '',
  2745. 'packing_spec' => '',
  2746. 'packing_list' => '',
  2747. 'packing_weight' => '',
  2748. 'good_bar' => '',
  2749. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2750. 'delivery_place' => '',
  2751. 'origin_place' => '',
  2752. 'delivery_day' => '',
  2753. 'lead_time' => '',
  2754. 'sample_day' => '',
  2755. 'sample_fee' => '',
  2756. 'good_img' => '',//$good_zixun_list[$value]['good_img'],
  2757. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2758. 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情
  2759. 'cert_fee' => '',
  2760. 'packing_fee' => '',
  2761. 'cost_fee' => '',
  2762. 'mark_fee' => '',
  2763. 'demo_fee' => '',
  2764. 'open_fee' => '',
  2765. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2766. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2767. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2768. 'cgd_gold_price' => '',
  2769. 'market_price' => '',
  2770. 'nake_price' => '',
  2771. 'is_step' => '',
  2772. 'is_online' => '',
  2773. 'status' => 8,//咨询商品待编辑
  2774. 'createrid' => $createrid,
  2775. 'creater' => $creater,
  2776. 'create_source' => 1,
  2777. 'field_change' => '',
  2778. 'is_del' => 0,
  2779. 'addtime' => date('Y-m-d H:i:s'),
  2780. 'updatetime' => date('Y-m-d H:i:s'),
  2781. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2782. 'config' => $good_zixun_list[$value]['config'],
  2783. 'other_config' => $good_zixun_list[$value]['other_config'],
  2784. ];
  2785. }
  2786. //good_spec
  2787. if (!empty($good_zixun_list[$value]['specinfo'])) {
  2788. $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true);
  2789. foreach ($spec_list as $spec) {
  2790. $specid = $spec['specid']??($spec['spec_id']??"");
  2791. $temp = Db::name('good_spec')
  2792. ->field('id')
  2793. ->where(['spuCode' => $value, 'spec_id' => $specid, 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2794. ->find();
  2795. if (!empty($temp)) {
  2796. $good_spec_insert_data[] = [
  2797. 'spuCode' => $value,
  2798. 'spec_id' => $specid,
  2799. 'spec_value_id' => $spec['spec_value_id'],
  2800. 'is_del' => 0,
  2801. 'addtime' => date('Y-m-d H:i:s'),
  2802. 'updatetime' => date('Y-m-d H:i:s'),
  2803. ];
  2804. }
  2805. }
  2806. }
  2807. $i++;
  2808. }
  2809. if (!empty($isonline)) {
  2810. return app_show(1009, "存在已上线产品", $isonline);
  2811. }
  2812. Db::startTrans();
  2813. try {
  2814. $create = Db::name("good_platform")->insertAll($data);
  2815. Db::name("good_zixun")
  2816. ->where(["is_del" => 0, 'status' => 1])
  2817. ->whereIn('spuCode', $param['codes'])
  2818. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s'),'is_basic'=>1]);
  2819. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2820. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2821. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2822. if ($create) {
  2823. foreach ($good_basic_insert_data as $value) {
  2824. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2825. "order_code" =>$value['spuCode'],//
  2826. "status" => 8,//待产品审核
  2827. "action_remark" => '',//备注
  2828. "action_type" => "create"//新建create,编辑edit,更改状态status
  2829. ], "SPCB", $value['status'], $value);
  2830. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2831. "order_type" => 'SPCB',
  2832. "order_code" =>$value['spuCode'],//
  2833. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2834. "order_status" => 8,//待产品审核
  2835. "before_status" => 0,//待产品审核
  2836. 'holder_id'=>$value['createrid'],
  2837. ]);
  2838. }
  2839. foreach ($data as $value) {
  2840. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2841. "order_code" =>$value['skuCode'],//
  2842. "status" => 0,//待产品审核
  2843. "action_remark" => '',//备注
  2844. "action_type" => "create"//新建create,编辑edit,更改状态status
  2845. ], "SPSX", $value['exam_status'], $value);
  2846. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2847. "order_type" => 'SPSX',
  2848. "order_code" =>$value['skuCode'],//
  2849. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2850. "order_status" =>$value['exam_status'],//待产品审核
  2851. "before_status" => 0,
  2852. 'holder_id' => $value['createrid'],
  2853. ]);
  2854. }
  2855. Db::commit();
  2856. return app_show(0, "提交成功");
  2857. } else {
  2858. Db::rollback();
  2859. return error_show(1004, "提交失败");
  2860. }
  2861. } catch (Exception $exception) {
  2862. Db::rollback();
  2863. return error_show(1005, $exception->getMessage());
  2864. }
  2865. }
  2866. //商品上线审核流程时,驳回重新审核
  2867. public function rejectGoodToAgainExamine()
  2868. {
  2869. $param = $this->request->only(['token', 'skuCode', 'exam_remark' => ''], 'post', 'trim');
  2870. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  2871. if (!$val->check($param)) return error_show(1005, $val->getError());
  2872. $user = GetUserInfo($param['token']);
  2873. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2874. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2875. Db::startTrans();
  2876. try {
  2877. $rs = Db::name("good_platform")
  2878. ->field('id,spuCode,skuCode,exam_status,createrid')
  2879. ->where(['skuCode' => $param['skuCode'], 'is_del' => 0])
  2880. ->where('exam_status', '<>', 3)//exam_status==6上线成功
  2881. ->find();
  2882. if (empty($rs)) throw new \Exception('该记录不存在');
  2883. $old_exam_staus = $rs['exam_status'];
  2884. $good_nake = Db::name("good_nake")
  2885. ->field('id')
  2886. ->where(["spuCode" => $rs['spuCode'], "is_del" => 0])
  2887. ->find();
  2888. $exam_status = empty($good_nake) ? 1 : 2;
  2889. if ($exam_status == $rs['exam_status']) $exam_status =4;//第一级审核失败时,状态改为'审核失败'
  2890. Db::name("good_platform")
  2891. ->where('id', $rs['id'])
  2892. ->save([
  2893. 'exam_status' => $exam_status,
  2894. 'updatetime' => date('Y-m-d H:i:s'),
  2895. ]);
  2896. Db::name("good_exam")->insert([
  2897. 'code' => $rs['skuCode'],
  2898. 'exam_status' => $old_exam_staus,
  2899. 'type' => 2,
  2900. 'exam_id' => $createrid,
  2901. 'exam_name' => $creater,
  2902. 'exam_remark' => $param['exam_remark'],
  2903. 'addtime' => date('Y-m-d H:i:s')
  2904. ]);
  2905. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2906. "order_code" => $param['skuCode'],//编号
  2907. "status" => $rs['exam_status'],
  2908. "action_remark" => '',//备注
  2909. "action_type" => "status"//新建create,编辑edit,更改状态status
  2910. ], "SPSX", $exam_status, $param);
  2911. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2912. "order_type" => 'SPSX',
  2913. "order_code" => $param['skuCode'],//咨询单详情编号
  2914. "order_id" => $rs['id'],
  2915. "order_status" => $exam_status,
  2916. "before_status" => $rs['exam_status'],
  2917. 'holder_id' => $rs['createrid'],
  2918. ]);
  2919. Db::commit();
  2920. return app_show(0, "驳回重新审核成功");
  2921. } catch (\Exception $e) {
  2922. Db::rollback();
  2923. return error_show(1004, '驳回重新审核失败,' . $e->getMessage());
  2924. }
  2925. }
  2926. //同一个spuCode下所有的商品都下线
  2927. public function offlineGoodBySpuCode()
  2928. {
  2929. $param = $this->request->only(['token', 'spuCode', 'offline_reason', 'offline_remark' => ''], 'post', 'trim');
  2930. $val = Validate::rule(['token' => 'require', 'spuCode' => 'require', 'offline_reason|下线原因' => 'require']);
  2931. if (!$val->check($param)) return error_show(1005, $val->getError());
  2932. $user = GetUserInfo($param['token']);
  2933. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2934. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2935. Db::startTrans();
  2936. try {
  2937. $good_name = Db::name("good_basic")
  2938. ->where(['is_del' => 0, 'spuCode' => $param['spuCode']])
  2939. ->value('good_name', '');
  2940. $skuCodeS = Db::name("good_platform")
  2941. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
  2942. ->whereNotIn('exam_status', [4,5])
  2943. ->column('exam_status,skuCode', 'skuCode');
  2944. if ($skuCodeS) {
  2945. // if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线');
  2946. //商品平台
  2947. Db::name("good_platform")
  2948. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
  2949. ->whereNotIn('exam_status', [4,5])
  2950. ->save([
  2951. 'exam_status' => 5,
  2952. "is_compliance"=>0,
  2953. "compliance_remark"=>'',
  2954. 'updatetime' => date('Y-m-d H:i:s'),
  2955. ]);
  2956. //商品下线记录
  2957. $good_offline_log_id = Db::name("good_offline_log")->insertGetId([
  2958. 'spuCode' => $param['spuCode'],
  2959. 'skuCodes' => implode(',', array_keys($skuCodeS)),
  2960. 'good_name' => $good_name,
  2961. 'offline_reason' => $param['offline_reason'],
  2962. 'offline_remark' => $param['offline_remark'],
  2963. 'createrid' => $createrid,
  2964. 'creater' => $creater,
  2965. 'addtime' => date('Y-m-d H:i:s'),
  2966. ]);
  2967. //根据权限查询应该接收商品下线通知的人员
  2968. $all_uid_name = Db::name('role_action')
  2969. ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致
  2970. ->field('role_id')
  2971. ->buildSql();
  2972. $all_user = Db::name('user_role')
  2973. ->alias('ur')
  2974. ->where('ur.roleid IN ' . $all_uid_name)
  2975. ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0')
  2976. ->column('ur.uid,du.nickName');
  2977. $insert_good_exam_data = $insert_order_msg_data = [];
  2978. foreach ($skuCodeS as $skuCode => $value) {
  2979. $insert_good_exam_data[] = [
  2980. 'code' => $skuCode,
  2981. 'exam_status' =>5,
  2982. 'type' => 2,
  2983. 'exam_id' => $createrid,
  2984. 'exam_name' => $creater,
  2985. 'exam_remark' => '',
  2986. 'addtime' => date('Y-m-d H:i:s')
  2987. ];
  2988. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2989. "order_code" => $skuCode,//编号
  2990. "status" =>$value['exam_status'] ,
  2991. "action_remark" => '',//备注
  2992. "action_type" => "status"//新建create,编辑edit,更改状态status
  2993. ], "GOL",5, $param);
  2994. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2995. "order_type" => 'GOL',
  2996. "order_code" => $skuCode,
  2997. "order_id" => $good_offline_log_id,
  2998. "order_status" =>5,
  2999. "before_status" => $value['exam_status']
  3000. ]);
  3001. foreach ($all_user as $itemitem) {
  3002. $insert_order_msg_data[] = [
  3003. 'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
  3004. 'orderCode' => $skuCode,
  3005. 'order_type' => 'GOL',
  3006. 'order_status' =>5,
  3007. 'order_id' => $good_offline_log_id,
  3008. 'uid' => $itemitem['uid'],
  3009. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  3010. 'apply_id' => $createrid,
  3011. 'apply_name' => $creater,
  3012. 'is_read' => 0,
  3013. 'addtime' => date('Y-m-d H:i:s'),
  3014. 'updatetime' => date('Y-m-d H:i:s'),
  3015. ];
  3016. }
  3017. }
  3018. //变动记录
  3019. Db::name("good_exam")->insertAll($insert_good_exam_data);
  3020. //消息表
  3021. Db::name('order_msg')->insertAll($insert_order_msg_data);
  3022. }
  3023. //处理有赞平台
  3024. $rs = Db::name('platform_youzan')
  3025. ->field('id,spuCode,skuCode,exam_status,platform_id')
  3026. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  3027. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  3028. ->select()
  3029. ->toArray();
  3030. if ($rs) {
  3031. $insert_good_offline_log_youzan_data = [];
  3032. foreach ($rs as $value) {
  3033. $curl_data = [
  3034. 'item_no' => $value['skuCode'],//商品自定义编码 skuCode
  3035. 'uid' => $createrid,
  3036. 'nickname' => $creater,
  3037. ];
  3038. //已上线的要调用有赞接口下线
  3039. //调有赞项目的接口,从有赞平台下线该商品
  3040. if($value['exam_status'] == PlatformYouzan::$exam_status_6){
  3041. $host = config('app.yz_domain');
  3042. $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
  3043. $response = json_decode($response, true);
  3044. if ($response['code'] != 0) throw new Exception($response['message']);
  3045. }
  3046. $insert_good_offline_log_youzan_data[] = [
  3047. 'spuCode' => $value['spuCode'],
  3048. 'skuCodes' => $value['skuCode'],
  3049. 'good_name' => $good_name,
  3050. 'offline_reason' => $param['offline_reason'],
  3051. 'offline_remark' => $param['offline_remark'],
  3052. 'createrid' => $createrid,
  3053. 'creater' => $creater,
  3054. 'addtime' => date('Y-m-d H:i:s')
  3055. ];
  3056. }
  3057. Db::name('platform_youzan')
  3058. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  3059. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  3060. ->update([
  3061. 'exam_status' => PlatformYouzan::$exam_status_8,
  3062. 'offline_reason_id' => $param['offline_reason'],
  3063. 'offline_remark' => $param['offline_remark'],
  3064. 'updaterid' => $createrid,
  3065. 'updater' => $creater,
  3066. 'updatetime' => date('Y-m-d H:i:s')
  3067. ]);
  3068. //下线记录表增加记录
  3069. if ($insert_good_offline_log_youzan_data) Db::name('good_offline_log_youzan')->insertAll($insert_good_offline_log_youzan_data);
  3070. }
  3071. Db::commit();
  3072. return app_show(0, "下线成功");
  3073. } catch (\Exception $e) {
  3074. Db::rollback();
  3075. return error_show(1004, '操作失败,' . $e->getMessage());
  3076. }
  3077. }
  3078. //判断是否允许修改成本信息和基础信息
  3079. public function checkIsUpdate()
  3080. {
  3081. $spuCode = $this->request->post('spuCode', '', 'trim');
  3082. if ($spuCode == '') return error_show(1004, '成本商品编号不能为空');
  3083. $is_allow_update = 1;
  3084. //检查是否有上线记录
  3085. $rs = Db::name('good_platform')
  3086. ->field('id')
  3087. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  3088. ->whereNotIn('exam_status', [0,1,5])//0待提交,8已下线
  3089. ->find();
  3090. if (!empty($rs)) $is_allow_update = 0;
  3091. else {
  3092. $rs = PlatformYouzan::field('id')
  3093. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  3094. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])//8已下线,2审核驳回
  3095. ->findOrEmpty()
  3096. ->isEmpty();
  3097. if (!$rs) $is_allow_update = 0;
  3098. }
  3099. return app_show(0, '请求成功', ['is_allow_update' => $is_allow_update]);
  3100. }
  3101. private function isUpdate($spuCode){
  3102. $is_allow_update = 1;
  3103. //检查是否有上线记录
  3104. $rs = Db::name('good_platform')
  3105. ->field('id')
  3106. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  3107. ->whereNotIn('exam_status', [0,1,5])
  3108. ->find();
  3109. if (!empty($rs)) $is_allow_update = 0;
  3110. else {
  3111. $rs = PlatformYouzan::field('id')
  3112. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  3113. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])
  3114. ->findOrEmpty()
  3115. ->isEmpty();
  3116. if (!$rs) $is_allow_update = 0;
  3117. }
  3118. return $is_allow_update;
  3119. }
  3120. //获取某个商品编号下的所有审核备注列表
  3121. public function getGoodExamList()
  3122. {
  3123. $param = $this->request->filter('trim')->only(['token', 'skuCode', 'page' => 1, 'size' => 15], 'post');
  3124. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  3125. if (!$val->check($param)) return error_show(1005, $val->getError());
  3126. $count = Db::name('good_exam')
  3127. ->where('code', $param['skuCode'])
  3128. ->count('id');
  3129. $list = Db::name('good_exam')
  3130. ->where('code', $param['skuCode'])
  3131. ->order('id')
  3132. ->page($param['page'], $param['size'])
  3133. ->select()
  3134. ->toArray();
  3135. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  3136. }
  3137. //获取某个商品编号下的所有审核备注列表
  3138. public function changeLog()
  3139. {
  3140. $param = $this->request->filter('trim')->only(["code"=>"","type"=>""], 'post');
  3141. $val = Validate::rule(['code' => 'require|max:255', 'type' => 'require|number|in:1,2,3,4,5,6,7,8']);
  3142. if (!$val->check($param)) return error_show(1005, $val->getError());
  3143. $count = Db::name('change_log')
  3144. ->where([['code',"=", $param['code']],["type","=",$param['type']]])
  3145. ->json(["after_info","before_info"])
  3146. ->order("id desc")
  3147. ->findOrEmpty();
  3148. return app_show(0, '请求成功', $count);
  3149. }
  3150. //财务审核是否合规接口 只有上线成功才可以操作
  3151. public function AddCompliance(){
  3152. $param = $this->request->filter('trim')->only(["skuCode"=>"","is_compliance"=>"","compliance_remark"=>""],
  3153. 'post',"trim");
  3154. $val = Validate::rule([
  3155. 'compliance_remark|备注' => 'max:255',
  3156. 'skuCode|上线商品编号' => 'require|max:255',
  3157. 'is_compliance|是否合规' => 'require|number|in:0,1,2']);
  3158. if ($val->check($param)==false) return error_show(1005, $val->getError());
  3159. $goodinfo =Db::name("good_platform")
  3160. ->where(["skuCode"=>$param["skuCode"],"is_del"=>0])
  3161. ->findOrEmpty();
  3162. if(empty($goodinfo)) return error_show(1004,"未找到上线商品数据");
  3163. if($goodinfo['exam_status']!=3)return error_show(1004,"商品完成未上线不可操作");
  3164. $upinfo = [
  3165. "is_compliance"=>$param['is_compliance'],
  3166. "compliance_remark"=>$param['compliance_remark'],
  3167. "updatetime"=>date("Y-m-d H:i:s")
  3168. ];
  3169. $up = Db::name("good_platform")
  3170. ->where(["skuCode"=>$param["skuCode"],"is_del"=>0])->update($upinfo);
  3171. if($up==false)return error_show(1004,"数据更新失败");
  3172. else return app_show(0,"数据更新成功");
  3173. }
  3174. /**
  3175. *咨询商品入成本库
  3176. */
  3177. public function basicZixunGoods(){
  3178. $param = $this->request->only(['codes'=>[]], 'post', 'trim');
  3179. $val = Validate::rule([
  3180. 'codes|所选上线商品编号' => 'require|array',
  3181. ]);
  3182. if (!$val->check($param)) return error_show(1004, $val->getError());
  3183. $good_zixun_list = Db::name('good_zixun')
  3184. ->where(['is_del' => 0])
  3185. ->whereIn('spuCode', $param['codes'])
  3186. ->select();
  3187. if (empty($good_zixun_list)) return error_show(1004, '未找到相关咨询商品数据');
  3188. $temp=[];
  3189. $good_spec_insert_data=[];
  3190. $GoodBasic = new GoodBasic();
  3191. foreach ($good_zixun_list as $item){
  3192. $isT =$GoodBasic->where(["spuCode"=>$item['spuCode'],"is_del"=>0])->findOrEmpty();
  3193. if($isT->isEmpty()==false)return error_show(1004, "{$item['good_name']}商品已存在成本库中!");
  3194. $temp[] = [
  3195. 'spuCode' => $item['spuCode'],
  3196. 'good_code' => $item['good_code'],
  3197. 'good_name' => $item['good_name'],
  3198. 'cat_id' => $item['cat_id'],
  3199. 'brand_id' => $item['brand_id'],
  3200. 'companyNo' => $item['companyNo'],
  3201. 'companyName' => $item['companyName'],
  3202. 'good_unit' => $item['good_unit'],
  3203. 'good_type' => $item['good_type'],
  3204. 'moq' => $item['moq'],
  3205. 'customized' => $item['customized'],
  3206. 'tax' => $item['tax'],
  3207. 'supplierNo' => $item['supplierNo'],
  3208. 'supplierName' => $item['supplierName'],
  3209. 'is_auth' => $item['is_auth'],
  3210. 'auth_img' => $item['auth_img'],
  3211. 'after_sales' => '',
  3212. 'craft_desc' => $item['craft_desc'],
  3213. 'good_remark' => $item['good_remark'],
  3214. 'weight' => $item['weight'],
  3215. 'packing_way' => '',
  3216. 'packing_size' => '',
  3217. 'packing_spec' => '',
  3218. 'packing_list' => '',
  3219. 'packing_weight' => '',
  3220. 'good_bar' => '',
  3221. 'supply_area' => $item['supply_area'],
  3222. 'delivery_place' => '',
  3223. 'origin_place' => '',
  3224. 'delivery_day' => '',
  3225. 'lead_time' => '',
  3226. 'sample_day' => '',
  3227. 'sample_fee' => '',
  3228. 'good_img' => '',//$item['good_img'],
  3229. 'good_thumb_img' => $item['good_thumb_img'],
  3230. 'good_info_img' => $item['good_img'],//商品主图对应到商品详情
  3231. 'cert_fee' => '',
  3232. 'packing_fee' => '',
  3233. 'cost_fee' => '',
  3234. 'mark_fee' => '',
  3235. 'demo_fee' => '',
  3236. 'open_fee' => '',
  3237. 'noble_metal' => $item['noble_metal'],
  3238. 'noble_weight' => $item['good_weight'],
  3239. 'is_gold_price' => $item['is_gold_price'],
  3240. 'cgd_gold_price' => '',
  3241. 'market_price' => '',
  3242. 'nake_price' => '',
  3243. 'is_step' => '',
  3244. 'is_online' => '',
  3245. 'status' => 8,//咨询商品待编辑
  3246. 'createrid' => $this->uid,
  3247. 'creater' => $this->uname,
  3248. 'create_source' => 1,
  3249. 'field_change' => '',
  3250. 'is_del' => 0,
  3251. 'addtime' => date('Y-m-d H:i:s'),
  3252. 'updatetime' => date('Y-m-d H:i:s'),
  3253. 'is_diff' => $item['is_diff'],
  3254. 'config' => $item['config'],
  3255. 'other_config' => $item['other_config'],
  3256. ];
  3257. if (!empty($item['specinfo'])) {
  3258. $spec_list = json_decode($item['specinfo'], true);
  3259. foreach ($spec_list as $spec) {
  3260. $specid = $spec['specid']??($spec['spec_id']??'');
  3261. $specinfo = Db::name('good_spec')
  3262. ->field('id')
  3263. ->where(['spuCode' => $item['spuCode'], 'spec_id' => $specid, 'spec_value_id' => $spec['spec_value_id'],
  3264. 'is_del' => 0])
  3265. ->find();
  3266. if (!empty($specinfo)) {
  3267. $good_spec_insert_data[] = [
  3268. 'spuCode' => $item['spuCode'],
  3269. 'spec_id' => $specid,
  3270. 'spec_value_id' => $spec['spec_value_id'],
  3271. 'is_del' => 0,
  3272. 'addtime' => date('Y-m-d H:i:s'),
  3273. 'updatetime' => date('Y-m-d H:i:s'),
  3274. ];
  3275. }
  3276. }
  3277. }
  3278. }
  3279. $GoodBasic->startTrans();
  3280. try {
  3281. $create = $GoodBasic->saveAll($temp);
  3282. Db::name('good_zixun')
  3283. ->where(['is_del' => 0, 'status' => 1])
  3284. ->whereIn('spuCode', $param['codes'])
  3285. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s'),"is_basic"=>1]);
  3286. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  3287. if ($create) {
  3288. foreach ($temp as $value) {
  3289. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], [
  3290. 'order_code' =>$value['spuCode'],//
  3291. 'status' => 8,//待产品审核
  3292. 'action_remark' => '',//备注
  3293. 'action_type' => 'create'//新建create,编辑edit,更改状态status
  3294. ], 'SPCB', $value['status'], $value);
  3295. ProcessOrder::AddProcess(['id' =>$this->uid, 'nickname' =>$this->uname], [
  3296. 'order_type' => 'SPCB',
  3297. 'order_code' =>$value['spuCode'],//
  3298. 'order_id' => isset($value['id']) ? $value['id'] : 0,
  3299. 'order_status' => 8,//待产品审核
  3300. 'before_status' => 0,//待产品审核
  3301. 'holder_id'=>$value['createrid'],
  3302. ]);
  3303. }
  3304. $GoodBasic->commit();
  3305. return app_show(0, '提交成功');
  3306. } else {
  3307. $GoodBasic->rollback();
  3308. return error_show(1004, '提交失败');
  3309. }
  3310. } catch (Exception $exception) {
  3311. $GoodBasic->rollback();
  3312. return error_show(1005, $exception->getMessage());
  3313. }
  3314. }
  3315. }