Goodup.php 157 KB

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