Goodup.php 168 KB

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