Goodup.php 164 KB

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