Goodup.php 82 KB

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