Goodup.php 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ChangeLog;
  4. use think\App;
  5. use think\facade\Db;
  6. class Goodup extends Base
  7. {
  8. public $noble=[];
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->noble=\think\facade\Config::get("noble");
  13. }
  14. public function list(){
  15. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  16. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  17. $where =[["is_del","=",0]];
  18. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):"";
  19. if($cat_id!==""){
  20. $cat_ids=catChild($cat_id);
  21. $where[]=['cat_id',"in",$cat_ids];
  22. }
  23. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  24. if($good_name!==""){
  25. $where[]=['good_name',"like","%$good_name%"];
  26. }
  27. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  28. :"";
  29. if($spucode!==""){
  30. $where[]=['spuCode',"like","%$spucode%"];
  31. }
  32. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type'])
  33. :"";
  34. if($good_type!==""){
  35. $where[]=['good_type',"=",$good_type];
  36. }
  37. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo'])
  38. :"";
  39. if($companyNo!==""){
  40. $where[]=['companyNo',"like","%$companyNo%"];
  41. }
  42. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  43. :"";
  44. if($supplierNo!==""){
  45. $where[]=['supplierNo',"like","%$supplierNo%"];
  46. }
  47. $supplier = isset($this->post['supplier']) && $this->post['supplier'] !=="" ? trim($this->post['supplier'])
  48. :"";
  49. if($supplier!==""){
  50. $suppliernos = Db::name("supplier")->where([["name","like","%$supplier%"]])->column("code");
  51. $where[]=['supplierNo',"in",$suppliernos];
  52. }
  53. $company = isset($this->post['company']) && $this->post['company'] !=="" ? trim($this->post['company'])
  54. :"";
  55. if($company!==""){
  56. $companyNos = Db::name("business")->where([["company","like","%$company%"]])->column("companyNo");
  57. $where[]=['companyNo',"in",$companyNos];
  58. }
  59. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid'])
  60. :"";
  61. if($brandid!==""){
  62. $where[]=['brand_id',"=",$brandid];
  63. }
  64. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  65. :"";
  66. if($status!==""){
  67. $where[]=['status',"=",$status];
  68. }
  69. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  70. if($start!==""){
  71. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  72. }
  73. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  74. if($end!==""){
  75. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  76. }
  77. $count = Db::name('good_basic')->where($where)->count();
  78. $total = ceil($count / $size);
  79. $page = $page >= $total ? $total : $page;
  80. $list = Db::name('good_basic')->where($where)->page($page,$size)->order("addtime desc")->select();
  81. $data=[];
  82. foreach ($list as $value){
  83. $value["cat_info"]= made($value['cat_id'],[]);
  84. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  85. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  86. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  87. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  88. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  89. $value['company'] = isset($company['company'])?$company['company']:"";
  90. $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  91. $value['supplier_name']=isset($supplier['name'])?$supplier['name']:"";
  92. $value['good_info_img']=$value['good_info_img'];
  93. $value['good_img']=$value['good_img'];
  94. $value['exclusive']=makeExcluse($value['is_exclusive']);
  95. $value['noble_name']=isset($value['noble_metal'])&&$value['noble_metal']!=0?$this->noble[$value['noble_metal']] :"";
  96. $data[]=$value;
  97. }
  98. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  99. }
  100. public function create(){
  101. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  102. if($good_name==""){
  103. return error_show(1004,"商品名称不能为空");
  104. }
  105. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  106. if($cat_id==''){
  107. return error_show(1004,"商品分类不能为空");
  108. }
  109. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  110. if($brandid==''){
  111. return error_show(1004,"商品品牌不能为空");
  112. }
  113. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  114. if($unit==''){
  115. return error_show(1004,"商品单位不能为空");
  116. }
  117. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  118. :"";
  119. if($good_type===''){
  120. return error_show(1004,"参数good_type不能为空");
  121. }
  122. $moq=0;
  123. $customized=0;
  124. if($good_type==1){
  125. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  126. if($moq===''){
  127. return error_show(1004,"定制商品起订量不能为空");
  128. }
  129. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  130. if($customized===''){
  131. return error_show(1004,"参数customized不能为空");
  132. }
  133. }
  134. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  135. if($is_exclusive===''){
  136. return error_show(1004,"参数is_exclusive不能为空");
  137. }
  138. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  139. // if($customized===''){
  140. // return error_show(1004,"参数customized不能为空");
  141. // }
  142. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  143. if($tax===''){
  144. return error_show(1004,"参数tax不能为空");
  145. }
  146. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  147. if($supplierNo==''){
  148. return error_show(1004,"参数supplierNo不能为空");
  149. }
  150. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size']):"";
  151. if($good_size==''){
  152. return error_show(1004,"参数good_size不能为空");
  153. }
  154. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  155. :"";
  156. if($company_id==''){
  157. return error_show(1004,"参数company_id不能为空");
  158. }
  159. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  160. if($is_auth===''){
  161. return error_show(1004,"参数is_auth不能为空");
  162. }
  163. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  164. // if($auth_img==''){
  165. // return error_show(1004,"商品不能为空");
  166. // }
  167. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  168. if($after_sales==""){
  169. return error_show(1004,"参数after_sales不能为空");
  170. }
  171. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  172. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  173. if($good_remark===""){
  174. return error_show(1004,"参数good_remark不能为空");
  175. }
  176. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  177. if($weight===""){
  178. return error_show(1004,"参数weight不能为空");
  179. }
  180. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  181. if($packing_way===""){
  182. return error_show(1004,"参数packing_way不能为空");
  183. }
  184. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  185. if($packing_size===""){
  186. return error_show(1004,"参数packing_size不能为空");
  187. }
  188. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  189. if($packing_spec===""){
  190. return error_show(1004,"参数packing_spec不能为空");
  191. }
  192. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  193. if($packing_weight===""){
  194. return error_show(1004,"参数packing_weight不能为空");
  195. }
  196. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  197. if($packing_list===""){
  198. return error_show(1004,"参数packing_list不能为空");
  199. }
  200. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  201. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  202. if($supply_area===""){
  203. return error_show(1004,"参数supply_area不能为空");
  204. }
  205. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  206. if($delivery_place===""){
  207. return error_show(1004,"参数delivery_place不能为空");
  208. }
  209. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  210. if($origin_place===""){
  211. return error_show(1004,"参数origin_place不能为空");
  212. }
  213. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  214. if($delivery_day===""){
  215. return error_show(1004,"参数delivery_day不能为空");
  216. }
  217. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  218. :"0";
  219. $cgd_gold_price =isset($ths->post['cgd_gold_price'])&&$ths->post['cgd_gold_price']!==""?floatval($ths->post['cgd_gold_price']):"0";
  220. // if($lead_time===""){
  221. // return error_show(1004,"参数lead_time不能为空");
  222. // }
  223. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  224. // if($sample_day===""){
  225. // return error_show(1004,"参数sample_day不能为空");
  226. // }
  227. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  228. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  229. if($is_stock===""){
  230. return error_show(1004,"参数is_stock不能为空");
  231. }
  232. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"0";
  233. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  234. $config = isset($this->post['config'])&&$this->post['config']!==""? trim($this->post['config']):"";
  235. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!==""? trim($this->post['other_config']):"";
  236. if($good_img===""){
  237. return error_show(1004,"参数good_img不能为空");
  238. }
  239. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  240. if($good_thumb_img===""){
  241. return error_show(1004,"参数good_thumb_img不能为空");
  242. }
  243. $good_info_img = isset($this->post['good_info_img'])&&$this->post['good_info_img']!=""? trim($this->post['good_info_img']):"";
  244. if($good_info_img===""){
  245. return error_show(1004,"参数good_info_img不能为空");
  246. }
  247. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  248. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  249. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  250. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  251. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  252. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  253. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  254. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  255. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  256. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  257. if($market_price===""){
  258. return error_show(1004,"参数market_price不能为空");
  259. }
  260. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  261. if($nake_price===""){
  262. return error_show(1004,"参数nake_price不能为空");
  263. }
  264. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  265. if($is_step===""){
  266. return error_show(1004,"参数is_step不能为空");
  267. }
  268. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  269. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  270. if($is_step==1 && $good_ladder==""){
  271. return error_show(1004,"启用阶梯,阶梯价不能为空");
  272. }
  273. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  274. if($token==''){
  275. return error_show(105,"参数token不能为空");
  276. }
  277. $user =GetUserInfo($token);
  278. if(empty($user)||$user['code']!=0){
  279. return error_show(1002,"创建人数据不存在");
  280. }
  281. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  282. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  283. $spucode=makeNo("SPU");
  284. Db::startTrans();
  285. try {
  286. $data=[
  287. "spuCode"=>$spucode,
  288. "good_code"=>'',
  289. "good_name"=>$good_name,
  290. "cat_id"=>$cat_id,
  291. 'brand_id'=>$brandid,
  292. "good_unit"=>$unit,
  293. "good_type"=>$good_type,
  294. "moq"=>$moq,
  295. "is_exclusive"=>$is_exclusive,
  296. "customized"=>$customized,
  297. "companyNo"=>$company_id,
  298. "tax"=>$tax,
  299. "supplierNo"=>$supplierNo,
  300. "good_size"=>$good_size,
  301. "is_auth"=>$is_auth,
  302. "is_stock"=>$is_stock,
  303. "auth_img"=>$auth_img,
  304. "after_sales"=>$after_sales,
  305. "craft_desc"=>$craft_desc,
  306. "good_remark"=>$good_remark,
  307. "weight"=>$weight,
  308. "packing_way"=>$packing_way,
  309. "packing_size"=>$packing_size,
  310. "packing_spec"=>$packing_spec,
  311. "packing_list"=>$packing_list,
  312. "packing_weight"=>$packing_weight,
  313. "good_bar"=>$good_bar,
  314. "supply_area"=>$supply_area,
  315. "delivery_place"=>$delivery_place,
  316. "origin_place"=>$origin_place,
  317. "delivery_day"=>$delivery_day,
  318. "lead_time"=>$lead_time,
  319. "sample_day"=>$sample_day,
  320. "sample_fee"=>$sample_fee,
  321. "good_img"=>$good_img,
  322. "good_thumb_img"=>$good_thumb_img,
  323. "good_info_img"=>$good_info_img,
  324. "cert_fee"=>$cert_fee,
  325. "packing_fee"=>$packing_fee,
  326. "cost_fee"=>$cost_fee,
  327. "mark_fee"=>$mark_fee,
  328. "demo_fee"=>$demo_fee,
  329. "open_fee"=>$open_fee,
  330. "noble_metal"=>$noble_metal,
  331. "cgd_gold_price"=>$cgd_gold_price,
  332. "noble_weight"=>$noble_weight,
  333. "is_gold_price"=>$is_gold_price,
  334. "market_price"=>$market_price,
  335. "nake_price"=>$nake_price,
  336. "is_diff"=>$is_diff,
  337. "config"=>$config,
  338. "other_config"=>$other_config,
  339. "is_step"=>$is_step,
  340. "is_online"=>0,
  341. "status"=>0,
  342. "createrid"=>$createrid,
  343. "creater"=>$creater,
  344. "addtime"=>date("Y-m-d H:i:s"),
  345. "updatetime"=>date("Y-m-d H:i:s")
  346. ];
  347. $in = Db::name("good_basic")->insert($data);
  348. if($in){
  349. if($speclist!=="" && !empty($speclist)){
  350. $temp=[];
  351. foreach ($speclist as $value){
  352. $lemp=[];
  353. $lemp['spuCode']=$spucode;
  354. $lemp['spec_id'] = $value['spec_id'];
  355. $lemp['spec_value_id'] = $value['spec_value_id'];
  356. $lemp['addtime'] = date("Y-m-d H:i:s");
  357. $lemp['updatetime'] =date("Y-m-d H:i:s");
  358. $temp[]=$lemp;
  359. }
  360. $count = Db::name("good_spec")->insertAll($temp);
  361. if($count==0){
  362. Db::rollback();
  363. return app_show(1004,"商品规格值创建失败");
  364. }
  365. }
  366. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  367. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  368. if($good_ladder!=="" && !empty($good_ladder)){
  369. $temp=[];
  370. foreach ($good_ladder as $value){
  371. $lemp=[];
  372. $lemp['spuCode']=$spucode;
  373. $lemp['min_num'] = $value['min_num'];
  374. $lemp['nake_fee'] = $value['nake_fee'];
  375. $lemp['cost_fee'] = $value['cost_fee'];
  376. $lemp['delivery_fee'] = $value['delivery_fee'];
  377. $lemp['cert_fee'] = $value['cert_fee'];
  378. $lemp['mark_fee'] = $value['mark_fee'];
  379. $lemp['package_fee'] = $value['package_fee'];
  380. $lemp['other_fee'] = $value['other_fee'];
  381. if($is_gold_price==1){
  382. $lemp['nake_total'] =$noble_weight*$cgd_gold_price + $value['cost_fee']*
  383. $noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  384. }else{
  385. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  386. }
  387. $lemp['is_del'] = 0;
  388. $lemp['addtime'] = date("Y-m-d H:i:s");
  389. $lemp['updatetime'] =date("Y-m-d H:i:s");
  390. $temp[]=$lemp;
  391. }
  392. $count = Db::name("good_nake")->insertAll($temp);
  393. if($count==0){
  394. Db::rollback();
  395. return app_show(1004,"商品规格值创建失败");
  396. }
  397. }
  398. Db::commit();
  399. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  400. }else{
  401. Db::rollback();
  402. return app_show(1004,"商品创建失败");
  403. }
  404. }catch (\Exception $e){
  405. Db::rollback();
  406. return app_show(1004,$e->getMessage());
  407. }
  408. }
  409. public function editinfo(){
  410. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  411. if($supcode==""){
  412. return error_show(1004,"参数spuCode不能为空");
  413. }
  414. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  415. if($data==false){
  416. return error_show(1004,"未找到商品数据");
  417. }
  418. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  419. if($good_name==""){
  420. return error_show(1004,"商品名称不能为空");
  421. }
  422. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  423. if($cat_id==''){
  424. return error_show(1004,"商品分类不能为空");
  425. }
  426. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  427. // if($brandid==''){
  428. // return error_show(1004,"商品品牌不能为空");
  429. // }
  430. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  431. if($unit==''){
  432. return error_show(1004,"商品单位不能为空");
  433. }
  434. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  435. :"";
  436. if($good_type===''){
  437. return error_show(1004,"参数good_type不能为空");
  438. }
  439. $moq=0;
  440. $customized=0;
  441. if($good_type==1){
  442. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  443. if($moq===''){
  444. return error_show(1004,"定制商品起订量不能为空");
  445. }
  446. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  447. if($customized===''){
  448. return error_show(1004,"参数customized不能为空");
  449. }
  450. }
  451. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  452. if($is_exclusive===''){
  453. return error_show(1004,"参数is_exclusive不能为空");
  454. }
  455. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  456. // if($customized===''){
  457. // return error_show(1004,"参数customized不能为空");
  458. // }
  459. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  460. if($tax===''){
  461. return error_show(1004,"参数tax不能为空");
  462. }
  463. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  464. if($supplierNo==''){
  465. return error_show(1004,"参数supplierNo不能为空");
  466. }
  467. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  468. :"";
  469. if($good_size==''){
  470. return error_show(1004,"参数good_size不能为空");
  471. }
  472. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  473. :"";
  474. if($company_id==''){
  475. return error_show(1004,"参数company_id不能为空");
  476. }
  477. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  478. if($is_auth===''){
  479. return error_show(1004,"参数is_auth不能为空");
  480. }
  481. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  482. // if($auth_img==''){
  483. // return error_show(1004,"商品不能为空");
  484. // }
  485. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  486. if($after_sales==""){
  487. return error_show(1004,"参数after_sales不能为空");
  488. }
  489. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  490. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  491. if($good_remark===""){
  492. return error_show(1004,"参数good_remark不能为空");
  493. }
  494. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  495. if($weight===""){
  496. return error_show(1004,"参数weight不能为空");
  497. }
  498. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  499. if($packing_way===""){
  500. return error_show(1004,"参数packing_way不能为空");
  501. }
  502. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  503. if($packing_size===""){
  504. return error_show(1004,"参数packing_size不能为空");
  505. }
  506. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  507. if($packing_spec===""){
  508. return error_show(1004,"参数packing_spec不能为空");
  509. }
  510. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  511. if($packing_weight===""){
  512. return error_show(1004,"参数packing_weight不能为空");
  513. }
  514. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  515. if($packing_list===""){
  516. return error_show(1004,"参数packing_list不能为空");
  517. }
  518. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  519. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  520. if($supply_area===""){
  521. return error_show(1004,"参数supply_area不能为空");
  522. }
  523. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  524. if($delivery_place===""){
  525. return error_show(1004,"参数delivery_place不能为空");
  526. }
  527. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  528. if($origin_place===""){
  529. return error_show(1004,"参数origin_place不能为空");
  530. }
  531. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  532. if($delivery_day===""){
  533. return error_show(1004,"参数delivery_day不能为空");
  534. }
  535. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  536. :"0";
  537. // if($lead_time===""){
  538. // return error_show(1004,"参数lead_time不能为空");
  539. // }
  540. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  541. // if($sample_day===""){
  542. // return error_show(1004,"参数sample_day不能为空");
  543. // }
  544. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  545. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  546. if($good_img===""){
  547. return error_show(1004,"参数good_img不能为空");
  548. }
  549. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  550. if($good_thumb_img===""){
  551. return error_show(1004,"参数good_thumb_img不能为空");
  552. }
  553. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  554. if($good_info_img===""){
  555. return error_show(1004,"参数good_info_img不能为空");
  556. }
  557. $count = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->count();
  558. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  559. Db::startTrans();
  560. try {
  561. $temp=[
  562. "good_name"=>$good_name,
  563. "cat_id"=>$cat_id,
  564. 'brand_id'=>$brandid,
  565. "good_unit"=>$unit,
  566. "good_type"=>$good_type,
  567. "companyNo"=>$company_id,
  568. "moq"=>$moq,
  569. "is_exclusive"=>$is_exclusive,
  570. "customized"=>$customized,
  571. "tax"=>$tax,
  572. "supplierNo"=>$supplierNo,
  573. "is_auth"=>$is_auth,
  574. "good_size"=>$good_size,
  575. "auth_img"=>$auth_img,
  576. "after_sales"=>$after_sales,
  577. "craft_desc"=>$craft_desc,
  578. "good_remark"=>$good_remark,
  579. "weight"=>$weight,
  580. "packing_way"=>$packing_way,
  581. "packing_size"=>$packing_size,
  582. "packing_spec"=>$packing_spec,
  583. "packing_list"=>$packing_list,
  584. "packing_weight"=>$packing_weight,
  585. "good_bar"=>$good_bar,
  586. "supply_area"=>$supply_area,
  587. "delivery_place"=>$delivery_place,
  588. "origin_place"=>$origin_place,
  589. "delivery_day"=>$delivery_day,
  590. "lead_time"=>$lead_time,
  591. "sample_day"=>$sample_day,
  592. "sample_fee"=>$sample_fee,
  593. "good_img"=>$good_img,
  594. "good_thumb_img"=>$good_thumb_img,
  595. "good_info_img"=>$good_info_img,
  596. "status"=>$count>0?2:1,
  597. "updatetime"=>date("Y-m-d H:i:s")
  598. ];
  599. $field = array_diff_assoc($temp,$data);
  600. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  601. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  602. $timp = array_diff($temp,$data);
  603. $json = json_encode($timp,JSON_UNESCAPED_UNICODE);
  604. $jsp = json_encode($data,JSON_UNESCAPED_UNICODE);
  605. if($up){
  606. ChangeLog::logAdd(3,$data['spuCode'],$jsp,$json,$this->post['token'],$this->post);
  607. if($speclist!=="" && !empty($speclist)){
  608. foreach ($speclist as $value){
  609. $lemp=[];
  610. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  611. $lemp['spuCode']=$supcode;
  612. $lemp['spec_id'] = $value['spec_id'];
  613. $lemp['spec_value_id'] = $value['spec_value_id'];
  614. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  615. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  616. $lemp['updatetime'] =date("Y-m-d H:i:s");
  617. $count = Db::name("good_spec")->save($lemp);
  618. if($count==false){
  619. Db::rollback();
  620. return app_show(1004,"商品规格值修改失败");
  621. }
  622. }
  623. }
  624. Db::commit();
  625. return app_show(0,"更新成功");
  626. }else{
  627. Db::rollback();
  628. return error_show(1005,"更新失败");
  629. }
  630. }catch (\Exception $e){
  631. Db::rollback();
  632. return error_show(1004,$e->getMessage());
  633. }
  634. }
  635. public function editfee(){
  636. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  637. if($supcode==""){
  638. return error_show(1004,"参数spuCode不能为空");
  639. }
  640. $datas = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  641. if($datas==false){
  642. return error_show(1004,"未找到商品数据");
  643. }
  644. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  645. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  646. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  647. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  648. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  649. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  650. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  651. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  652. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  653. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  654. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  655. if($market_price===""){
  656. return error_show(1004,"参数market_price不能为空");
  657. }
  658. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  659. if($nake_price===""){
  660. return error_show(1004,"参数nake_price不能为空");
  661. }
  662. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  663. if($is_step===""){
  664. return error_show(1004,"参数is_step不能为空");
  665. }
  666. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  667. if($is_step==1 && $good_ladder==""){
  668. return error_show(1004,"启用阶梯,阶梯价不能为空");
  669. }
  670. $data=[
  671. "cert_fee"=>$cert_fee,
  672. "packing_fee"=>$packing_fee,
  673. "cost_fee"=>$cost_fee,
  674. "mark_fee"=>$mark_fee,
  675. "demo_fee"=>$demo_fee,
  676. "open_fee"=>$open_fee,
  677. "noble_metal"=>$noble_metal,
  678. "noble_weight"=>$noble_weight,
  679. "is_gold_price"=>$is_gold_price,
  680. "market_price"=>$market_price,
  681. "nake_price"=>$nake_price,
  682. "cgd_gold_price"=>$cgd_gold_price,
  683. "is_step"=>$is_step,
  684. "status"=>"2",
  685. "updatetime"=>date("Y-m-d H:i:s")
  686. ];
  687. $field = array_diff_assoc($data,$datas);
  688. $data['field_change'] =empty($field)?"":json_encode(array_keys($field));
  689. Db::startTrans();
  690. try{
  691. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  692. $temp = array_diff($data,$datas);
  693. $json = json_encode($temp,JSON_UNESCAPED_UNICODE);
  694. $jsp = json_encode($datas,JSON_UNESCAPED_UNICODE);
  695. if($up){
  696. ChangeLog::logAdd(3,$datas['spuCode'],$jsp,$json,$this->post['token'],$this->post);
  697. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_online"=>0,"status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
  698. if($good_ladder!=="" && !empty($good_ladder)){
  699. foreach ($good_ladder as $value){
  700. $lemp=[];
  701. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  702. $lemp['spuCode']=$supcode;
  703. $lemp['min_num'] = $value['min_num'];
  704. $lemp['nake_fee'] = $value['nake_fee'];
  705. $lemp['cost_fee'] = $value['cost_fee'];
  706. $lemp['delivery_fee'] = $value['delivery_fee'];
  707. $lemp['cert_fee'] = $value['cert_fee'];
  708. $lemp['mark_fee'] = $value['mark_fee'];
  709. $lemp['package_fee'] = $value['package_fee'];
  710. $lemp['other_fee'] = $value['other_fee'];
  711. if($is_gold_price==1){
  712. $lemp['nake_total'] =$noble_weight*$cgd_gold_price + $value['cost_fee']*
  713. $noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  714. }else{
  715. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  716. }
  717. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  718. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  719. $lemp['updatetime'] =date("Y-m-d H:i:s");
  720. $count = Db::name("good_nake")->save($lemp);
  721. if($count==false){
  722. Db::rollback();
  723. return app_show(1004,"商品规成本修改失败");
  724. }
  725. }
  726. }
  727. Db::commit();
  728. return app_show(0,"更新成功");
  729. }else{
  730. Db::rollback();
  731. return error_show(1005,"更新失败");
  732. }
  733. }catch (\Exception $e){
  734. Db::rollback();
  735. return error_show(1005,$e->getMessage());
  736. }
  737. }
  738. public function exam(){
  739. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  740. if($supcode==""){
  741. return error_show(1004,"参数spuCode不能为空");
  742. }
  743. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  744. if($data==false){
  745. return error_show(1004,"未找到商品数据");
  746. }
  747. if($data['status']==1){
  748. return error_show(1004,"商品已审核通过");
  749. }
  750. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  751. // if($status===""){
  752. // return error_show(1004,"参数status不能为空");
  753. // }
  754. $remark = isset($this->post['remark'])&&$this->post['remark']!=="" ? trim($this->post['remark']):"";
  755. // if($remark===""){
  756. // return error_show(1004,"参数remark不能为空");
  757. // }
  758. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  759. if($token==''){
  760. return error_show(105,"参数token不能为空");
  761. }
  762. $user =GetUserInfo($token);
  763. if(empty($user)||$user['code']!=0){
  764. return error_show(1002,"用户数据不存在");
  765. }
  766. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  767. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  768. Db::startTrans();
  769. try {
  770. if($data['status']==3 && $status==1){
  771. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_online"=>0,"status"=>0, "is_del"=>0])->save(["is_online"=>0,"exam_status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  772. }
  773. $data['status']=$status;
  774. $data['updatetime']=date("Y-m-d H:i:s");
  775. $up= Db::name("good_basic")->save($data);
  776. if($up){
  777. $data=[
  778. "code"=>$supcode,
  779. "exam_status"=>$status,
  780. "type"=>1,
  781. "exam_id"=>$createrid,
  782. "exam_name"=>$creater,
  783. "exam_remark"=>$remark,
  784. "addtime"=>date("Y-m-d H:i:s")
  785. ];
  786. $inr=Db::name("good_exam")->insert($data);
  787. if($inr){
  788. Db::commit();
  789. return app_show(0,"审核成功");
  790. }else{
  791. Db::rollback();
  792. return error_show(1004,"审核失败");
  793. }
  794. }else{
  795. Db::rollback();
  796. return error_show(1004,"审核失败");
  797. }
  798. }catch (\Exception $e){
  799. Db::rollback();
  800. return error_show(1004,$e->getMessage());
  801. }
  802. }
  803. public function info(){
  804. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  805. if($supcode==""){
  806. return error_show(1004,"参数spuCode不能为空");
  807. }
  808. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  809. if($data==false){
  810. return error_show(1004,"未找到商品数据");
  811. }
  812. $unit =Db::name("unit")->where(["id"=>$data['good_unit']])->find();
  813. $data['unit'] = isset($unit['unit'])?$unit['unit']:'';
  814. $data['cat_info'] = made($data['cat_id'],[]);
  815. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  816. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  817. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  818. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  819. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  820. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  821. $data['company'] = isset($company['company'])?$company['company']:"";
  822. $data['field_change'] = $data['field_change']!=''?json_decode($data['field_change']):"";
  823. if($data['brand_id']!=0){
  824. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  825. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  826. }else{
  827. $data["brand_name"]="";
  828. $data["brand_id"]="";
  829. }
  830. $excluse = makeExcluse($data['is_exclusive']);
  831. $data['exclusive']=$excluse;
  832. $data['noble_name']=isset($data['noble_metal'])&&$data['noble_metal']!=0?$this->noble[$data['noble_metal']] :"";
  833. $data["good_info_img"]=$data['good_info_img']!=""? $data['good_info_img']:[];
  834. $data["good_img"]=$data['good_img']!=""? $data['good_img']:[];
  835. $speclist=[];
  836. if(!empty($spec)){
  837. foreach ($spec as $value){
  838. $temp=[];
  839. $temp['id']=$value['id'];
  840. $temp['spuCode']=$value['spuCode'];
  841. $temp['spec_id']=$value['spec_id'];
  842. $temp['spec_value_id']=$value['spec_value_id'];
  843. $temp['is_del']=$value['is_del'];
  844. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  845. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  846. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  847. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  848. $speclist[]=$temp;
  849. }
  850. }
  851. $data["speclist"]=empty($speclist)?[]:$speclist;
  852. // $nake=[];
  853. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  854. // $catinfo = Db::name("cat")->where(["id"=>$data['cat_id']])->find();
  855. // $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  856. $nakearry=[];
  857. if(!empty($nakelist)){
  858. foreach ($nakelist as $value) {
  859. $nakearry[] = $value;
  860. }
  861. }
  862. $data["nakelist"]=$nakearry;
  863. return app_show(0,"获取成功",$data);
  864. }
  865. public function delall(){
  866. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  867. if($supcode==""){
  868. return error_show(1004,"参数codes不能为空");
  869. }
  870. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  871. if(empty($data)){
  872. return error_show(1004,"未找到商品数据");
  873. }
  874. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  875. if($up){
  876. return app_show(0,"更新成功");
  877. }else{
  878. return error_show(1005,"更新失败");
  879. }
  880. }
  881. public function online(){
  882. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  883. if($platform==""){
  884. return error_show(1004,"参数codes不能为空");
  885. }
  886. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  887. if($spuCode===''){
  888. return error_show(1004,"参数codes不能为空");
  889. }
  890. $datas = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->select()->toArray();
  891. if(empty($datas)){
  892. return error_show(1004,"未找到商品数据");
  893. }
  894. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  895. if($online_reason===""){
  896. return error_show(1004,"参数online_reason不能为空");
  897. }
  898. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  899. if($online_remark===""){
  900. return error_show(1004,"参数online_remark不能为空");
  901. }
  902. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  903. if($token==''){
  904. return error_show(105,"参数token不能为空");
  905. }
  906. $user =GetUserInfo($token);
  907. if(empty($user)||$user['code']!=0){
  908. return error_show(1002,"用户数据不存在");
  909. }
  910. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  911. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  912. $data=[];
  913. $isonline=[];
  914. foreach ($spuCode as $value){
  915. $count = Db::name("good_nake")->where(["spuCode"=>$value,"is_del"=>0])->count();
  916. $ist =Db::name("good_platform")->where(["spuCode"=>$value,"platform_code"=>$platform,"is_del"=>0])->find();
  917. if($ist){
  918. $god=Db::name("good_basic")->where(["spuCode"=>$value,"is_del"=>0])->find();
  919. if($god){
  920. $tp=[];
  921. $tp['spuCode']=$value;
  922. $tp['good_name']=$god['good_name'];
  923. $tp['good_img']=$god['good_thumb_img'];
  924. $tp['exam_status']=$ist['exam_status'];
  925. $spec = Db::name("good_spec")->where(["spuCode"=>$value,"is_del"=>0])->select()->toArray();
  926. $speclist=[];
  927. if(!empty($spec)){
  928. foreach ($spec as $val){
  929. $temp=[];
  930. $temp['id']=$val['id'];
  931. $temp['spuCode']=$val['spuCode'];
  932. $temp['spec_id']=$val['spec_id'];
  933. $temp['spec_value_id']=$val['spec_value_id'];
  934. $temp['is_del']=$val['is_del'];
  935. $sp = Db::name("specs")->where(["id"=>$val['spec_id']])->find();
  936. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  937. $spv = Db::name("spec_value")->where(["id"=>$val['spec_value_id']])->find();
  938. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  939. $speclist[]=$temp;
  940. }
  941. }
  942. $tp["speclist"]=empty($speclist)?[]:$speclist;
  943. $isonline[]=$tp;
  944. }
  945. }
  946. $data[]=[
  947. "spuCode"=>$value,
  948. "skuCode"=>makeNo("SKU"),
  949. "platform_code"=>$platform,
  950. "online_reason"=>$online_reason,
  951. "online_remark"=>$online_remark,
  952. "exam_status"=>$count>0 ?2:1,
  953. "is_online"=>0,
  954. "status"=>1,
  955. "is_del"=>0,
  956. "creater"=>$creater,
  957. "createrid"=>$createrid,
  958. "addtime"=>date("Y-m-d H:i:s"),
  959. "updatetime"=>date("Y-m-d H:i:s")
  960. ];
  961. }
  962. if(!empty($isonline)){
  963. return app_show(1009,"存在已上线产品",$isonline);
  964. }
  965. Db::startTrans();
  966. $create =Db::name("good_platform")->insertAll($data);
  967. if($create){
  968. foreach ($datas as $value){
  969. $iso = Db::name("good")->where(["spuCode"=>$value['spuCode'],"is_del"=>0])->find();
  970. if($iso==false){
  971. unset($value['id']);
  972. $value['creater']=$creater;
  973. $value['createrid']=$createrid;
  974. $value['addtime']=date("Y-m-d H:i:s");
  975. $value['updatetime']=date("Y-m-d H:i:s");
  976. }else{
  977. $value['id']=$iso['id'];
  978. $value['creater']=$creater;
  979. $value['createrid']=$createrid;
  980. $value['updatetime']=date("Y-m-d H:i:s");
  981. }
  982. $up =Db::name("good")->save($value);
  983. if(!$up){
  984. Db::rollback();
  985. return error_show(1004,"提交失败");
  986. }
  987. }
  988. Db::commit();
  989. return app_show(0,"提交成功");
  990. }else{
  991. Db::rollback();
  992. return error_show(1004,"提交失败");
  993. }
  994. }
  995. public function online_exam(){
  996. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  997. if($skuCode===""){
  998. return error_show(1004,"参数skuCode不能为空");
  999. }
  1000. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1001. if($platform==false){
  1002. return error_show(1004,"未找到数据");
  1003. }
  1004. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  1005. // if($exam_status===""){
  1006. // return error_show(1004,"参数exam_status不能为空");
  1007. // }
  1008. if($exam_status==3){
  1009. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  1010. if($online_time===""){
  1011. return error_show(1004,"参数online_time不能为空");
  1012. }
  1013. $platform['online_time']=$online_time;
  1014. }
  1015. if($exam_status==6){
  1016. $good_code= isset($this->post['plat_code'])&&$this->post['plat_code']!==""?trim($this->post['plat_code']):"";
  1017. if($good_code===""){
  1018. return error_show(1004,"参数plat_code不能为空");
  1019. }
  1020. $platform['plat_code']=$good_code;
  1021. }
  1022. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  1023. $platform['exam_status']=$exam_status;
  1024. $platform['updatetime']=date("Y-m-d H:i:s");
  1025. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1026. if($token==''){
  1027. return error_show(105,"参数token不能为空");
  1028. }
  1029. $user =GetUserInfo($token);
  1030. if(empty($user)||$user['code']!=0){
  1031. return error_show(1002,"用户数据不存在");
  1032. }
  1033. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1034. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1035. Db::startTrans();
  1036. try {
  1037. $up = Db::name("good_platform")->save($platform);
  1038. if($up){
  1039. $data=[
  1040. "code"=>$platform['skuCode'],
  1041. "exam_status"=>$exam_status,
  1042. "type"=>2,
  1043. "exam_id"=>$createrid,
  1044. "exam_name"=>$creater,
  1045. "exam_remark"=>$exam_remark,
  1046. "addtime"=>date("Y-m-d H:i:s")
  1047. ];
  1048. $inr=Db::name("good_exam")->insert($data);
  1049. if($inr){
  1050. Db::commit();
  1051. return app_show(0,"审核成功");
  1052. }else{
  1053. Db::rollback();
  1054. return error_show(1004,"审核失败");
  1055. }
  1056. }else{
  1057. Db::rollback();
  1058. return error_show(1004,"审核失败");
  1059. }
  1060. }catch (\Exception $e){
  1061. Db::rollback();
  1062. return error_show(1004,$e->getMessage());
  1063. }
  1064. }
  1065. public function editladder(){
  1066. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1067. if($skuCode===""){
  1068. return error_show(1004,"参数skuCode不能为空");
  1069. }
  1070. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1071. if($platform==false){
  1072. return error_show(1004,"未找到数据");
  1073. }
  1074. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  1075. if($good_ladder==""){
  1076. return error_show(1004,"参数good_ladder不能为空");
  1077. }
  1078. $proof_type = isset($this->post['proof_type'])&&$this->post['proof_type']!==""?intval($this->post['proof_type']):"";
  1079. if($proof_type===""){
  1080. return error_show(1004,"参数proof_type不能为空");
  1081. }
  1082. $proof_url = isset($this->post['proof_url'])&&$this->post['proof_url']!==""?trim($this->post['proof_url']):"";
  1083. if($proof_url===""){
  1084. return error_show(1004,"参数proof_url不能为空");
  1085. }
  1086. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1087. if($token==''){
  1088. return error_show(105,"参数token不能为空");
  1089. }
  1090. $user =GetUserInfo($token);
  1091. if(empty($user)||$user['code']!=0){
  1092. return error_show(1002,"用户数据不存在");
  1093. }
  1094. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1095. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1096. $platform['exam_status']=4;
  1097. $platform['updatetime']=date("Y-m-d H:i:s");
  1098. Db::startTrans();
  1099. try {
  1100. foreach ($good_ladder as $value){
  1101. $lemp=[];
  1102. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  1103. $lemp['skuCode']=$skuCode;
  1104. $lemp['min_num'] = $value['min_num'];
  1105. $lemp['max_num'] = 0;
  1106. $lemp['sale_price'] = $value['sale_price'];
  1107. $lemp['market_price'] = $value['market_price'];
  1108. $lemp['market_platform'] = $value['market_platform'];
  1109. $lemp['status'] = $value['status'];
  1110. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1111. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1112. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1113. $count = Db::name("good_ladder")->save($lemp);
  1114. if($count==false){
  1115. Db::rollback();
  1116. return app_show(1004,"商品起订价修改失败");
  1117. }
  1118. }
  1119. $up = Db::name("good_platform")->save($platform);
  1120. if($up){
  1121. $proof=[
  1122. 'spuCode'=>$platform['spuCode'],
  1123. 'proof_type'=>$proof_type,
  1124. 'proof_url'=>$proof_url,
  1125. 'is_del'=>0,
  1126. "creater"=>$creater,
  1127. "createrid"=>$createrid,
  1128. "addtime"=>date("Y-m-d H:i:s"),
  1129. "updatetime"=>date("Y-m-d H:i:s")
  1130. ];
  1131. $inproof = Db::name("good_proof")->insert($proof);
  1132. if($inproof==false){
  1133. Db::rollback();
  1134. return app_show(1004,"商品凭证新建失败");
  1135. }
  1136. $data=[
  1137. "code"=>$platform['skuCode'],
  1138. "type"=>2,
  1139. "exam_status"=>4,
  1140. "exam_id"=>$createrid,
  1141. "exam_name"=>$creater,
  1142. "exam_remark"=>'',
  1143. "addtime"=>date("Y-m-d H:i:s")
  1144. ];
  1145. $inr=Db::name("good_exam")->insert($data);
  1146. if($inr){
  1147. Db::commit();
  1148. return app_show(0,"审核成功");
  1149. }else{
  1150. Db::rollback();
  1151. return error_show(1004,"审核失败");
  1152. }
  1153. }else{
  1154. Db::rollback();
  1155. return error_show(1004,"审核失败");
  1156. }
  1157. }catch (\Exception $e){
  1158. Db::rollback();
  1159. return error_show(1004,$e->getMessage());
  1160. }
  1161. }
  1162. public function prooflist(){
  1163. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  1164. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  1165. $where =[["is_del","=",0]];
  1166. $spuCode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1167. if($spuCode!==""){
  1168. $where[]=["spuCode","like","%$spuCode%"];
  1169. }
  1170. $count = Db::name("good_proof")->where($where)->count();
  1171. $total = ceil($count / $size);
  1172. $page = $page >= $total ? $total : $page;
  1173. $data = Db::name("good_proof")->where($where)->page($page,$size)->order("addtime desc")->select();
  1174. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  1175. }
  1176. /**
  1177. *
  1178. */
  1179. public function againOnline(){
  1180. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  1181. if($skuCode===""){
  1182. return error_show(1004,"参数skuCode不能为空");
  1183. }
  1184. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  1185. if($platform==false){
  1186. return error_show(1004,"未找到数据");
  1187. }
  1188. if($platform["exam_status"]!=7&&$platform["exam_status"]!=8){
  1189. return error_show(1004,"商品状态有误");
  1190. }
  1191. $nake =Db::name("good_nake")->where(["spuCode"=>$platform['spuCode'],"is_del"=>0])->select()->toArray();
  1192. $platform['exam_status'] = empty($nake)?1:2;
  1193. $platform['updatetime'] = date("Y-m-d H:i:s");
  1194. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1195. if($token==''){
  1196. return error_show(105,"参数token不能为空");
  1197. }
  1198. $user =GetUserInfo($token);
  1199. if(empty($user)||$user['code']!=0){
  1200. return error_show(1002,"用户数据不存在");
  1201. }
  1202. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1203. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1204. Db::startTrans();
  1205. try {
  1206. $save =Db::name("good_platform")->save($platform);
  1207. if($save){
  1208. $data=[
  1209. "code"=>$platform['skuCode'],
  1210. "type"=>2,
  1211. "exam_status"=>$platform['exam_status'] ,
  1212. "exam_id"=>$createrid,
  1213. "exam_name"=>$creater,
  1214. "exam_remark"=>'',
  1215. "addtime"=>date("Y-m-d H:i:s")
  1216. ];
  1217. $inr=Db::name("good_exam")->insert($data);
  1218. if($inr){
  1219. Db::commit();
  1220. return app_show(0,"审核成功");
  1221. }
  1222. }
  1223. Db::rollback();
  1224. return error_show(1004,"审核失败");
  1225. }catch (\Exception $e){
  1226. Db::rollback();
  1227. return error_show(1004,$e->getMessage());
  1228. }
  1229. }
  1230. public function copy(){
  1231. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1232. if($supcode==""){
  1233. return error_show(1004,"参数spuCode不能为空");
  1234. }
  1235. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1236. if($data==false){
  1237. return error_show(1004,"未找到商品数据");
  1238. }
  1239. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1240. if($token==''){
  1241. return error_show(105,"参数token不能为空");
  1242. }
  1243. $user =GetUserInfo($token);
  1244. if(empty($user)||$user['code']!=0){
  1245. return error_show(102,"用户数据不存在");
  1246. }
  1247. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1248. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1249. $nake = Db::name("good_nake")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1250. $ladd=[];
  1251. $newCode =makeNo("SPU");
  1252. if(!empty($nake)){
  1253. foreach ($nake as $value){
  1254. $tmp=[];
  1255. $tmp['spuCode']=$newCode;
  1256. $tmp['min_num']=$value['min_num'];
  1257. $tmp['nake_fee'] = $value['nake_fee'];
  1258. $tmp['cost_fee'] = $value['cost_fee'];
  1259. $tmp['delivery_fee'] = $value['delivery_fee'];
  1260. $tmp['cert_fee'] = $value['cert_fee'];
  1261. $tmp['mark_fee'] = $value['mark_fee'];
  1262. $tmp['package_fee'] = $value['package_fee'];
  1263. $tmp['other_fee'] = $value['other_fee'];
  1264. $tmp['nake_total'] =$value['nake_total'];
  1265. $tmp['is_del']=$value['is_del'];
  1266. $tmp['addtime']=date("Y-m-d H:i:s");
  1267. $tmp['updatetime']=date("Y-m-d H:i:s");
  1268. $ladd[]=$tmp;
  1269. }
  1270. }
  1271. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  1272. $specArr=[];
  1273. if(!empty($spec)){
  1274. foreach ($spec as $value){
  1275. $tmp=[];
  1276. $tmp['spuCode']=$newCode;
  1277. $tmp['spec_id']=$value['spec_id'];
  1278. $tmp['spec_value_id']=$value['spec_value_id'];
  1279. $tmp['is_del']=$value['is_del'];
  1280. $tmp['addtime']=date("Y-m-d H:i:s");
  1281. $tmp['updatetime']=date("Y-m-d H:i:s");
  1282. $specArr[]=$tmp;
  1283. }
  1284. }
  1285. Db::startTrans();
  1286. try {
  1287. unset($data['id']);
  1288. $data['spuCode']=$newCode;
  1289. $data['createrid']=$createrid;
  1290. $data['creater']=$creater;
  1291. $data['status']=7;
  1292. $data['addtime']=date("Y-m-d H:i:s");
  1293. $data['updatetime']=date("Y-m-d H:i:s");
  1294. $cre = Db::name("good_basic")->insert($data);
  1295. if($cre){
  1296. if(!empty($ladd)){
  1297. $na = Db::name("good_nake")->insertAll($ladd);
  1298. if($na==0){
  1299. Db::rollback();
  1300. return error_show(1005,"成本数据复制失败");
  1301. }
  1302. }
  1303. if(!empty($specArr)){
  1304. $sp = Db::name("good_spec")->insertAll($specArr);
  1305. if($sp==0){
  1306. Db::rollback();
  1307. return error_show(1005,"规格数据复制失败");
  1308. }
  1309. }
  1310. Db::commit();
  1311. return app_show(0,"复制数据成功",["spuCode"=>$newCode]);
  1312. }else{
  1313. Db::rollback();
  1314. return error_show(1005,"数据复制失败");
  1315. }
  1316. }catch (\Exception $e){
  1317. Db::rollback();
  1318. return error_show(1004,$e->getMessage());
  1319. }
  1320. }
  1321. public function edit(){
  1322. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  1323. if($supcode==""){
  1324. return error_show(1004,"参数spuCode不能为空");
  1325. }
  1326. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  1327. if($data==false){
  1328. return error_show(1004,"未找到商品数据");
  1329. }
  1330. if($data['status']!=6 &&$data['status']!=7 ){
  1331. return error_show(1004,"商品状态有误");
  1332. }
  1333. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  1334. if($good_name==""){
  1335. return error_show(1004,"商品名称不能为空");
  1336. }
  1337. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  1338. if($cat_id==''){
  1339. return error_show(1004,"商品分类不能为空");
  1340. }
  1341. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  1342. // if($brandid==''){
  1343. // return error_show(1004,"商品品牌不能为空");
  1344. // }
  1345. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  1346. if($unit==''){
  1347. return error_show(1004,"商品单位不能为空");
  1348. }
  1349. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  1350. :"";
  1351. if($good_type===''){
  1352. return error_show(1004,"参数good_type不能为空");
  1353. }
  1354. $moq=0;
  1355. $customized=0;
  1356. if($good_type==1){
  1357. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  1358. if($moq===''){
  1359. return error_show(1004,"定制商品起订量不能为空");
  1360. }
  1361. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1362. if($customized===''){
  1363. return error_show(1004,"参数customized不能为空");
  1364. }
  1365. }
  1366. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  1367. if($is_exclusive===''){
  1368. return error_show(1004,"参数is_exclusive不能为空");
  1369. }
  1370. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  1371. // if($customized===''){
  1372. // return error_show(1004,"参数customized不能为空");
  1373. // }
  1374. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  1375. if($tax===''){
  1376. return error_show(1004,"参数tax不能为空");
  1377. }
  1378. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  1379. if($supplierNo==''){
  1380. return error_show(1004,"参数supplierNo不能为空");
  1381. }
  1382. $good_size = isset($this->post['good_size'])&&$this->post['good_size']!=""? trim($this->post['good_size'])
  1383. :"";
  1384. if($good_size==''){
  1385. return error_show(1004,"参数good_size不能为空");
  1386. }
  1387. $company_id = isset($this->post['companyNo'])&&$this->post['companyNo']!=""? trim($this->post['companyNo'])
  1388. :"";
  1389. if($company_id==''){
  1390. return error_show(1004,"参数companyNo不能为空");
  1391. }
  1392. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  1393. if($is_auth===''){
  1394. return error_show(1004,"参数is_auth不能为空");
  1395. }
  1396. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  1397. // if($auth_img==''){
  1398. // return error_show(1004,"商品不能为空");
  1399. // }
  1400. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  1401. if($after_sales==""){
  1402. return error_show(1004,"参数after_sales不能为空");
  1403. }
  1404. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  1405. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  1406. if($good_remark===""){
  1407. return error_show(1004,"参数good_remark不能为空");
  1408. }
  1409. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  1410. if($weight===""){
  1411. return error_show(1004,"参数weight不能为空");
  1412. }
  1413. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  1414. if($packing_way===""){
  1415. return error_show(1004,"参数packing_way不能为空");
  1416. }
  1417. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  1418. if($packing_size===""){
  1419. return error_show(1004,"参数packing_size不能为空");
  1420. }
  1421. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  1422. if($packing_spec===""){
  1423. return error_show(1004,"参数packing_spec不能为空");
  1424. }
  1425. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  1426. if($packing_weight===""){
  1427. return error_show(1004,"参数packing_weight不能为空");
  1428. }
  1429. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  1430. if($packing_list===""){
  1431. return error_show(1004,"参数packing_list不能为空");
  1432. }
  1433. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  1434. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1435. if($supply_area===""){
  1436. return error_show(1004,"参数supply_area不能为空");
  1437. }
  1438. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  1439. if($delivery_place===""){
  1440. return error_show(1004,"参数delivery_place不能为空");
  1441. }
  1442. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  1443. if($origin_place===""){
  1444. return error_show(1004,"参数origin_place不能为空");
  1445. }
  1446. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  1447. if($delivery_day===""){
  1448. return error_show(1004,"参数delivery_day不能为空");
  1449. }
  1450. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  1451. :"0";
  1452. // if($lead_time===""){
  1453. // return error_show(1004,"参数lead_time不能为空");
  1454. // }
  1455. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  1456. // if($sample_day===""){
  1457. // return error_show(1004,"参数sample_day不能为空");
  1458. // }
  1459. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  1460. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? trim($this->post['good_img']):"";
  1461. if($good_img===""){
  1462. return error_show(1004,"参数good_img不能为空");
  1463. }
  1464. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  1465. if($good_thumb_img===""){
  1466. return error_show(1004,"参数good_thumb_img不能为空");
  1467. }
  1468. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? trim($this->post['good_info_img']):"";
  1469. if($good_info_img===""){
  1470. return error_show(1004,"参数good_info_img不能为空");
  1471. }
  1472. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  1473. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  1474. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  1475. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  1476. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  1477. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  1478. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  1479. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  1480. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  1481. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  1482. $cgd_gold_price = isset($this->post['cgd_gold_price'])&&$this->post['cgd_gold_price']!==""? floatval($this->post['cgd_gold_price']):"0";
  1483. if($market_price===""){
  1484. return error_show(1004,"参数market_price不能为空");
  1485. }
  1486. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  1487. if($nake_price===""){
  1488. return error_show(1004,"参数nake_price不能为空");
  1489. }
  1490. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  1491. if($is_step===""){
  1492. return error_show(1004,"参数is_step不能为空");
  1493. }
  1494. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  1495. if($is_step==1 && $good_ladder==""){
  1496. return error_show(1004,"启用阶梯,阶梯价不能为空");
  1497. }
  1498. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  1499. Db::startTrans();
  1500. try {
  1501. $temp=[
  1502. "good_name"=>$good_name,
  1503. "cat_id"=>$cat_id,
  1504. 'brand_id'=>$brandid,
  1505. "good_unit"=>$unit,
  1506. "good_type"=>$good_type,
  1507. "companyNo"=>$company_id,
  1508. "moq"=>$moq,
  1509. "is_exclusive"=>$is_exclusive,
  1510. "customized"=>$customized,
  1511. "tax"=>$tax,
  1512. "supplierNo"=>$supplierNo,
  1513. "is_auth"=>$is_auth,
  1514. "good_size"=>$good_size,
  1515. "auth_img"=>$auth_img,
  1516. "after_sales"=>$after_sales,
  1517. "craft_desc"=>$craft_desc,
  1518. "good_remark"=>$good_remark,
  1519. "weight"=>$weight,
  1520. "packing_way"=>$packing_way,
  1521. "packing_size"=>$packing_size,
  1522. "packing_spec"=>$packing_spec,
  1523. "packing_list"=>$packing_list,
  1524. "packing_weight"=>$packing_weight,
  1525. "good_bar"=>$good_bar,
  1526. "supply_area"=>$supply_area,
  1527. "delivery_place"=>$delivery_place,
  1528. "origin_place"=>$origin_place,
  1529. "delivery_day"=>$delivery_day,
  1530. "lead_time"=>$lead_time,
  1531. "sample_day"=>$sample_day,
  1532. "sample_fee"=>$sample_fee,
  1533. "good_img"=>$good_img,
  1534. "good_thumb_img"=>$good_thumb_img,
  1535. "good_info_img"=>$good_info_img,
  1536. "cert_fee"=>$cert_fee,
  1537. "packing_fee"=>$packing_fee,
  1538. "cost_fee"=>$cost_fee,
  1539. "mark_fee"=>$mark_fee,
  1540. "demo_fee"=>$demo_fee,
  1541. "open_fee"=>$open_fee,
  1542. "noble_metal"=>$noble_metal,
  1543. "noble_weight"=>$noble_weight,
  1544. "is_gold_price"=>$is_gold_price,
  1545. "market_price"=>$market_price,
  1546. "nake_price"=>$nake_price,
  1547. "cgd_gold_price"=>$cgd_gold_price,
  1548. "is_step"=>$is_step,
  1549. "status"=>"0",
  1550. "updatetime"=>date("Y-m-d H:i:s")
  1551. ];
  1552. $field = array_diff_assoc($temp,$data);
  1553. $temp['field_change'] =empty($field)?"":json_encode(array_keys($field));
  1554. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  1555. $var = array_diff($temp,$data);
  1556. $json = json_encode($var,JSON_UNESCAPED_UNICODE);
  1557. $dat = json_encode($data,JSON_UNESCAPED_UNICODE);
  1558. if($up){
  1559. ChangeLog::logAdd(3,$data['spuCode'],$dat,$json,$this->post['token'],$this->post);
  1560. if($speclist!=="" && !empty($speclist)){
  1561. foreach ($speclist as $value){
  1562. $lemp=[];
  1563. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1564. $lemp['spuCode']=$supcode;
  1565. $lemp['spec_id'] = $value['spec_id'];
  1566. $lemp['spec_value_id'] = $value['spec_value_id'];
  1567. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1568. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1569. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1570. $count = Db::name("good_spec")->save($lemp);
  1571. if($count==false){
  1572. Db::rollback();
  1573. return app_show(1004,"商品规格值修改失败");
  1574. }
  1575. }
  1576. }
  1577. if($good_ladder!=="" && !empty($good_ladder)){
  1578. foreach ($good_ladder as $value){
  1579. $lemp=[];
  1580. isset($value["id"])&&$value["id"]!=''?$lemp['id']=$value['id']:"";
  1581. $lemp['spuCode']=$supcode;
  1582. $lemp['min_num'] = $value['min_num'];
  1583. $lemp['nake_fee'] = $value['nake_fee'];
  1584. $lemp['cost_fee'] = $value['cost_fee'];
  1585. $lemp['delivery_fee'] = $value['delivery_fee'];
  1586. $lemp['cert_fee'] = $value['cert_fee'];
  1587. $lemp['mark_fee'] = $value['mark_fee'];
  1588. $lemp['package_fee'] = $value['package_fee'];
  1589. $lemp['other_fee'] = $value['other_fee'];
  1590. if($is_gold_price==1){
  1591. $lemp['nake_total'] =$noble_weight*$cgd_gold_price + $value['cost_fee']*
  1592. $noble_weight+$value['mark_fee']+$value['package_fee']+$value['cert_fee']+$value['nake_fee']+$value['delivery_fee']+$value['other_fee'];
  1593. }else{
  1594. $lemp['nake_total'] =$value['nake_fee']+$value['delivery_fee']+$value['cert_fee']+$value['mark_fee']+$value['package_fee']+$value['other_fee'];
  1595. }
  1596. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  1597. isset($value["id"])&&$value["id"]!=''?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  1598. $lemp['updatetime'] =date("Y-m-d H:i:s");
  1599. $count = Db::name("good_nake")->save($lemp);
  1600. if($count==false){
  1601. Db::rollback();
  1602. return app_show(1004,"商品规成本修改失败");
  1603. }
  1604. }
  1605. }
  1606. Db::commit();
  1607. return app_show(0,"更新成功");
  1608. }else{
  1609. Db::rollback();
  1610. return error_show(1005,"更新失败");
  1611. }
  1612. }catch (\Exception $e){
  1613. Db::rollback();
  1614. return error_show(1004,$e->getMessage());
  1615. }
  1616. }
  1617. public function checkPrice(){
  1618. $spuCode=isset($this->post['spuCode'])&&$this->post['spuCode']!=""? trim($this->post['spuCode']):"";
  1619. if($spuCode==""){
  1620. return error_show(1005,"参数spuCode不能为空");
  1621. }
  1622. $good =Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  1623. if($good==false){
  1624. return error_show(1005,"商品数据未找到");
  1625. }
  1626. $num=isset($this->post['min_num'])&&$this->post['min_num']!=="" ? intval($this->post['min_num']):"";
  1627. if($num==""){
  1628. return error_show(1005,"参数min_num不能为空");
  1629. }
  1630. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->where([["min_num","<=",$num]])
  1631. ->order("min_num desc")->find();
  1632. if($nakelist==false){
  1633. $nakelist = Db::name("good_nake")->where(['spuCode'=>$spuCode,"is_del"=>0])->order("min_num asc")->find();
  1634. return error_show(1010,"起订量不足{$nakelist['min_num']}");
  1635. }
  1636. $catinfo = Db::name("cat")->where(["id"=>$good['cat_id']])->find();
  1637. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1638. if($good['is_gold_price']==1){
  1639. $saleprice = $good['noble_weight']*$good["cgd_gold_price"] + $nakelist['cost_fee']/(1-$budget)*
  1640. $good['noble_weight']+$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['nake_fee']+$nakelist['delivery_fee'];
  1641. }else{
  1642. $saleprice =$nakelist['mark_fee']+$nakelist['package_fee']+$nakelist['cert_fee']+$nakelist['delivery_fee']+$nakelist['nake_fee']/(1-$budget);
  1643. }
  1644. return app_show(0,"获取成功",["sale_price"=>round($saleprice,2)]);
  1645. }
  1646. }