Goodup.php 87 KB

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