Goodup.php 156 KB

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