Goodup.php 125 KB

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