Goodup.php 151 KB

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