Goodup.php 92 KB

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