Goodup.php 85 KB

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