Goodup.php 81 KB

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