Goodup.php 166 KB

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