Goodup.php 161 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241
  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('gb.id');
  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'] = $value['companyName'];//$supplierInfo['data'][$value['companyNo']]??'';//isset($company['company'])?$company['company']:"";
  201. // $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  202. $value['supplier_name']=$value['supplierName'];//$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, "获取成功", ['count' => $count, 'list' => $data]);
  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,['id' => $this->uid, 'nickname' => $this->uname]);
  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,['id' => $this->uid, 'nickname' => $this->uname]);
  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. //
  1097. // ProcessOrder::AddProcess($this->post['token'], [
  1098. // "order_type" => 'SPCB',
  1099. // "order_code" => $supcode,//咨询单详情编号
  1100. // "order_id" => $datas['id'],
  1101. // "order_status" =>$data['status'],
  1102. // "before_status"=>$datas['status'],
  1103. // 'holder_id'=>$datas['createrid'],
  1104. // ]);
  1105. // $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1106. // if($online){
  1107. // $onup = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save
  1108. // (["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  1109. // if($onup==false){
  1110. // Db::rollback();
  1111. // return app_show(1004,"商品规成本修改失败");
  1112. // }
  1113. // //修改状态,添加待办
  1114. // ActionLog::logAdd($this->post['token'], [
  1115. // "order_code" =>$online['skuCode'],//咨询单详情编号
  1116. // "status" => $online['exam_status'],//这里的status是之前的值
  1117. // "action_remark" => '',//备注
  1118. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  1119. // ], "SPSX",2,["exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  1120. //
  1121. // ProcessOrder::AddProcess($this->post['token'], [
  1122. // "order_type" => 'SPSX',
  1123. // "order_code" => $online['skuCode'],//咨询单详情编号
  1124. // "order_id" => $online['id'],
  1125. // "order_status" =>2,"before_status"=>$online['exam_status']
  1126. // ]);
  1127. // }
  1128. if($good_ladder!=="" && !empty($good_ladder)){
  1129. $user =GetUserInfo($this->post['token']);
  1130. foreach ($good_ladder as $value){
  1131. $lemp=[];
  1132. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1133. $lemp['spuCode']=$supcode;
  1134. $lemp['min_num'] = $value['min_num'];
  1135. $lemp['nake_fee'] = $value['nake_fee'];
  1136. $lemp['cost_fee'] = $value['cost_fee'];
  1137. $lemp['delivery_fee'] = $value['delivery_fee'];
  1138. $lemp['cert_fee'] = $value['cert_fee'];
  1139. $lemp['mark_fee'] = $value['mark_fee'];
  1140. $lemp['package_fee'] = $value['package_fee'];
  1141. $lemp['other_fee'] = $value['other_fee'];
  1142. $top_cat_id = made($datas['cat_id']);//获取所有分类
  1143. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  1144. if($is_gold_price==1 && $top_cat_id==6){
  1145. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  1146. //$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'];
  1147. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  1148. //成本总计启用实时金价时,采用供应商实时金价
  1149. $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'];
  1150. }else{
  1151. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1152. }
  1153. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1154. $lemp['creater_id'] = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1155. $lemp['creater'] =isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1156. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1157. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1158. $count = Db::name("good_nake")->save($lemp);
  1159. if($count==false){
  1160. Db::rollback();
  1161. return app_show(1004,"商品规成本修改失败");
  1162. }
  1163. }
  1164. }
  1165. Db::commit();
  1166. return app_show(0,"更新成功");
  1167. }else{
  1168. Db::rollback();
  1169. return error_show(1005,"更新失败");
  1170. }
  1171. }catch (\Exception $e){
  1172. Db::rollback();
  1173. return error_show(1005,$e->getMessage());
  1174. }
  1175. }
  1176. public function exam(){
  1177. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1178. if($supcode==""){
  1179. return error_show(1004,"参数spuCode不能为空");
  1180. }
  1181. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1182. if($data==false){
  1183. return error_show(1004,"未找到商品数据");
  1184. }
  1185. $isupdate = $this->isUpdate($supcode);
  1186. if($isupdate==0){
  1187. return error_show(1004,"存在上线进行中的商品");
  1188. }
  1189. if($data['status']==1){
  1190. return error_show(1004,"商品已审核通过");
  1191. }
  1192. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  1193. // if($status===""){
  1194. // return error_show(1004,"参数status不能为空");
  1195. // }
  1196. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  1197. // if($remark===""){
  1198. // return error_show(1004,"参数remark不能为空");
  1199. // }
  1200. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1201. if($token==''){
  1202. return error_show(105,"参数token不能为空");
  1203. }
  1204. $createrid=$this->uid;
  1205. $creater= $this->uname;
  1206. Db::startTrans();
  1207. try {
  1208. if($data['status']==3 && $status==1){
  1209. //区分是否是对接平台
  1210. $platform_info=Db::name('platform')
  1211. ->field('id,platform_type')
  1212. ->where(['is_del'=>0,'platform_type'=>1])
  1213. ->column("id");
  1214. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->whereNotIn("platform_code",$platform_info)->find();
  1215. if($online) {
  1216. $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")]);
  1217. if ($onl == false) {
  1218. Db::rollback();
  1219. return error_show(1004, "审核失败");
  1220. }
  1221. ActionLog::logAdd($this->post['token'], [
  1222. "order_code" =>$online['skuCode'],//咨询单详情编号
  1223. "status" => $online['exam_status'],//这里的status是之前的值
  1224. "action_remark" => '',//备注
  1225. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1226. ], "SPSX", 2, ["exam_status" => 2, "updatetime" => date("Y-m-d H:i:s")]);
  1227. ProcessOrder::AddProcess($this->post['token'], [
  1228. "order_type" => 'SPSX',
  1229. "order_code" =>$online['skuCode'],//咨询单详情编号
  1230. "order_id" => $online['id'],
  1231. "order_status" => 2,
  1232. "before_status"=>$online['exam_status'],
  1233. 'holder_id' => $online['createrid'],
  1234. ]);
  1235. }
  1236. }
  1237. // if ($status == 1) {
  1238. // //把同一个spuCode,且状态为1待完善成本,的记录更改状态为2待产品审核
  1239. // Db::name('good')
  1240. // ->where(['is_del' => 0, 'status' => 1])
  1241. // ->whereIn('spuCode', $supcode)
  1242. // ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  1243. // }
  1244. $old_status = $data['status'];
  1245. $data['status']=$status;
  1246. $data['updatetime']=date("Y-m-d H:i:s");
  1247. $up= Db::name("good_basic")->save($data);
  1248. if($up){
  1249. //修改状态,添加待办
  1250. ActionLog::logAdd($this->post['token'], [
  1251. "order_code" =>$supcode,//咨询单详情编号
  1252. "status" => $status,//这里的status是之前的值
  1253. "action_remark" => '',//备注
  1254. "action_type" => "edit"//新建create,编辑edit,更改状态status
  1255. ], "SPCB",$data['status'] ,$data);
  1256. ProcessOrder::AddProcess($this->post['token'], [
  1257. "order_type" => 'SPCB',
  1258. "order_code" => $supcode,//咨询单详情编号
  1259. "order_id" => $data['id'],
  1260. "order_status" =>$data['status'],
  1261. "before_status"=>$old_status,
  1262. 'holder_id'=>$data['createrid'],
  1263. ]);
  1264. $data=[
  1265. "code"=>$supcode,
  1266. "exam_status"=>$status,
  1267. "type"=>1,
  1268. "exam_id"=>$createrid,
  1269. "exam_name"=>$creater,
  1270. "exam_remark"=>$remark,
  1271. "addtime"=>date("Y-m-d H:i:s")
  1272. ];
  1273. $inr=Db::name("good_exam")->insert($data);
  1274. if($inr){
  1275. Db::commit();
  1276. return app_show(0,"审核成功");
  1277. }else{
  1278. Db::rollback();
  1279. return error_show(1004,"审核失败");
  1280. }
  1281. }else{
  1282. Db::rollback();
  1283. return error_show(1004,"审核失败");
  1284. }
  1285. }catch (\Exception $e){
  1286. Db::rollback();
  1287. return error_show(1004,$e->getMessage());
  1288. }
  1289. }
  1290. public function info(){
  1291. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1292. if($supcode==""){
  1293. return error_show(1004,"参数spuCode不能为空");
  1294. }
  1295. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1296. if($data==false){
  1297. return error_show(1004,"未找到商品数据");
  1298. }
  1299. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  1300. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1301. $data['cat_info'] = made($data['cat_id'],[]);
  1302. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1303. $userCommon = \app\admin\common\User::getIns();
  1304. $sinfo = $userCommon->handle('sInfo',['code'=>$data['supplierNo']]);
  1305. // $names = $userCommon->handle('getCodeAndName', ['code' => [$data['supplierNo'], $data['companyNo']]]);
  1306. // $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  1307. // $data['supplierName'] = $names['data'][$data['supplierNo']] ?? '';//isset($supplier['name'])
  1308. //?$supplier['name']:"";
  1309. // $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  1310. // $data['company'] = $names['data'][$data['companyNo']] ?? ''; //isset($company['company'])?$company['company']:"";
  1311. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  1312. if($data['brand_id']!=0){
  1313. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  1314. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1315. }else{
  1316. $data["brand_name"]="";
  1317. $data["brand_id"]="";
  1318. }
  1319. $excluse = makeExcluse($data['is_exclusive']);
  1320. $data['exclusive']=$excluse;
  1321. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  1322. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:'';
  1323. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  1324. $gold=[];
  1325. if ($data['is_gold_price'] == 1) {
  1326. $gold = Db::name("gold_price1")->where(["type" => $data['noble_metal'], "status" => 1, "is_del" => 0])->order("addtime desc")->find();
  1327. }
  1328. $data['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1329. $speclist=[];
  1330. if(!empty($spec)){
  1331. foreach ($spec as $value){
  1332. $temp=[];
  1333. $temp['id']=$value['id'];
  1334. $temp['spuCode']=$value['spuCode'];
  1335. $temp['spec_id']=$value['spec_id'];
  1336. $temp['spec_value_id']=$value['spec_value_id'];
  1337. $temp['is_del']=$value['is_del'];
  1338. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  1339. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1340. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  1341. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1342. $speclist[]=$temp;
  1343. }
  1344. }
  1345. $data["speclist"]=empty($speclist)?[]:$speclist;
  1346. // $nake=[];
  1347. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  1348. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  1349. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1350. $nakearry=[];
  1351. if(!empty($nakelist)){
  1352. foreach ($nakelist as $value) {
  1353. $nakearry[] = $value;
  1354. }
  1355. }
  1356. $data["nakelist"]=$nakearry;
  1357. $data['cgderid'] = $sinfo['data']['personid'] ?? '';
  1358. $data['cgder'] = $sinfo['data']['person'] ?? '';
  1359. return app_show(0,"获取成功",$data);
  1360. }
  1361. //删除商品成本
  1362. public function delall()
  1363. {
  1364. $supcode = $this->request->post('codes', '', 'trim');
  1365. if ($supcode == "") {
  1366. return error_show(1004, "参数codes不能为空");
  1367. }
  1368. Db::startTrans();
  1369. try {
  1370. $good_basic = Db::name("good_basic")
  1371. ->field('id,spuCode,status')
  1372. ->where(["spuCode" => $supcode, "is_del" => 0])
  1373. ->select()->toArray();
  1374. if (empty($good_basic)) throw new Exception('该记录不存在或已删除');
  1375. $good = Db::name('good')
  1376. ->alias('g')
  1377. ->field('gp.id,gp.exam_status,gp.skuCode')
  1378. ->leftJoin('good_platform gp', 'gp.spuCode=g.spuCode AND gp.is_del=0')
  1379. ->where(['g.spuCode' => $supcode, 'g.is_del' => 0])
  1380. ->whereNotIn('gp.exam_status', [1, 8])
  1381. ->select()->toArray();
  1382. if (!empty($good)) throw new Exception('该商品需要下线之后才能删除');
  1383. Db::name("good_basic")
  1384. ->where(["spuCode" => $supcode, 'is_del' => 0])
  1385. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1386. Db::name("good")
  1387. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1388. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1389. Db::name("good_platform")
  1390. ->where(['spuCode' => $supcode, 'is_del' => 0])
  1391. ->whereIn('exam_status', [1, 8])
  1392. ->update(['is_del' => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1393. Db::name("good_ladder")->where(["skuCode"=>array_column($good,"skuCode"),"is_del"=>0])->update(['is_del'
  1394. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1395. Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->update(['is_del'
  1396. => 1, 'updatetime' => date('Y-m-d H:i:s')]);
  1397. ProcessOrder::workdel(["order_type" => "SPCB", "order_code" => $supcode]);
  1398. ProcessOrder::workdel(["order_type" => "SPSX", "order_code" => array_column($good,"skuCode")]);
  1399. Db::commit();
  1400. app_show(0, "删除成功");
  1401. } catch (Exception $exception) {
  1402. Db::rollback();
  1403. return error_show(1005, "删除失败," . $exception->getMessage());
  1404. }
  1405. }
  1406. //添加上线商品
  1407. public function online(){
  1408. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  1409. if($platform==""){
  1410. return error_show(1004,"参数platform不能为空");
  1411. }
  1412. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  1413. if($spuCode===''){
  1414. return error_show(1004,"参数codes不能为空");
  1415. }
  1416. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  1417. if(empty($datas)){
  1418. return error_show(1004,"未找到商品数据");
  1419. }
  1420. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  1421. if($online_reason===""){
  1422. return error_show(1004,"参数online_reason不能为空");
  1423. }
  1424. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  1425. if($online_remark===""){
  1426. return error_show(1004,"参数online_remark不能为空");
  1427. }
  1428. $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1429. $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1430. //区分是否是对接平台
  1431. $platform_info=Db::name('platform')
  1432. ->field('id,platform_type,is_select_pay_rate')
  1433. ->where(['is_del'=>0,'id'=>$platform])
  1434. ->findOrEmpty();
  1435. if(empty($platform_info)) return error_show(1005,'所选的平台不存在');
  1436. if($platform_info['is_select_pay_rate']==1){
  1437. //所选的商品成本中的业务公司,不能和支付渠道中的业务公司重复
  1438. $companyNo = Db::name('platform_pay_rate')
  1439. ->where(['platform_id'=>$platform,'is_del'=>0])
  1440. ->column('companyNo');
  1441. $tmp = Db::name("good_basic")
  1442. ->field('id,spuCode,good_name,companyNo,good_thumb_img')
  1443. ->where(["spuCode"=>$spuCode,"is_del"=>0])
  1444. ->whereIn('companyNo',$companyNo)
  1445. ->select()
  1446. ->toArray();
  1447. if(!empty($tmp)) return json_show(1009,'以下商品的业务公司和平台支付渠道中的业务公司重复,不允许上线',$tmp);
  1448. }
  1449. if($platform_info['platform_type']==1) return \app\youzan\logic\Goodup::create([
  1450. 'platform_id'=>$platform,
  1451. 'online_reason'=>$online_reason,
  1452. 'online_remark'=>$online_remark,
  1453. 'good_data'=>$datas,
  1454. 'createrid'=>$createrid,
  1455. 'creater'=>$creater,
  1456. ]);
  1457. $data=[];
  1458. $isonline=[];
  1459. $i=0;
  1460. Db::startTrans();
  1461. try{
  1462. foreach ($datas as $value){
  1463. $count = Db::name("good_nake")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->count();
  1464. $ist =Db::name("good_platform")->where(["spuCode"=>$value['spuCode'],"platform_code"=>$platform,"is_del"=>0])->find();
  1465. if($ist){
  1466. $god=Db::name("good_basic")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1467. if($god){
  1468. $tp=[];
  1469. $tp['spuCode']=$value['spuCode'];
  1470. $tp['good_name']=$god['good_name'];
  1471. $tp['good_img']=$god['good_thumb_img'];
  1472. $tp['exam_status']=$ist['exam_status'];
  1473. $spec = Db::name("good_spec")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->select()->toArray();
  1474. $speclist=[];
  1475. if(!empty($spec)){
  1476. foreach ($spec as $val){
  1477. $temp=[];
  1478. $temp['id']=$val['id'];
  1479. $temp['spuCode']=$val['spuCode'];
  1480. $temp['spec_id']=$val['spec_id'];
  1481. $temp['spec_value_id']=$val['spec_value_id'];
  1482. $temp['is_del']=$val['is_del'];
  1483. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  1484. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  1485. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  1486. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  1487. $speclist[]=$temp;
  1488. }
  1489. }
  1490. $tp["speclist"]=empty($speclist)?[]:$speclist;
  1491. $isonline[]=$tp;
  1492. }
  1493. }
  1494. if(!empty($isonline)){
  1495. return app_show(1009,"存在已上线产品",$isonline);
  1496. }
  1497. //改变编码规则,将原来的skuCode后两位换成序列号
  1498. //str_pad字符串填充
  1499. $skuCode = makeNo("SN");
  1500. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  1501. $tmp=[
  1502. "spuCode"=>$value['spuCode'],
  1503. "skuCode"=>$skuCode,
  1504. "platform_code"=>$platform,
  1505. "online_reason"=>$online_reason,
  1506. "online_remark"=>$online_remark,
  1507. "exam_status"=>$count>0 ?2:1,
  1508. "is_online"=>0,
  1509. "status"=>1,
  1510. "is_del"=>0,
  1511. "creater"=>$creater,
  1512. "createrid"=>$createrid,
  1513. "addtime"=>date("Y-m-d H:i:s"),
  1514. "updatetime"=>date("Y-m-d H:i:s")
  1515. ];
  1516. $i++;
  1517. //修改状态,添加待办
  1518. $create =Db::name("good_platform")->insert($tmp,true);
  1519. if($create>0){
  1520. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  1521. if($iso==false){
  1522. unset($value['id']);
  1523. $value['addtime']=date("Y-m-d H:i:s");
  1524. $value['updatetime']=date("Y-m-d H:i:s");
  1525. }else{
  1526. $value['id']=$iso['id'];
  1527. $value['updatetime']=date("Y-m-d H:i:s");
  1528. }
  1529. $up = Db::name("good")->strict(false)->save($value);
  1530. if(!$up){
  1531. Db::rollback();
  1532. return error_show(1004,"提交失败");
  1533. }
  1534. }else{
  1535. Db::rollback();
  1536. return error_show(1004,"提交失败");
  1537. }
  1538. }
  1539. Db::commit();
  1540. return app_show(0,"提交成功");
  1541. }catch (\Exception $e){
  1542. Db::rollback();
  1543. return error_show(1004, $e->getMessage());
  1544. }
  1545. }
  1546. //审核
  1547. public function online_exam(){
  1548. $post =$this->request->only([
  1549. "skuCode"=>"", //商品成本编号
  1550. "exam_status"=>"", //审核状态 1 提交待完善成本 2待审核 3上线完成 4 审核驳回 5 下线完成
  1551. "offline_reason"=>"", //下线原因
  1552. "offline_remark"=>"", //下线备注
  1553. "plat_code"=>"", //平台订单号
  1554. 'exam_remark'=>"", //审核备注
  1555. 'good_ladder'=>[], //售价阶梯
  1556. 'proof_type'=>"", // 售价凭证类型
  1557. 'proof_url'=>"", // 售价凭证
  1558. ],"post","trim");
  1559. $valide = Validate::rule([
  1560. "shuCode|商品编号"=>"require|max:255",
  1561. "exam_status|审核状态"=>"require|number|in:0,1,2,3,4,5",
  1562. "offline_reason|线下原因"=>"requireIf:exam_status,5|max:255",
  1563. "offline_remark|下线备注"=>"requireIf:exam_status,5|max:255",
  1564. "plat_code|平台商品编码"=>"requireIf:exam_status,3|max:255",
  1565. 'exam_remark|审核备注'=>"max:255",
  1566. 'good_ladder|售价阶梯'=>"requireIf:exam_status,3|array",
  1567. 'proof_type|售价凭证类型'=>"requireIf:exam_status,3|number|gt:0",
  1568. 'proof_url|售价凭证'=>"requireIf:exam_status,3|url",
  1569. ]);
  1570. if($valide->check($post)==false) return error_show(1004,$valide->getError());
  1571. $platform = Db::name("good_platform")->where(["skuCode"=>$post['skuCode'],"is_del"=>0])->find();
  1572. if($platform==false){
  1573. return error_show(1004,"未找到数据");
  1574. }
  1575. if($post['exam_status']==3){
  1576. $is_exit = Db::name("good_platform")
  1577. ->where(["plat_code" =>$post['plat_code'], "platform_code" => $platform['platform_code'], "is_del" =>0, 'exam_status' =>3])//exam_status==3已上线
  1578. ->where("id", "<>", $platform['id'])
  1579. ->find();
  1580. if($is_exit==false){
  1581. $platform['plat_code']=$post['plat_code'];
  1582. }else{
  1583. return error_show(1004,"平台商品编码 {$post['plat_code']} 已存在");
  1584. }
  1585. }
  1586. $platform['exam_status']=$post['exam_status'];
  1587. $platform['updatetime']=date("Y-m-d H:i:s");
  1588. $createrid= $this->uid;
  1589. $creater= $this->uname;
  1590. Db::startTrans();
  1591. try {
  1592. $up = Db::name("good_platform")->save($platform);
  1593. if($up){
  1594. $data=[
  1595. "code"=>$platform['skuCode'],
  1596. "exam_status"=>$post['exam_status'],//$exam_status,
  1597. "type"=>2,
  1598. "exam_id"=>$createrid,
  1599. "exam_name"=>$creater,
  1600. "exam_remark"=>$post['exam_remark'],
  1601. "addtime"=>date("Y-m-d H:i:s")
  1602. ];
  1603. $inr=Db::name("good_exam")->insert($data);
  1604. if($inr){
  1605. //如果是商品下线的话,记入商品下线记录表
  1606. if ($post['exam_status'] == 5) {
  1607. $offline_id = Db::name("good_offline_log")->insertGetId([
  1608. 'spuCode' => $platform['spuCode'],
  1609. 'skuCodes' => $platform['skuCode'],
  1610. 'good_name' => Db::name("good_basic")->where('spuCode', $platform['spuCode'])->value('good_name', ''),
  1611. 'offline_reason' => $post['offline_reason'],
  1612. 'offline_remark' => $post['offline_remark'],
  1613. 'createrid' => $createrid,
  1614. 'creater' => $creater,
  1615. 'addtime' => date('Y-m-d H:i:s'),
  1616. ]);
  1617. //根据权限查询应该接收商品下线通知的人员
  1618. $all_uid_name = Db::name('role_action')
  1619. ->whereFindInSet('action_conllect','877')//数据写死的,要注意各个环境数据是否一致
  1620. ->field('role_id')
  1621. ->buildSql();
  1622. $all_user = Db::name('user_role')
  1623. ->alias('ur')
  1624. ->where('ur.roleid IN '.$all_uid_name)
  1625. ->leftJoin('depart_user du','du.uid = ur.uid AND du.is_del=0')
  1626. ->column('ur.uid,du.nickName');
  1627. $insert_order_msg_data=[];
  1628. foreach ($all_user as $itemitem) {
  1629. $insert_order_msg_data[] = [
  1630. 'content' => '商品下线:' . $platform['spuCode'] . '由' . $creater . '操作下线',
  1631. 'orderCode' => $platform['skuCode'],
  1632. 'order_type' => 'GOL',
  1633. 'order_status' => 5,
  1634. 'order_id' => $offline_id,
  1635. 'apply_id' => $createrid,
  1636. 'apply_name' => $creater,
  1637. 'uid' => $itemitem['uid'],
  1638. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  1639. 'is_read' => 0,
  1640. 'addtime' => date('Y-m-d H:i:s'),
  1641. 'updatetime' => date('Y-m-d H:i:s'),
  1642. ];
  1643. }
  1644. //消息表
  1645. Db::name('order_msg')->insertAll($insert_order_msg_data);
  1646. }
  1647. if ($post['exam_status'] == 3) {
  1648. $proof=[
  1649. 'spuCode'=>$platform['spuCode'],
  1650. 'proof_type'=>$post['proof_type'],
  1651. 'proof_url'=>$post['proof_url'],
  1652. 'is_del'=>0,
  1653. "creater"=>$creater,
  1654. "createrid"=>$createrid,
  1655. "addtime"=>date("Y-m-d H:i:s"),
  1656. "updatetime"=>date("Y-m-d H:i:s")
  1657. ];
  1658. $inproof = Db::name("good_proof")->insert($proof);
  1659. if($inproof==false)throw new \Exception("商品凭证新建失败");
  1660. if(empty($post['good_ladder']))throw new \Exception("商品阶梯价不能为空");
  1661. foreach ($post['good_ladder'] as $value){
  1662. $lemp=[];
  1663. $value["id"]?$lemp['id']=$value['id']:"";
  1664. $lemp['skuCode']=$platform['skuCode'];
  1665. $lemp['min_num'] = $value['min_num'];
  1666. $lemp['max_num'] = 0;
  1667. $lemp['sale_price'] = $value['sale_price'];
  1668. $lemp['market_price'] = $value['market_price'];
  1669. $lemp['market_platform'] = $value['market_platform'];
  1670. $lemp['cost_fee'] = $value['cost_fee'];
  1671. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1672. $value["id"]??$lemp['addtime'] = date("Y-m-d H:i:s");
  1673. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1674. $ladderUp = Db::name("good_ladder")->save($lemp);
  1675. if($ladderUp==false) throw new \Exception("商品起订价修改失败");
  1676. }
  1677. }
  1678. Db::commit();
  1679. return app_show(0,"审核成功");
  1680. }else{
  1681. Db::rollback();
  1682. return error_show(1004,"审核失败");
  1683. }
  1684. }else{
  1685. Db::rollback();
  1686. return error_show(1004,"审核失败");
  1687. }
  1688. }catch (\Exception $e){
  1689. Db::rollback();
  1690. return error_show(1004,$e->getMessage());
  1691. }
  1692. }
  1693. //财务定价 废弃
  1694. public function editladder(){
  1695. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1696. if($skuCode===""){
  1697. return error_show(1004,"参数skuCode不能为空");
  1698. }
  1699. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1700. if($platform==false){
  1701. return error_show(1004,"未找到数据");
  1702. }
  1703. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1704. if($good_ladder==""){
  1705. return error_show(1004,"参数good_ladder不能为空");
  1706. }
  1707. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1708. if($proof_type===""){
  1709. return error_show(1004,"参数proof_type不能为空");
  1710. }
  1711. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1712. if($proof_url===""){
  1713. return error_show(1004,"参数proof_url不能为空");
  1714. }
  1715. $exam_remark = isset($this->post['exam_remark'])&& $this->post['exam_remark']!='' ? trim($this->post['exam_remark']):"";
  1716. $createrid= $this->uid;//isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1717. $creater= $this->uname;//isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1718. $bifore=$platform['exam_status'];
  1719. $platform['exam_status']=4;
  1720. $platform['updatetime']=date("Y-m-d H:i:s");
  1721. Db::startTrans();
  1722. try {
  1723. foreach ($good_ladder as $value){
  1724. $lemp=[];
  1725. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1726. $lemp['skuCode']=$skuCode;
  1727. $lemp['min_num'] = $value['min_num'];
  1728. $lemp['max_num'] = 0;
  1729. $lemp['sale_price'] = $value['sale_price'];
  1730. $lemp['market_price'] = $value['market_price'];
  1731. $lemp['market_platform'] = $value['market_platform'];
  1732. $lemp['cost_fee'] = $value['cost_fee'];
  1733. $lemp['status'] = $value['status'];
  1734. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1735. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1736. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1737. $count = Db::name("good_ladder")->save($lemp);
  1738. if($count==false){
  1739. Db::rollback();
  1740. return app_show(1004,"商品起订价修改失败");
  1741. }
  1742. }
  1743. $up = Db::name("good_platform")->save($platform);
  1744. if($up){
  1745. // ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname], [
  1746. // "order_code" =>$platform['skuCode'],//咨询单详情编号
  1747. // "status" =>$bifore,//这里的status是之前的值
  1748. // "action_remark" => '',//备注
  1749. // "action_type" => "edit"//新建create,编辑edit,更改状态status
  1750. // ], "SPSX", $platform['exam_status'],$platform);
  1751. //
  1752. // ProcessOrder::AddProcess(['id'=>$this->uid,'nickname'=>$this->uname], [
  1753. // "order_type" => 'SPSX',
  1754. // "order_code" =>$platform['skuCode'],//咨询单详情编号
  1755. // "order_id" => $platform['id'],
  1756. // "order_status" => $platform['exam_status'],
  1757. // "before_status"=>$bifore,
  1758. // 'holder_id' => $platform['createrid'],
  1759. // ]);
  1760. $proof=[
  1761. 'spuCode'=>$platform['spuCode'],
  1762. 'proof_type'=>$proof_type,
  1763. 'proof_url'=>$proof_url,
  1764. 'is_del'=>0,
  1765. "creater"=>$creater,
  1766. "createrid"=>$createrid,
  1767. "addtime"=>date("Y-m-d H:i:s"),
  1768. "updatetime"=>date("Y-m-d H:i:s")
  1769. ];
  1770. $inproof = Db::name("good_proof")->insert($proof);
  1771. if($inproof==false){
  1772. Db::rollback();
  1773. return app_show(1004,"商品凭证新建失败");
  1774. }
  1775. $data=[
  1776. "code"=>$platform['skuCode'],
  1777. "type"=>2,
  1778. "exam_status"=>$bifore,//4,
  1779. "exam_id"=>$createrid,
  1780. "exam_name"=>$creater,
  1781. "exam_remark"=>$exam_remark,
  1782. "addtime"=>date("Y-m-d H:i:s")
  1783. ];
  1784. $inr=Db::name("good_exam")->insert($data);
  1785. if($inr){
  1786. Db::commit();
  1787. return app_show(0,"审核成功");
  1788. }else{
  1789. Db::rollback();
  1790. return error_show(1004,"审核失败");
  1791. }
  1792. }else{
  1793. Db::rollback();
  1794. return error_show(1004,"审核失败");
  1795. }
  1796. }catch (\Exception $e){
  1797. Db::rollback();
  1798. return error_show(1004,$e->getMessage());
  1799. }
  1800. }
  1801. public function prooflist(){
  1802. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1803. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1804. $where =[["is_del","=",0]];
  1805. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1806. if($spuCode!==""){
  1807. $where[]=["spuCode","like","%$spuCode%"];
  1808. }
  1809. $count = Db::name("good_proof")->where($where)->count();
  1810. $total = ceil($count / $size);
  1811. $page = $page >= $total ? $total : $page;
  1812. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1813. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1814. }
  1815. /**
  1816. * 已下线商品重新发起上线流程
  1817. */
  1818. public function againOnline(){
  1819. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1820. if($skuCode===""){
  1821. return error_show(1004,"参数skuCode不能为空");
  1822. }
  1823. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1824. if($platform==false){
  1825. return error_show(1004,"未找到数据");
  1826. }
  1827. if($platform["exam_status"]!=5){
  1828. return error_show(1004,"商品状态有误");
  1829. }
  1830. //判断平台商品编码是否重复
  1831. // $rs = Db::name("good_platform")
  1832. // ->field('id')
  1833. // ->where(["plat_code" => $platform['plat_code'],"platform_code" => $platform['platform_code'], 'exam_status' => 6, "is_del" => 0])//exam_status==6已上线
  1834. // ->where('id', '<>', $platform['id'])
  1835. // ->find();
  1836. // if (!empty($rs)) return error_show(1005, '该商品的平台商品编码已被使用');
  1837. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1838. $bifore=$platform['exam_status'];
  1839. $platform['exam_status'] = empty($nake)?1:2;
  1840. $platform['updatetime'] = date("Y-m-d H:i:s");
  1841. $createrid= $this->uid;
  1842. $creater= $this->uame;
  1843. Db::startTrans();
  1844. try {
  1845. $save =Db::name("good_platform")->save($platform);
  1846. if($save){
  1847. $data=[
  1848. "code"=>$platform['skuCode'],
  1849. "type"=>2,
  1850. "exam_status"=>$platform['exam_status'],//$platform['exam_status'] ,
  1851. "exam_id"=>$createrid,
  1852. "exam_name"=>$creater,
  1853. "exam_remark"=>'',
  1854. "addtime"=>date("Y-m-d H:i:s")
  1855. ];
  1856. $inr=Db::name("good_exam")->insert($data);
  1857. if($inr){
  1858. //将good_basic数据同步到good表
  1859. $good_basic = Db::name('good_basic')
  1860. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1861. ->find();
  1862. if (!empty($good_basic)) {
  1863. unset($good_basic['id']);
  1864. unset($good_basic['addtime']);
  1865. $good_basic['updatetime'] = date('Y-m-d H:i:s');
  1866. Db::name('good')
  1867. ->strict(false)
  1868. ->where(['spuCode' => $platform['spuCode'], 'is_del' => 0])
  1869. ->update($good_basic);
  1870. }
  1871. Db::commit();
  1872. return app_show(0,"审核成功");
  1873. }
  1874. }
  1875. Db::rollback();
  1876. return error_show(1004,"审核失败");
  1877. }catch (\Exception $e){
  1878. Db::rollback();
  1879. return error_show(1004,$e->getMessage());
  1880. }
  1881. }
  1882. public function copy(){
  1883. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1884. if($supcode==""){
  1885. return error_show(1004,"参数spuCode不能为空");
  1886. }
  1887. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1888. if($data==false){
  1889. return error_show(1004,"未找到商品数据");
  1890. }
  1891. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1892. if($token==''){
  1893. return error_show(105,"参数token不能为空");
  1894. }
  1895. $createrid= $this->uid;
  1896. $creater= $this->uname;
  1897. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1898. $ladd=[];
  1899. $newCode =makeNo("SKU");
  1900. if(!empty($nake)){
  1901. foreach ($nake as $value){
  1902. $tmp=[];
  1903. $tmp['spuCode']=$newCode;
  1904. $tmp['min_num']=$value['min_num'];
  1905. $tmp['nake_fee'] = $value['nake_fee'];
  1906. $tmp['cost_fee'] = $value['cost_fee'];
  1907. $tmp['delivery_fee'] = $value['delivery_fee'];
  1908. $tmp['cert_fee'] = $value['cert_fee'];
  1909. $tmp['mark_fee'] = $value['mark_fee'];
  1910. $tmp['package_fee'] = $value['package_fee'];
  1911. $tmp['other_fee'] = $value['other_fee'];
  1912. $tmp['nake_total'] =$value['nake_total'];
  1913. $tmp['creater_id']=$createrid;
  1914. $tmp['creater']=$creater;
  1915. $tmp['is_del']=$value['is_del'];
  1916. $tmp['addtime']=date("Y-m-d H:i:s");
  1917. $tmp['updatetime']=date("Y-m-d H:i:s");
  1918. $ladd[]=$tmp;
  1919. }
  1920. }
  1921. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1922. $specArr=[];
  1923. if(!empty($spec)){
  1924. foreach ($spec as $value){
  1925. $tmp=[];
  1926. $tmp['spuCode']=$newCode;
  1927. $tmp['spec_id']=$value['spec_id'];
  1928. $tmp['spec_value_id']=$value['spec_value_id'];
  1929. $tmp['is_del']=$value['is_del'];
  1930. $tmp['addtime']=date("Y-m-d H:i:s");
  1931. $tmp['updatetime']=date("Y-m-d H:i:s");
  1932. $specArr[]=$tmp;
  1933. }
  1934. }
  1935. Db::startTrans();
  1936. try {
  1937. unset($data['id']);
  1938. $data['spuCode']=$newCode;
  1939. $data['createrid']=$createrid;
  1940. $data['creater']=$creater;
  1941. $data['status']=7;
  1942. $data['addtime']=date("Y-m-d H:i:s");
  1943. $data['updatetime']=date("Y-m-d H:i:s");
  1944. $cre = Db::name("good_basic")->insertGetId($data);
  1945. if($cre){
  1946. //修改状态,添加待办
  1947. ActionLog::logAdd($this->post['token'], [
  1948. "order_code" =>$newCode,//咨询单详情编号
  1949. "status" => 0,//这里的status是之前的值
  1950. "action_remark" => '',//备注
  1951. "action_type" => "create"//新建create,编辑edit,更改状态status
  1952. ], "SPCB", 7,$data);
  1953. ProcessOrder::AddProcess($this->post['token'], [
  1954. "order_type" => 'SPCB',
  1955. "order_code" =>$newCode,//咨询单详情编号
  1956. "order_id" => $cre,
  1957. "order_status" =>7,
  1958. "before_status"=>0,
  1959. 'holder_id'=>$data['createrid'],
  1960. ]);
  1961. if(!empty($ladd)){
  1962. $na = Db::name("good_nake")->insertAll($ladd);
  1963. if($na==0){
  1964. Db::rollback();
  1965. return error_show(1005,"成本数据复制失败");
  1966. }
  1967. }
  1968. if(!empty($specArr)){
  1969. $sp = Db::name("good_spec")->insertAll($specArr);
  1970. if($sp==0){
  1971. Db::rollback();
  1972. return error_show(1005,"规格数据复制失败");
  1973. }
  1974. }
  1975. Db::commit();
  1976. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1977. }else{
  1978. Db::rollback();
  1979. return error_show(1005,"数据复制失败");
  1980. }
  1981. }catch (\Exception $e){
  1982. Db::rollback();
  1983. return error_show(1004,$e->getMessage());
  1984. }
  1985. }
  1986. public function edit(){
  1987. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1988. if($supcode==""){
  1989. return error_show(1004,"参数spuCode不能为空");
  1990. }
  1991. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1992. if($data==false){
  1993. return error_show(1004,"未找到商品数据");
  1994. }
  1995. $is_down = Db::name("good_platform")
  1996. ->where(["spuCode"=>$supcode,"is_del"=>0])
  1997. ->where("exam_status", "not in", [1, 8])//exam_status=1待完善成本,8已下线,除了这两个状态外其他状态都不允许编辑
  1998. ->find();
  1999. if($is_down!=false){
  2000. return error_show(1004,"存在未下线商品数据");
  2001. }
  2002. if ($data['status'] != 6 && $data['status'] != 7 && $data['status'] != 8) {
  2003. return error_show(1004,"商品状态有误");
  2004. }
  2005. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  2006. if($good_name==""){
  2007. return error_show(1004,"商品名称不能为空");
  2008. }
  2009. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  2010. if($cat_id==''){
  2011. return error_show(1004,"商品分类不能为空");
  2012. }
  2013. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  2014. // if($brandid==''){
  2015. // return error_show(1004,"商品品牌不能为空");
  2016. // }
  2017. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  2018. if($unit==''){
  2019. return error_show(1004,"商品单位不能为空");
  2020. }
  2021. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type']) :"";
  2022. if($good_type===''){
  2023. return error_show(1004,"参数good_type不能为空");
  2024. }
  2025. $moq=0;
  2026. $customized=0;
  2027. if($good_type==1){
  2028. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  2029. if($moq===''){
  2030. return error_show(1004,"定制商品起订量不能为空");
  2031. }
  2032. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  2033. if($customized===''){
  2034. return error_show(1004,"参数customized不能为空");
  2035. }
  2036. }
  2037. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  2038. if($is_exclusive===''){
  2039. return error_show(1004,"参数is_exclusive不能为空");
  2040. }
  2041. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  2042. // if($customized===''){
  2043. // return error_show(1004,"参数customized不能为空");
  2044. // }
  2045. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  2046. if($tax===''){
  2047. return error_show(1004,"参数tax不能为空");
  2048. }
  2049. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  2050. if($supplierNo==''){
  2051. return error_show(1004,"参数supplierNo不能为空");
  2052. }
  2053. if (($this->level == 2) && ($supplierNo != $data['supplierNo'])) {
  2054. $supplier_account = checkHasAccountBySupplierNos([$supplierNo]);
  2055. if (isset($supplier_account[$supplierNo])) return json_show(1004, '该供应商已开通账号,不允许操作');
  2056. }
  2057. $userCommon= \app\admin\common\User::getIns();
  2058. $supplier_temp =$userCommon->handle("hqInfo",["code"=>$supplierNo]);
  2059. if($supplier_temp['code']!=0 || empty($supplier_temp['data']) ) return error_show(1004,"供应商信息未找到");
  2060. $supplierArr=$supplier_temp['data']??[];
  2061. $supplier=$supplierArr['child']??[];
  2062. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']) :"";
  2063. if($good_size==''){
  2064. return error_show(1004,"参数good_size不能为空");
  2065. }
  2066. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo']) :"";
  2067. if($company_id==''){
  2068. return error_show(1004,"参数companyNo不能为空");
  2069. }
  2070. $companyinfo =$userCommon->handle("getCodeAndName",["code"=>$company_id]);
  2071. if($supplierArr['relation_code']==$company_id){
  2072. return error_show(1004,"业务公司与供应商属于同一家公司");
  2073. }
  2074. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  2075. if($is_auth===''){
  2076. return error_show(1004,"参数is_auth不能为空");
  2077. }
  2078. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  2079. // if($auth_img==''){
  2080. // return error_show(1004,"商品不能为空");
  2081. // }
  2082. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  2083. if($after_sales==""){
  2084. return error_show(1004,"参数after_sales不能为空");
  2085. }
  2086. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  2087. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  2088. if($good_remark===""){
  2089. return error_show(1004,"参数good_remark不能为空");
  2090. }
  2091. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  2092. if($weight===""){
  2093. return error_show(1004,"参数weight不能为空");
  2094. }
  2095. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  2096. if($packing_way===""){
  2097. return error_show(1004,"参数packing_way不能为空");
  2098. }
  2099. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  2100. if($packing_size===""){
  2101. return error_show(1004,"参数packing_size不能为空");
  2102. }
  2103. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  2104. if($packing_spec===""){
  2105. return error_show(1004,"参数packing_spec不能为空");
  2106. }
  2107. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  2108. if($packing_weight===""){
  2109. return error_show(1004,"参数packing_weight不能为空");
  2110. }
  2111. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  2112. if($packing_list===""){
  2113. return error_show(1004,"参数packing_list不能为空");
  2114. }
  2115. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  2116. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  2117. if($supply_area===""){
  2118. return error_show(1004,"参数supply_area不能为空");
  2119. }
  2120. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  2121. if($delivery_place===""){
  2122. return error_show(1004,"参数delivery_place不能为空");
  2123. }
  2124. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  2125. if($origin_place===""){
  2126. return error_show(1004,"参数origin_place不能为空");
  2127. }
  2128. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  2129. if($delivery_day===""){
  2130. return error_show(1004,"参数delivery_day不能为空");
  2131. }
  2132. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time']) :"0";
  2133. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  2134. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  2135. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  2136. if($good_img===""){
  2137. return error_show(1004,"参数good_img不能为空");
  2138. }
  2139. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  2140. if($good_thumb_img===""){
  2141. return error_show(1004,"参数good_thumb_img不能为空");
  2142. }
  2143. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  2144. if($good_info_img===""){
  2145. return error_show(1004,"参数good_info_img不能为空");
  2146. }
  2147. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  2148. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  2149. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  2150. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  2151. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  2152. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  2153. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  2154. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  2155. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  2156. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  2157. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  2158. if($market_price===""){
  2159. return error_show(1004,"参数market_price不能为空");
  2160. }
  2161. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"0";
  2162. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  2163. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  2164. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  2165. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"0";
  2166. $stock_moq = isset($this->post['stock_moq'])&&$this->post['stock_moq']!==""? intval($this->post['stock_moq']):"0";
  2167. if($is_stock==1 && $stock_moq ==0){
  2168. return error_show(1004,"库存品备库起订量不能为零");
  2169. }
  2170. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  2171. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  2172. $is_support_barter = isset($this->post['is_support_barter']) && $this->post['is_support_barter'] !== "" ? intval($this->post['is_support_barter']) : 1;
  2173. Db::startTrans();
  2174. try {
  2175. $temp=[
  2176. "good_name"=>$good_name,
  2177. "cat_id"=>$cat_id,
  2178. 'brand_id'=>$brandid,
  2179. "good_unit"=>$unit,
  2180. "good_type"=>$good_type,
  2181. "companyNo"=>$company_id,
  2182. "companyName"=>$companyinfo['data'][$company_id]??"",
  2183. "moq"=>$moq,
  2184. "is_exclusive"=>$is_exclusive,
  2185. "customized"=>$customized,
  2186. "tax"=>$tax,
  2187. "supplierNo"=>$supplierNo,
  2188. "supplierName"=>$supplierArr['name'],
  2189. "is_auth"=>$is_auth,
  2190. "good_size"=>$good_size,
  2191. "auth_img"=>$auth_img,
  2192. "after_sales"=>$after_sales,
  2193. "craft_desc"=>$craft_desc,
  2194. "good_remark"=>$good_remark,
  2195. "weight"=>$weight,
  2196. "packing_way"=>$packing_way,
  2197. "packing_size"=>$packing_size,
  2198. "packing_spec"=>$packing_spec,
  2199. "packing_list"=>$packing_list,
  2200. "packing_weight"=>$packing_weight,
  2201. "good_bar"=>$good_bar,
  2202. "supply_area"=>$supply_area,
  2203. "delivery_place"=>$delivery_place,
  2204. "origin_place"=>$origin_place,
  2205. "delivery_day"=>$delivery_day,
  2206. "lead_time"=>$lead_time,
  2207. "sample_day"=>$sample_day,
  2208. "sample_fee"=>$sample_fee,
  2209. "good_img"=>$good_img,
  2210. "good_thumb_img"=>$good_thumb_img,
  2211. "good_info_img"=>$good_info_img,
  2212. "cert_fee"=>$cert_fee,
  2213. "packing_fee"=>$packing_fee,
  2214. "is_diff"=>$is_diff,
  2215. "config"=>$config,
  2216. "other_config"=>$other_config,
  2217. "is_stock"=>$is_stock,
  2218. "cost_fee"=>$cost_fee,
  2219. "mark_fee"=>$mark_fee,
  2220. "demo_fee"=>$demo_fee,
  2221. "open_fee"=>$open_fee,
  2222. "noble_metal"=>$noble_metal,
  2223. "noble_weight"=>$noble_weight,
  2224. "is_gold_price"=>$is_gold_price,
  2225. "market_price"=>$market_price,
  2226. "nake_price"=>$nake_price,
  2227. "cgd_gold_price"=>$cgd_gold_price,
  2228. "is_step" => count($good_ladder) > 1 ? 1 : 0,
  2229. "stock_moq"=>$stock_moq,
  2230. "status"=>"0",
  2231. "updatetime"=>date("Y-m-d H:i:s"),
  2232. 'is_support_barter'=>$is_support_barter,
  2233. 'chargerid' => $supplier['personid'] ?? $this->uid,
  2234. 'charger' => $supplier['person'] ?? $this->uname,
  2235. ];
  2236. $field = array_diff_assoc($temp,$data);
  2237. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  2238. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  2239. $var = array_diff($temp,$data);
  2240. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  2241. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  2242. if($up){
  2243. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,['id' => $this->uid, 'nickname' => $this->uname]);
  2244. // //修改状态,添加待办
  2245. // ActionLog::logAdd($this->post['token'], [
  2246. // "order_code" =>$supcode,//咨询单详情编号
  2247. // "status" => $data['status'],//这里的status是之前的值
  2248. // "action_remark" => '',//备注
  2249. // "action_type" => "create"//新建create,编辑edit,更改状态status
  2250. // ], "SPCB", 0,$temp);
  2251. //
  2252. // ProcessOrder::AddProcess($this->post['token'], [
  2253. // "order_type" => 'SPCB',
  2254. // "order_code" =>$supcode,//咨询单详情编号
  2255. // "order_id" => $data['id'],
  2256. // "order_status" =>0,
  2257. // "before_status"=>0,
  2258. // 'holder_id'=>$data['createrid'],
  2259. // ]);
  2260. if($speclist!=="" && !empty($speclist)){
  2261. foreach ($speclist as $value){
  2262. $lemp=[];
  2263. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2264. $lemp['spuCode']=$supcode;
  2265. $lemp['spec_id'] = $value['spec_id'];
  2266. $lemp['spec_value_id'] = $value['spec_value_id'];
  2267. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2268. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2269. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2270. $count = Db::name("good_spec")->save($lemp);
  2271. if($count==false){
  2272. Db::rollback();
  2273. return app_show(1004,"商品规格值修改失败");
  2274. }
  2275. }
  2276. }
  2277. if($good_ladder!=="" && !empty($good_ladder)){
  2278. // $user =GetUserInfo($this->post['token']);//获取用户信息,下面更新成本表的创建人
  2279. $top_cat_id = made($cat_id);//获取所有分类
  2280. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2281. foreach ($good_ladder as $value){
  2282. $lemp=[];
  2283. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  2284. $lemp['spuCode']=$supcode;
  2285. $lemp['min_num'] = $value['min_num'];
  2286. $lemp['nake_fee'] = $value['nake_fee'];
  2287. $lemp['cost_fee'] = $value['cost_fee'];
  2288. $lemp['delivery_fee'] = $value['delivery_fee'];
  2289. $lemp['cert_fee'] = $value['cert_fee'];
  2290. $lemp['mark_fee'] = $value['mark_fee'];
  2291. $lemp['package_fee'] = $value['package_fee'];
  2292. $lemp['other_fee'] = $value['other_fee'];
  2293. if ($is_gold_price == 1 && $top_cat_id == 6) {
  2294. $gold =Db::name("gold_price1")->where(["type"=>$noble_metal,"status"=>1,"is_del"=>0])->order("addtime desc")->find();
  2295. //$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'];
  2296. //成本合计=贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用
  2297. //成本总计启用实时金价时,采用供应商实时金价
  2298. $lemp['nake_total'] =$noble_weight *$gold['price']+ $value['cost_fee'] * $noble_weight +
  2299. $value['mark_fee'] + $value['package_fee'] + $value['cert_fee'] + $value['nake_fee'] + $value['delivery_fee'] + $value['other_fee'];
  2300. }else{
  2301. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  2302. }
  2303. $lemp['creater_id'] = $this->uid;
  2304. $lemp['creater'] = $this->uname;
  2305. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  2306. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  2307. $lemp['updatetime'] =date("Y-m-d H:i:s");
  2308. $count = Db::name("good_nake")->save($lemp);
  2309. if($count==false){
  2310. Db::rollback();
  2311. return app_show(1004,"商品规成本修改失败");
  2312. }
  2313. }
  2314. }
  2315. Db::commit();
  2316. return app_show(0,"更新成功");
  2317. }else{
  2318. Db::rollback();
  2319. return error_show(1005,"更新失败");
  2320. }
  2321. }catch (\Exception $e){
  2322. Db::rollback();
  2323. return error_show(1004,$e->getMessage());
  2324. }
  2325. }
  2326. public function checkPrice(){
  2327. $param = $this->request->only(['spuCode', 'min_num', 'platform_id', 'relaComNo'], 'post', 'trim');
  2328. $val = Validate::rule([
  2329. 'spuCode|商品成本编码' => 'require',
  2330. 'min_num|起订量' => 'require|number|gt:0',
  2331. 'platform_id|上线平台ID' => 'require|number|gt:0',
  2332. 'relaComNo'=>'require'
  2333. ]);
  2334. if($val->check($param) == false) return json_show(1005,$val->getError());
  2335. $good =Db::name("good_basic")
  2336. ->field('id,is_stock,cat_id,is_gold_price,noble_weight,cgd_gold_price')
  2337. ->where(["spuCode"=>$param['spuCode'],"is_del"=>0])
  2338. ->findOrEmpty();
  2339. if(empty($good)) return json_show(1005,"商品数据未找到");
  2340. // $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  2341. // if($num==""){
  2342. // return error_show(1005,"参数min_num不能为空");
  2343. // }
  2344. $nakelist = Db::name("good_nake")
  2345. ->where(['spuCode'=>$param['spuCode'],"is_del"=>0])
  2346. ->where([["min_num","<=",$param['min_num']]])
  2347. ->order("min_num desc")
  2348. ->find();
  2349. if($nakelist==false){
  2350. $nakelist = Db::name("good_nake")
  2351. ->where(['spuCode'=>$param['spuCode'],"is_del"=>0])
  2352. ->order("min_num asc")
  2353. ->find();
  2354. //非库存品的话,继续校验最小起订量
  2355. //库存品的话,不足采购起订量的时候,取采购最小起订量
  2356. if ($good['is_stock'] == 0) return error_show(1010, "起订量不足{$nakelist['min_num']}");
  2357. }
  2358. //计算毛利率
  2359. $budget = get_budget($good['cat_id'],$param['relaComNo'],$param['platform_id']);
  2360. $top_cat_id = made($good['id']);//获取所有分类
  2361. $top_cat_id = isset($top_cat_id[0]['id']) ? $top_cat_id[0]['id'] : 0;//获取顶级分类id
  2362. $sale_cost_fee = 0;
  2363. if ($good['is_gold_price'] == 1 && $top_cat_id == 6) {
  2364. // $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'];
  2365. //系统售价=(贵金属重量*供应商采购金价 + 工艺费*贵金属重量+加标费+包装费+证书费+成本裸价+运费+其他费用)/(1-成本售价/100)
  2366. $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);
  2367. //计算工艺费
  2368. //销售工艺费=(( 商品重量* 供应商采购金价 + 采购成本工艺费* 商品重量+包装费+加标费+证书费+产品裸价+其他费用)/(1-成本售价/100)-(包装费+加标费+证书费+产品裸价0+运费+其他费用) )/商品重量-供应商采购金价
  2369. $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"];
  2370. }else{
  2371. // $saleprice = ($nakelist['mark_fee'] + $nakelist['package_fee'] + $nakelist['cert_fee'] + $nakelist['delivery_fee'] + $nakelist['nake_fee']) / (1 - $budget);
  2372. // (加标费+包装费+证书费+成本裸价+运费)/(1-成本售价/100)=系统售价
  2373. // $saleprice = (加标费 + 包装费 + 证书费 + 运费 + 成本裸价+其他费用) / (1 - $budget);
  2374. $saleprice = $nakelist['nake_total'] / (1 - $budget);
  2375. }
  2376. return app_show(0, "获取成功", ["sale_price" => round($saleprice, 2), 'new_cost_fee' => round($sale_cost_fee, 2)]);
  2377. }
  2378. //咨询成交商品池 添加上线商品
  2379. public function onlineZixunGoods()
  2380. {
  2381. $param = $this->request->only(['platform', 'codes', 'online_reason', 'online_remark', 'token'], 'post', 'trim');
  2382. $val = Validate::rule([
  2383. 'platform|所选上线平台' => 'require|number|gt:0',
  2384. 'codes|所选上线商品编号' => 'require',
  2385. 'online_reason|上线原因' => 'require',
  2386. 'online_remark|上线备注' => 'require',
  2387. 'token' => 'require',
  2388. ]);
  2389. if (!$val->check($param)) return error_show(1004, $val->getError());
  2390. $good_zixun_list = Db::name("good_zixun")
  2391. ->where(["is_del" => 0])
  2392. ->whereIn('spuCode', $param['codes'])
  2393. ->column('*', 'spuCode');
  2394. if (empty($good_zixun_list)) return error_show(1004, "未找到相关咨询商品数据");
  2395. $a = array_diff($param['codes'], array_keys($good_zixun_list));
  2396. if (!empty($a)) return error_show(1005, '该咨询商品不存在' . implode(',', $a));
  2397. $isonline = Db::name("good_platform")
  2398. ->alias('gp')
  2399. ->field('gp.id,gp.spuCode,gb.good_name,gb.good_img,gp.exam_status')
  2400. ->where(["gp.platform_code" => $param['platform'], "gp.is_del" => 0])
  2401. ->whereIn('gp.spuCode', $param['codes'])
  2402. ->leftJoin('good_basic gb', 'gb.spuCode=gp.spuCode AND gb.is_del=0')
  2403. ->select()
  2404. ->toArray();
  2405. if (!empty($isonline)) {
  2406. foreach ($isonline as &$v) {
  2407. $spec = Db::name("good_spec")
  2408. ->where(["spuCode" => $v['spuCode'], "is_del" => 0])
  2409. ->select()
  2410. ->toArray();
  2411. $speclist = [];
  2412. if (!empty($spec)) {
  2413. foreach ($spec as $val) {
  2414. $temp = [];
  2415. $temp['id'] = $val['id'];
  2416. $temp['spuCode'] = $val['spuCode'];
  2417. $temp['spec_id'] = $val['spec_id'];
  2418. $temp['spec_value_id'] = $val['spec_value_id'];
  2419. $temp['is_del'] = $val['is_del'];
  2420. $sp = Db::name("specs")->where(["id" => $val['spec_id']])->find();
  2421. $temp['spec_name'] = isset($sp["spec_name"]) ? $sp["spec_name"] : "";
  2422. $spv = Db::name("spec_value")->where(["id" => $val['spec_value_id']])->find();
  2423. $temp['spec_value'] = isset($spv["spec_value"]) ? $spv["spec_value"] : "";
  2424. $speclist[] = $temp;
  2425. }
  2426. }
  2427. $v["speclist"] = empty($speclist) ? [] : $speclist;
  2428. }
  2429. return app_show(1009, "存在已上线产品", $isonline);
  2430. }
  2431. if (!empty($isonline)) return error_show(1005, $isonline['spuCode'] . '该商品已在商品成本管理中,请在商品成本管理菜单提交上线!');
  2432. $user = GetUserInfo($param['token']);
  2433. if (empty($user) || $user['code'] != 0) return error_show(1002, "用户数据不存在");
  2434. $createrid = isset($user["data"]['id']) ? $user["data"]['id'] : "";
  2435. $creater = isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  2436. $data = $good_insert_data = $good_basic_insert_data = $good_spec_insert_data = [];
  2437. $i = 0;
  2438. $all_nakes = Db::name("good_nake")
  2439. ->where(["is_del" => 0])->fetchSql()
  2440. ->whereIn('spuCode', $param['codes'])
  2441. ->group('spuCode')
  2442. ->column('count(`id`) total', 'spuCode');
  2443. $all_good = Db::name('good')
  2444. ->where('is_del', 0)
  2445. ->whereIn('spuCode', $param['codes'])
  2446. ->column('id', 'spuCode');
  2447. if (!empty($all_good)) return error_show(1004, '请从商品成本提交该商品上线');
  2448. $all_good_basic = Db::name('good_basic')
  2449. ->where('is_del', 0)
  2450. ->whereIn('spuCode', $param['codes'])
  2451. ->column('id', 'spuCode');
  2452. if (!empty($all_good_basic)) return error_show(1004, '请从商品成本提交该商品上线');
  2453. foreach ($param['codes'] as $value) {
  2454. //改变编码规则,将原来的skuCode后两位换成序列号
  2455. //str_pad字符串填充
  2456. $skuCode = makeNo("SN");
  2457. $skuCode = substr($skuCode, 0, -2) . str_pad($i, 2, '0', STR_PAD_LEFT);
  2458. $data[] = [
  2459. "spuCode" => $value,
  2460. "skuCode" => $skuCode,
  2461. "platform_code" => $param['platform'],
  2462. "online_reason" => $param['online_reason'],
  2463. "online_remark" => $param['online_remark'],
  2464. "exam_status" => isset($all_nakes[$value]) ? ($all_nakes[$value] > 0 ? 2 : 1) : 1,
  2465. "is_online" => 0,
  2466. "status" => 0,
  2467. "is_del" => 0,
  2468. "creater" => $creater,
  2469. "createrid" => $createrid,
  2470. "addtime" => date("Y-m-d H:i:s"),
  2471. "updatetime" => date("Y-m-d H:i:s")
  2472. ];
  2473. //good表
  2474. if (!isset($all_good[$value])) {
  2475. $good_insert_data[] = [
  2476. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2477. 'good_code' => $good_zixun_list[$value]['good_code'],
  2478. 'good_name' => $good_zixun_list[$value]['good_name'],
  2479. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2480. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2481. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2482. 'good_type' => $good_zixun_list[$value]['good_type'],
  2483. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2484. 'moq' => $good_zixun_list[$value]['moq'],
  2485. 'customized' => $good_zixun_list[$value]['customized'],
  2486. 'tax' => $good_zixun_list[$value]['tax'],
  2487. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2488. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2489. 'is_stock' => '',
  2490. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2491. 'after_sales' => '',
  2492. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2493. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2494. 'good_size' => '',
  2495. 'weight' => $good_zixun_list[$value]['weight'],
  2496. 'packing_way' => '',
  2497. 'packing_size' => '',
  2498. 'packing_spec' => '',
  2499. 'packing_list' => '',
  2500. 'packing_weight' => '',
  2501. 'good_bar' => '',
  2502. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2503. 'delivery_place' => '',
  2504. 'origin_place' => '',
  2505. 'delivery_day' => 0,
  2506. 'lead_time' => '',
  2507. 'sample_day' => '',
  2508. 'sample_fee' => '',
  2509. 'good_img' => $good_zixun_list[$value]['good_img'],
  2510. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2511. 'good_info_img' => $good_zixun_list[$value]['good_info_img'],
  2512. 'cert_fee' => '',
  2513. 'packing_fee' => '',
  2514. 'cost_fee' => '',
  2515. 'mark_fee' => '',
  2516. 'demo_fee' => '',
  2517. 'open_fee' => '',
  2518. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2519. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2520. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2521. 'cgd_gold_price' => '',
  2522. 'market_price' => '',
  2523. 'nake_price' => '',
  2524. 'is_step' => '',
  2525. 'is_online' => '',
  2526. 'status' => 1,//待完善成本
  2527. 'createrid' => $createrid,
  2528. 'creater' => $creater,
  2529. 'is_del' => 0,
  2530. 'field_change' => '',
  2531. 'addtime' => date('Y-m-d H:i:s'),
  2532. 'updatetime' => date('Y-m-d H:i:s'),
  2533. 'is_exclusive' => '',
  2534. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2535. 'config' => $good_zixun_list[$value]['config'],
  2536. 'other_config' => $good_zixun_list[$value]['other_config'],
  2537. ];
  2538. }
  2539. //good_basic表
  2540. if (!isset($all_good_basic[$value])) {
  2541. $good_basic_insert_data[] = [
  2542. 'spuCode' => $good_zixun_list[$value]['spuCode'],
  2543. 'good_code' => $good_zixun_list[$value]['good_code'],
  2544. 'good_name' => $good_zixun_list[$value]['good_name'],
  2545. 'cat_id' => $good_zixun_list[$value]['cat_id'],
  2546. 'brand_id' => $good_zixun_list[$value]['brand_id'],
  2547. 'companyNo' => $good_zixun_list[$value]['companyNo'],
  2548. 'good_unit' => $good_zixun_list[$value]['good_unit'],
  2549. 'good_type' => $good_zixun_list[$value]['good_type'],
  2550. 'moq' => $good_zixun_list[$value]['moq'],
  2551. 'customized' => $good_zixun_list[$value]['customized'],
  2552. 'tax' => $good_zixun_list[$value]['tax'],
  2553. 'supplierNo' => $good_zixun_list[$value]['supplierNo'],
  2554. 'is_auth' => $good_zixun_list[$value]['is_auth'],
  2555. 'auth_img' => $good_zixun_list[$value]['auth_img'],
  2556. 'after_sales' => '',
  2557. 'craft_desc' => $good_zixun_list[$value]['craft_desc'],
  2558. 'good_remark' => $good_zixun_list[$value]['good_remark'],
  2559. 'weight' => $good_zixun_list[$value]['weight'],
  2560. 'packing_way' => '',
  2561. 'packing_size' => '',
  2562. 'packing_spec' => '',
  2563. 'packing_list' => '',
  2564. 'packing_weight' => '',
  2565. 'good_bar' => '',
  2566. 'supply_area' => $good_zixun_list[$value]['supply_area'],
  2567. 'delivery_place' => '',
  2568. 'origin_place' => '',
  2569. 'delivery_day' => '',
  2570. 'lead_time' => '',
  2571. 'sample_day' => '',
  2572. 'sample_fee' => '',
  2573. 'good_img' => '',//$good_zixun_list[$value]['good_img'],
  2574. 'good_thumb_img' => $good_zixun_list[$value]['good_thumb_img'],
  2575. 'good_info_img' => $good_zixun_list[$value]['good_img'],//商品主图对应到商品详情
  2576. 'cert_fee' => '',
  2577. 'packing_fee' => '',
  2578. 'cost_fee' => '',
  2579. 'mark_fee' => '',
  2580. 'demo_fee' => '',
  2581. 'open_fee' => '',
  2582. 'noble_metal' => $good_zixun_list[$value]['noble_metal'],
  2583. 'noble_weight' => $good_zixun_list[$value]['good_weight'],
  2584. 'is_gold_price' => $good_zixun_list[$value]['is_gold_price'],
  2585. 'cgd_gold_price' => '',
  2586. 'market_price' => '',
  2587. 'nake_price' => '',
  2588. 'is_step' => '',
  2589. 'is_online' => '',
  2590. 'status' => 8,//咨询商品待编辑
  2591. 'createrid' => $createrid,
  2592. 'creater' => $creater,
  2593. 'field_change' => '',
  2594. 'is_del' => 0,
  2595. 'addtime' => date('Y-m-d H:i:s'),
  2596. 'updatetime' => date('Y-m-d H:i:s'),
  2597. 'is_diff' => $good_zixun_list[$value]['is_diff'],
  2598. 'config' => $good_zixun_list[$value]['config'],
  2599. 'other_config' => $good_zixun_list[$value]['other_config'],
  2600. ];
  2601. }
  2602. //good_spec
  2603. if (!empty($good_zixun_list[$value]['specinfo'])) {
  2604. $spec_list = json_decode($good_zixun_list[$value]['specinfo'], true);
  2605. foreach ($spec_list as $spec) {
  2606. $temp = Db::name('good_spec')
  2607. ->field('id')
  2608. ->where(['spuCode' => $value, 'spec_id' => $spec['specid'], 'spec_value_id' => $spec['spec_value_id'], 'is_del' => 0])
  2609. ->find();
  2610. if (!empty($temp)) {
  2611. $good_spec_insert_data[] = [
  2612. 'spuCode' => $value,
  2613. 'spec_id' => $spec['specid'],
  2614. 'spec_value_id' => $spec['spec_value_id'],
  2615. 'is_del' => 0,
  2616. 'addtime' => date('Y-m-d H:i:s'),
  2617. 'updatetime' => date('Y-m-d H:i:s'),
  2618. ];
  2619. }
  2620. }
  2621. }
  2622. $i++;
  2623. }
  2624. if (!empty($isonline)) {
  2625. return app_show(1009, "存在已上线产品", $isonline);
  2626. }
  2627. Db::startTrans();
  2628. try {
  2629. $create = Db::name("good_platform")->insertAll($data);
  2630. Db::name("good_zixun")
  2631. ->where(["is_del" => 0, 'status' => 1])
  2632. ->whereIn('spuCode', $param['codes'])
  2633. ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);
  2634. if (!empty($good_insert_data)) Db::name('good')->insertAll($good_insert_data);
  2635. if (!empty($good_basic_insert_data)) Db::name('good_basic')->insertAll($good_basic_insert_data);
  2636. if (!empty($good_spec_insert_data)) Db::name('good_spec')->insertAll($good_spec_insert_data);
  2637. if ($create) {
  2638. foreach ($good_basic_insert_data as $value) {
  2639. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2640. "order_code" =>$value['spuCode'],//
  2641. "status" => 8,//待产品审核
  2642. "action_remark" => '',//备注
  2643. "action_type" => "create"//新建create,编辑edit,更改状态status
  2644. ], "SPCB", $value['status'], $value);
  2645. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2646. "order_type" => 'SPCB',
  2647. "order_code" =>$value['spuCode'],//
  2648. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2649. "order_status" => 8,//待产品审核
  2650. "before_status" => 0,//待产品审核
  2651. 'holder_id'=>$value['createrid'],
  2652. ]);
  2653. }
  2654. foreach ($data as $value) {
  2655. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2656. "order_code" =>$value['skuCode'],//
  2657. "status" => 0,//待产品审核
  2658. "action_remark" => '',//备注
  2659. "action_type" => "create"//新建create,编辑edit,更改状态status
  2660. ], "SPSX", $value['exam_status'], $value);
  2661. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2662. "order_type" => 'SPSX',
  2663. "order_code" =>$value['skuCode'],//
  2664. "order_id" => isset($value['id']) ? $value['id'] : 0,
  2665. "order_status" =>$value['exam_status'],//待产品审核
  2666. "before_status" => 0,
  2667. 'holder_id' => $value['createrid'],
  2668. ]);
  2669. }
  2670. Db::commit();
  2671. return app_show(0, "提交成功");
  2672. } else {
  2673. Db::rollback();
  2674. return error_show(1004, "提交失败");
  2675. }
  2676. } catch (Exception $exception) {
  2677. Db::rollback();
  2678. return error_show(1005, $exception->getMessage());
  2679. }
  2680. }
  2681. //商品上线审核流程时,驳回重新审核
  2682. public function rejectGoodToAgainExamine()
  2683. {
  2684. $param = $this->request->only(['token', 'skuCode', 'exam_remark' => ''], 'post', 'trim');
  2685. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  2686. if (!$val->check($param)) return error_show(1005, $val->getError());
  2687. $user = GetUserInfo($param['token']);
  2688. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2689. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2690. Db::startTrans();
  2691. try {
  2692. $rs = Db::name("good_platform")
  2693. ->field('id,spuCode,skuCode,exam_status,createrid')
  2694. ->where(['skuCode' => $param['skuCode'], 'is_del' => 0])
  2695. ->where('exam_status', '<>', 6)//exam_status==6上线成功
  2696. ->find();
  2697. if (empty($rs)) throw new \Exception('该记录不存在');
  2698. $old_exam_staus = $rs['exam_status'];
  2699. $good_nake = Db::name("good_nake")
  2700. ->field('id')
  2701. ->where(["spuCode" => $rs['spuCode'], "is_del" => 0])
  2702. ->find();
  2703. $exam_status = empty($good_nake) ? 1 : 2;
  2704. if ($exam_status == $rs['exam_status']) $exam_status = 7;//第一级审核失败时,状态改为'审核失败'
  2705. Db::name("good_platform")
  2706. ->where('id', $rs['id'])
  2707. ->save([
  2708. 'exam_status' => $exam_status,
  2709. 'updatetime' => date('Y-m-d H:i:s'),
  2710. ]);
  2711. Db::name("good_exam")->insert([
  2712. 'code' => $rs['skuCode'],
  2713. 'exam_status' => $old_exam_staus,
  2714. 'type' => 2,
  2715. 'exam_id' => $createrid,
  2716. 'exam_name' => $creater,
  2717. 'exam_remark' => $param['exam_remark'],
  2718. 'addtime' => date('Y-m-d H:i:s')
  2719. ]);
  2720. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2721. "order_code" => $param['skuCode'],//编号
  2722. "status" => $rs['exam_status'],
  2723. "action_remark" => '',//备注
  2724. "action_type" => "status"//新建create,编辑edit,更改状态status
  2725. ], "SPSX", $exam_status, $param);
  2726. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2727. "order_type" => 'SPSX',
  2728. "order_code" => $param['skuCode'],//咨询单详情编号
  2729. "order_id" => $rs['id'],
  2730. "order_status" => $exam_status,
  2731. "before_status" => $rs['exam_status'],
  2732. 'holder_id' => $rs['createrid'],
  2733. ]);
  2734. Db::commit();
  2735. return app_show(0, "驳回重新审核成功");
  2736. } catch (\Exception $e) {
  2737. Db::rollback();
  2738. return error_show(1004, '驳回重新审核失败,' . $e->getMessage());
  2739. }
  2740. }
  2741. //同一个spuCode下所有的商品都下线
  2742. public function offlineGoodBySpuCode()
  2743. {
  2744. $param = $this->request->only(['token', 'spuCode', 'offline_reason', 'offline_remark' => ''], 'post', 'trim');
  2745. $val = Validate::rule(['token' => 'require', 'spuCode' => 'require', 'offline_reason|下线原因' => 'require']);
  2746. if (!$val->check($param)) return error_show(1005, $val->getError());
  2747. $user = GetUserInfo($param['token']);
  2748. $createrid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  2749. $creater = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  2750. Db::startTrans();
  2751. try {
  2752. $good_name = Db::name("good_basic")
  2753. ->where(['is_del' => 0, 'spuCode' => $param['spuCode']])
  2754. ->value('good_name', '');
  2755. $skuCodeS = Db::name("good_platform")
  2756. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
  2757. ->whereNotIn('exam_status', [7,8])
  2758. ->column('exam_status,skuCode', 'skuCode');
  2759. if ($skuCodeS) {
  2760. // if (empty($skuCodeS)) throw new \Exception('该商品未在任何平台申请上线');
  2761. //商品平台
  2762. Db::name("good_platform")
  2763. ->where(['spuCode' => $param['spuCode'], 'is_del' => 0])//exam_status 7审核失败,8已下线
  2764. ->whereNotIn('exam_status', [7,8])
  2765. ->save([
  2766. 'exam_status' => 8,
  2767. 'updatetime' => date('Y-m-d H:i:s'),
  2768. ]);
  2769. //商品下线记录
  2770. $good_offline_log_id = Db::name("good_offline_log")->insertGetId([
  2771. 'spuCode' => $param['spuCode'],
  2772. 'skuCodes' => implode(',', array_keys($skuCodeS)),
  2773. 'good_name' => $good_name,
  2774. 'offline_reason' => $param['offline_reason'],
  2775. 'offline_remark' => $param['offline_remark'],
  2776. 'createrid' => $createrid,
  2777. 'creater' => $creater,
  2778. 'addtime' => date('Y-m-d H:i:s'),
  2779. ]);
  2780. //根据权限查询应该接收商品下线通知的人员
  2781. $all_uid_name = Db::name('role_action')
  2782. ->whereFindInSet('action_conllect', '877')//数据写死的,要注意各个环境数据是否一致
  2783. ->field('role_id')
  2784. ->buildSql();
  2785. $all_user = Db::name('user_role')
  2786. ->alias('ur')
  2787. ->where('ur.roleid IN ' . $all_uid_name)
  2788. ->leftJoin('depart_user du', 'du.uid = ur.uid AND du.is_del=0')
  2789. ->column('ur.uid,du.nickName');
  2790. $insert_good_exam_data = $insert_order_msg_data = [];
  2791. foreach ($skuCodeS as $skuCode => $value) {
  2792. $insert_good_exam_data[] = [
  2793. 'code' => $skuCode,
  2794. 'exam_status' => 8,
  2795. 'type' => 2,
  2796. 'exam_id' => $createrid,
  2797. 'exam_name' => $creater,
  2798. 'exam_remark' => '',
  2799. 'addtime' => date('Y-m-d H:i:s')
  2800. ];
  2801. ActionLog::logAdd(['id' => $createrid, 'nickname' => $creater], [
  2802. "order_code" => $skuCode,//编号
  2803. "status" =>$value['exam_status'] ,
  2804. "action_remark" => '',//备注
  2805. "action_type" => "status"//新建create,编辑edit,更改状态status
  2806. ], "GOL", 8, $param);
  2807. ProcessOrder::AddProcess(['id' => $createrid, 'nickname' => $creater], [
  2808. "order_type" => 'GOL',
  2809. "order_code" => $skuCode,
  2810. "order_id" => $good_offline_log_id,
  2811. "order_status" => 8,
  2812. "before_status" => $value['exam_status']
  2813. ]);
  2814. foreach ($all_user as $itemitem) {
  2815. $insert_order_msg_data[] = [
  2816. 'content' => '商品下线:' . $skuCode . '由' . $creater . '操作下线',
  2817. 'orderCode' => $skuCode,
  2818. 'order_type' => 'GOL',
  2819. 'order_status' => 8,
  2820. 'order_id' => $good_offline_log_id,
  2821. 'uid' => $itemitem['uid'],
  2822. 'uname' => empty($itemitem['nickName']) ? '' : $itemitem['nickName'],
  2823. 'apply_id' => $createrid,
  2824. 'apply_name' => $creater,
  2825. 'is_read' => 0,
  2826. 'addtime' => date('Y-m-d H:i:s'),
  2827. 'updatetime' => date('Y-m-d H:i:s'),
  2828. ];
  2829. }
  2830. }
  2831. //变动记录
  2832. Db::name("good_exam")->insertAll($insert_good_exam_data);
  2833. //消息表
  2834. Db::name('order_msg')->insertAll($insert_order_msg_data);
  2835. }
  2836. //处理有赞平台
  2837. $rs = Db::name('platform_youzan')
  2838. ->field('id,spuCode,skuCode,exam_status,platform_id')
  2839. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  2840. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  2841. ->select()
  2842. ->toArray();
  2843. if ($rs) {
  2844. $insert_good_offline_log_youzan_data = [];
  2845. foreach ($rs as $value) {
  2846. $curl_data = [
  2847. 'item_no' => $value['skuCode'],//商品自定义编码 skuCode
  2848. 'uid' => $createrid,
  2849. 'nickname' => $creater,
  2850. ];
  2851. //已上线的要调用有赞接口下线
  2852. //调有赞项目的接口,从有赞平台下线该商品
  2853. if($value['exam_status'] == PlatformYouzan::$exam_status_6){
  2854. $host = config('app.yz_domain');
  2855. $response = curl_request($host . 'api/yz_goodup_offline', $curl_data);
  2856. $response = json_decode($response, true);
  2857. if ($response['code'] != 0) throw new Exception($response['message']);
  2858. }
  2859. $insert_good_offline_log_youzan_data[] = [
  2860. 'spuCode' => $value['spuCode'],
  2861. 'skuCodes' => $value['skuCode'],
  2862. 'good_name' => $good_name,
  2863. 'offline_reason' => $param['offline_reason'],
  2864. 'offline_remark' => $param['offline_remark'],
  2865. 'createrid' => $createrid,
  2866. 'creater' => $creater,
  2867. 'addtime' => date('Y-m-d H:i:s')
  2868. ];
  2869. }
  2870. Db::name('platform_youzan')
  2871. ->where(['spuCode' => $param['spuCode'], 'is_del' => PlatformYouzan::$del_normal])
  2872. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_7, PlatformYouzan::$exam_status_8])
  2873. ->update([
  2874. 'exam_status' => PlatformYouzan::$exam_status_8,
  2875. 'offline_reason_id' => $param['offline_reason'],
  2876. 'offline_remark' => $param['offline_remark'],
  2877. 'updaterid' => $createrid,
  2878. 'updater' => $creater,
  2879. 'updatetime' => date('Y-m-d H:i:s')
  2880. ]);
  2881. //下线记录表增加记录
  2882. if ($insert_good_offline_log_youzan_data) Db::name('good_offline_log_youzan')->insertAll($insert_good_offline_log_youzan_data);
  2883. }
  2884. Db::commit();
  2885. return app_show(0, "下线成功");
  2886. } catch (\Exception $e) {
  2887. Db::rollback();
  2888. return error_show(1004, '操作失败,' . $e->getMessage());
  2889. }
  2890. }
  2891. //判断是否允许修改成本信息和基础信息
  2892. public function checkIsUpdate()
  2893. {
  2894. $spuCode = $this->request->post('spuCode', '', 'trim');
  2895. if ($spuCode == '') return error_show(1004, '成本商品编号不能为空');
  2896. $is_allow_update = 1;
  2897. //检查是否有上线记录
  2898. $rs = Db::name('good_platform')
  2899. ->field('id')
  2900. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  2901. ->whereNotIn('exam_status', [0, 8])//0待提交,8已下线
  2902. ->find();
  2903. if (!empty($rs)) $is_allow_update = 0;
  2904. else {
  2905. $rs = PlatformYouzan::field('id')
  2906. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  2907. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])//8已下线,2审核驳回
  2908. ->findOrEmpty()
  2909. ->isEmpty();
  2910. if (!$rs) $is_allow_update = 0;
  2911. }
  2912. return app_show(0, '请求成功', ['is_allow_update' => $is_allow_update]);
  2913. }
  2914. private function isUpdate($spuCode){
  2915. $is_allow_update = 1;
  2916. //检查是否有上线记录
  2917. $rs = Db::name('good_platform')
  2918. ->field('id')
  2919. ->where(['spuCode' => $spuCode, 'is_del' => 0])
  2920. ->whereNotIn('exam_status', [0, 5])
  2921. ->find();
  2922. if (!empty($rs)) $is_allow_update = 0;
  2923. else {
  2924. $rs = PlatformYouzan::field('id')
  2925. ->where(['spuCode' => $spuCode, 'is_del' => PlatformYouzan::$del_normal])
  2926. ->whereNotIn('exam_status', [PlatformYouzan::$exam_status_8,PlatformYouzan::$exam_status_2])
  2927. ->findOrEmpty()
  2928. ->isEmpty();
  2929. if (!$rs) $is_allow_update = 0;
  2930. }
  2931. return $is_allow_update;
  2932. }
  2933. //获取某个商品编号下的所有审核备注列表
  2934. public function getGoodExamList()
  2935. {
  2936. $param = $this->request->filter('trim')->only(['token', 'skuCode', 'page' => 1, 'size' => 15], 'post');
  2937. $val = Validate::rule(['token' => 'require', 'skuCode' => 'require']);
  2938. if (!$val->check($param)) return error_show(1005, $val->getError());
  2939. $count = Db::name('good_exam')
  2940. ->where('code', $param['skuCode'])
  2941. ->count('id');
  2942. $list = Db::name('good_exam')
  2943. ->where('code', $param['skuCode'])
  2944. ->order('id')
  2945. ->page($param['page'], $param['size'])
  2946. ->select()
  2947. ->toArray();
  2948. return app_show(0, '请求成功', ['list' => $list, 'count' => $count]);
  2949. }
  2950. //获取某个商品编号下的所有审核备注列表
  2951. public function changeLog()
  2952. {
  2953. $param = $this->request->filter('trim')->only(["code"=>"","type"=>""], 'post');
  2954. $val = Validate::rule(['code' => 'require|max:255', 'type' => 'require|number|in:1,2,3,4,5,6,7,8']);
  2955. if (!$val->check($param)) return error_show(1005, $val->getError());
  2956. $count = Db::name('change_log')
  2957. ->where([['code',"=", $param['code']],["type","=",$param['type']]])
  2958. ->json(["after_info","before_info"])
  2959. ->order("id desc")
  2960. ->findOrEmpty();
  2961. return app_show(0, '请求成功', $count);
  2962. }
  2963. }