Goodup.php 85 KB

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