Goodup.php 169 KB

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