Goodup.php 155 KB

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