Goodup.php 156 KB

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