Goodup.php 170 KB

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