Goodup.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Goodup extends BaseController
  7. {
  8. public $post="";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function list(){
  15. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  16. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  17. $where =[["is_del","=",0]];
  18. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? intval($this->post['cat_id']):"";
  19. if($cat_id!==""){
  20. $where[]=['cat_id',"=",$cat_id];
  21. }
  22. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  23. if($good_name!==""){
  24. $where[]=['good_name',"like","%$good_name%"];
  25. }
  26. $spucode = isset($this->post['spucode']) && $this->post['spucode'] !=="" ? trim($this->post['spucode'])
  27. :"";
  28. if($spucode!==""){
  29. $where[]=['spuCode',"like","%$spucode%"];
  30. }
  31. $good_type = isset($this->post['good_type']) && $this->post['good_type'] !=="" ? trim($this->post['good_type'])
  32. :"";
  33. if($good_type!==""){
  34. $where[]=['good_type',"=",$good_type];
  35. }
  36. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo'])
  37. :"";
  38. if($companyNo!==""){
  39. $where[]=['companyNo',"like","%$companyNo%"];
  40. }
  41. $supplierNo = isset($this->post['supplierNo']) && $this->post['supplierNo'] !=="" ? trim($this->post['supplierNo'])
  42. :"";
  43. if($supplierNo!==""){
  44. $where[]=['supplierNo',"like","%$supplierNo%"];
  45. }
  46. $brandid = isset($this->post['brandid']) && $this->post['brandid'] !=="" ? intval($this->post['brandid'])
  47. :"";
  48. if($brandid!==""){
  49. $where[]=['brand_id',"=",$brandid];
  50. }
  51. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status'])
  52. :"";
  53. if($status!==""){
  54. $where[]=['status',"=",$status];
  55. }
  56. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  57. if($start!==""){
  58. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  59. }
  60. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  61. if($end!==""){
  62. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  63. }
  64. $count = Db::name('good_basic')->where($where)->count();
  65. $total = ceil($count / $size);
  66. $page = $page >= $total ? $total : $page;
  67. $list = Db::name('good_basic')->where($where)->page($page,$size)->order("addtime desc")->select();
  68. $data=[];
  69. foreach ($list as $value){
  70. $value["cat_info"]= made($value['cat_id'],[]);
  71. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  72. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  73. $unit = Db::name("unit")->where(["id"=>$value['good_unit']])->find();
  74. $value['unit'] =isset($unit['unit'])?$unit['unit']:"";
  75. $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  76. $value['company'] = isset($company['company'])?$company['company']:"";
  77. $supplier = Db::name("supplier")->where(['code'=>$value['supplierNo']])->find();
  78. $value['supplier_name']=isset($supplier['name'])?$supplier['name']:"";
  79. $data[]=$value;
  80. }
  81. return app_show(0,"获取成功",['list'=>$data,'count'=>$count]);
  82. }
  83. public function create(){
  84. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  85. if($good_name==""){
  86. return error_show(1004,"商品名称不能为空");
  87. }
  88. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  89. if($cat_id==''){
  90. return error_show(1004,"商品分类不能为空");
  91. }
  92. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  93. // if($brandid==''){
  94. // return error_show(1004,"商品品牌不能为空");
  95. // }
  96. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  97. if($unit==''){
  98. return error_show(1004,"商品单位不能为空");
  99. }
  100. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  101. :"";
  102. if($good_type===''){
  103. return error_show(1004,"参数good_type不能为空");
  104. }
  105. $moq=0;
  106. $customized=0;
  107. if($good_type==1){
  108. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  109. if($moq===''){
  110. return error_show(1004,"定制商品起订量不能为空");
  111. }
  112. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  113. if($customized===''){
  114. return error_show(1004,"参数customized不能为空");
  115. }
  116. }
  117. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  118. if($is_exclusive===''){
  119. return error_show(1004,"参数is_exclusive不能为空");
  120. }
  121. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  122. // if($customized===''){
  123. // return error_show(1004,"参数customized不能为空");
  124. // }
  125. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  126. if($tax===''){
  127. return error_show(1004,"参数tax不能为空");
  128. }
  129. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  130. if($supplierNo==''){
  131. return error_show(1004,"参数supplierNo不能为空");
  132. }
  133. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  134. :"";
  135. if($company_id==''){
  136. return error_show(1004,"参数company_id不能为空");
  137. }
  138. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  139. if($is_auth===''){
  140. return error_show(1004,"参数is_auth不能为空");
  141. }
  142. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  143. // if($auth_img==''){
  144. // return error_show(1004,"商品不能为空");
  145. // }
  146. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  147. if($after_sales==""){
  148. return error_show(1004,"参数after_sales不能为空");
  149. }
  150. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  151. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  152. if($good_remark===""){
  153. return error_show(1004,"参数good_remark不能为空");
  154. }
  155. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  156. if($weight===""){
  157. return error_show(1004,"参数weight不能为空");
  158. }
  159. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  160. if($packing_way===""){
  161. return error_show(1004,"参数packing_way不能为空");
  162. }
  163. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  164. if($packing_size===""){
  165. return error_show(1004,"参数packing_size不能为空");
  166. }
  167. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  168. if($packing_spec===""){
  169. return error_show(1004,"参数packing_spec不能为空");
  170. }
  171. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  172. if($packing_weight===""){
  173. return error_show(1004,"参数packing_weight不能为空");
  174. }
  175. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  176. if($packing_list===""){
  177. return error_show(1004,"参数packing_list不能为空");
  178. }
  179. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  180. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  181. if($supply_area===""){
  182. return error_show(1004,"参数supply_area不能为空");
  183. }
  184. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? trim($this->post['delivery_place']):"";
  185. if($delivery_place===""){
  186. return error_show(1004,"参数delivery_place不能为空");
  187. }
  188. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? trim($this->post['origin_place']):"";
  189. if($origin_place===""){
  190. return error_show(1004,"参数origin_place不能为空");
  191. }
  192. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  193. if($delivery_day===""){
  194. return error_show(1004,"参数delivery_day不能为空");
  195. }
  196. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  197. :"0";
  198. // if($lead_time===""){
  199. // return error_show(1004,"参数lead_time不能为空");
  200. // }
  201. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  202. // if($sample_day===""){
  203. // return error_show(1004,"参数sample_day不能为空");
  204. // }
  205. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  206. $is_stock = isset($this->post['is_stock'])&&$this->post['is_stock']!==""? intval($this->post['is_stock']):"";
  207. if($is_stock===""){
  208. return error_show(1004,"参数is_stock不能为空");
  209. }
  210. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  211. // if($good_img===""){
  212. // return error_show(1004,"参数good_img不能为空");
  213. // }
  214. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  215. if($good_thumb_img===""){
  216. return error_show(1004,"参数good_thumb_img不能为空");
  217. }
  218. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  219. if($good_info_img===""){
  220. return error_show(1004,"参数good_info_img不能为空");
  221. }
  222. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  223. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  224. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  225. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  226. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  227. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  228. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  229. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  230. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  231. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  232. if($market_price===""){
  233. return error_show(1004,"参数market_price不能为空");
  234. }
  235. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  236. if($nake_price===""){
  237. return error_show(1004,"参数nake_price不能为空");
  238. }
  239. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  240. if($is_step===""){
  241. return error_show(1004,"参数is_step不能为空");
  242. }
  243. $speclist = isset($this->post['speclist'])&&!empty($this->post['speclist'])? $this->post['speclist']:"";
  244. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  245. $spucode=makeNo("SPU");
  246. Db::startTrans();
  247. try {
  248. $data=[
  249. "spuCode"=>$spucode,
  250. "good_code"=>'',
  251. "good_name"=>$good_name,
  252. "cat_id"=>$cat_id,
  253. 'brand_id'=>$brandid,
  254. "good_unit"=>$unit,
  255. "good_type"=>$good_type,
  256. "moq"=>$moq,
  257. "is_exclusive"=>$is_exclusive,
  258. "customized"=>$customized,
  259. "companyNo"=>$company_id,
  260. "tax"=>$tax,
  261. "supplierNo"=>$supplierNo,
  262. "is_auth"=>$is_auth,
  263. "is_stock"=>$is_stock,
  264. "auth_img"=>$auth_img,
  265. "after_sales"=>$after_sales,
  266. "craft_desc"=>$craft_desc,
  267. "good_remark"=>$good_remark,
  268. "weight"=>$weight,
  269. "packing_way"=>$packing_way,
  270. "packing_size"=>$packing_size,
  271. "packing_spec"=>$packing_spec,
  272. "packing_list"=>$packing_list,
  273. "packing_weight"=>$packing_weight,
  274. "good_bar"=>$good_bar,
  275. "supply_area"=>$supply_area,
  276. "delivery_place"=>$delivery_place,
  277. "origin_place"=>$origin_place,
  278. "delivery_day"=>$delivery_day,
  279. "lead_time"=>$lead_time,
  280. "sample_day"=>$sample_day,
  281. "sample_fee"=>$sample_fee,
  282. "good_img"=>$good_img,
  283. "good_thumb_img"=>$good_thumb_img,
  284. "good_info_img"=>json_encode($good_info_img),
  285. "cert_fee"=>$cert_fee,
  286. "packing_fee"=>$packing_fee,
  287. "cost_fee"=>$cost_fee,
  288. "mark_fee"=>$mark_fee,
  289. "demo_fee"=>$demo_fee,
  290. "open_fee"=>$open_fee,
  291. "noble_metal"=>$noble_metal,
  292. "noble_weight"=>$noble_weight,
  293. "is_gold_price"=>$is_gold_price,
  294. "market_price"=>$market_price,
  295. "nake_price"=>$nake_price,
  296. "is_step"=>$is_step,
  297. "is_online"=>0,
  298. "status"=>0,
  299. "createrid"=>0,
  300. "creater"=>"",
  301. "addtime"=>date("Y-m-d H:i:s"),
  302. "updatetime"=>date("Y-m-d H:i:s")
  303. ];
  304. $in = Db::name("good_basic")->insert($data);
  305. if($in){
  306. if($speclist!=="" && !empty($speclist)){
  307. $temp=[];
  308. foreach ($speclist as $value){
  309. $lemp=[];
  310. $lemp['spuCode']=$spucode;
  311. $lemp['spec_id'] = $value['spec_id'];
  312. $lemp['spec_value_id'] = $value['spec_value_id'];
  313. $lemp['addtime'] = date("Y-m-d H:i:s");
  314. $lemp['updatetime'] =date("Y-m-d H:i:s");
  315. $temp[]=$lemp;
  316. }
  317. $count = Db::name("good_spec")->insertAll($temp);
  318. if($count==0){
  319. Db::rollback();
  320. return app_show(1004,"商品规格值创建失败");
  321. }
  322. }
  323. if($good_ladder!=="" && !empty($good_ladder)){
  324. $temp=[];
  325. foreach ($good_ladder as $value){
  326. $lemp=[];
  327. $lemp['spuCode']=$spucode;
  328. $lemp['min_num'] = $value['min_num'];
  329. $lemp['nake_fee'] = $value['nake_fee'];
  330. $lemp['cost_fee'] = $value['cost_fee'];
  331. $lemp['delivery_fee'] = $value['delivery_fee'];
  332. $lemp['is_del'] = 0;
  333. $lemp['addtime'] = date("Y-m-d H:i:s");
  334. $lemp['updatetime'] =date("Y-m-d H:i:s");
  335. $temp[]=$lemp;
  336. }
  337. $count = Db::name("good_nake")->insertAll($temp);
  338. if($count==0){
  339. Db::rollback();
  340. return app_show(1004,"商品规格值创建失败");
  341. }
  342. }
  343. Db::commit();
  344. return app_show(0,"创建成功",["spuCode"=>$spucode]);
  345. }else{
  346. Db::rollback();
  347. return app_show(1004,"商品创建失败");
  348. }
  349. }catch (\Exception $e){
  350. Db::rollback();
  351. return app_show(1004,$e->getMessage());
  352. }
  353. }
  354. public function editinfo(){
  355. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  356. if($supcode==""){
  357. return error_show(1004,"参数spuCode不能为空");
  358. }
  359. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  360. if($data==false){
  361. return error_show(1004,"未找到商品数据");
  362. }
  363. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!="" ? trim($this->post['good_name']):"";
  364. if($good_name==""){
  365. return error_show(1004,"商品名称不能为空");
  366. }
  367. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? intval($this->post['cat_id']):"";
  368. if($cat_id==''){
  369. return error_show(1004,"商品分类不能为空");
  370. }
  371. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"0";
  372. // if($brandid==''){
  373. // return error_show(1004,"商品品牌不能为空");
  374. // }
  375. $unit = isset($this->post['unit'])&&$this->post['unit']!=""? trim($this->post['unit']):"";
  376. if($unit==''){
  377. return error_show(1004,"商品单位不能为空");
  378. }
  379. $good_type = isset($this->post['good_type'])&&$this->post['good_type']!==""? intval($this->post['good_type'])
  380. :"";
  381. if($good_type===''){
  382. return error_show(1004,"参数good_type不能为空");
  383. }
  384. $moq=0;
  385. $customized=0;
  386. if($good_type==1){
  387. $moq = isset($this->post['moq'])&&$this->post['moq']!==""? intval($this->post['moq']):"";
  388. if($moq===''){
  389. return error_show(1004,"定制商品起订量不能为空");
  390. }
  391. $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  392. if($customized===''){
  393. return error_show(1004,"参数customized不能为空");
  394. }
  395. }
  396. $is_exclusive = isset($this->post['is_exclusive'])&&$this->post['is_exclusive']!==""? intval($this->post['is_exclusive']):"";
  397. if($is_exclusive===''){
  398. return error_show(1004,"参数is_exclusive不能为空");
  399. }
  400. // $customized = isset($this->post['customized'])&&$this->post['customized']!==""? intval($this->post['customized']):"";
  401. // if($customized===''){
  402. // return error_show(1004,"参数customized不能为空");
  403. // }
  404. $tax = isset($this->post['tax'])&&$this->post['tax']!==""? intval($this->post['tax']):"";
  405. if($tax===''){
  406. return error_show(1004,"参数tax不能为空");
  407. }
  408. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  409. if($supplierNo==''){
  410. return error_show(1004,"参数supplierNo不能为空");
  411. }
  412. $company_id = isset($this->post['company_id'])&&$this->post['company_id']!=""? trim($this->post['company_id'])
  413. :"";
  414. if($company_id==''){
  415. return error_show(1004,"参数company_id不能为空");
  416. }
  417. $is_auth = isset($this->post['is_auth'])&&$this->post['is_auth']!==""? intval($this->post['is_auth']):"";
  418. if($is_auth===''){
  419. return error_show(1004,"参数is_auth不能为空");
  420. }
  421. $auth_img = isset($this->post['auth_img'])&&$this->post['auth_img']!=""? trim($this->post['auth_img']):"";
  422. // if($auth_img==''){
  423. // return error_show(1004,"商品不能为空");
  424. // }
  425. $after_sales = isset($this->post['after_sales'])&&$this->post['after_sales']!=""? trim($this->post['after_sales']):"";
  426. if($after_sales==""){
  427. return error_show(1004,"参数after_sales不能为空");
  428. }
  429. $craft_desc = isset($this->post['craft_desc'])&&$this->post['craft_desc']!=""? trim($this->post['craft_desc']):"";
  430. $good_remark = isset($this->post['good_remark'])&&$this->post['good_remark']!=""? trim($this->post['good_remark']):"";
  431. if($good_remark===""){
  432. return error_show(1004,"参数good_remark不能为空");
  433. }
  434. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"";
  435. if($weight===""){
  436. return error_show(1004,"参数weight不能为空");
  437. }
  438. $packing_way = isset($this->post['packing_way'])&&$this->post['packing_way']!==""? trim($this->post['packing_way']):"";
  439. if($packing_way===""){
  440. return error_show(1004,"参数packing_way不能为空");
  441. }
  442. $packing_size = isset($this->post['packing_size'])&&$this->post['packing_size']!==""? trim($this->post['packing_size']):"";
  443. if($packing_size===""){
  444. return error_show(1004,"参数packing_size不能为空");
  445. }
  446. $packing_spec = isset($this->post['packing_spec'])&&$this->post['packing_spec']!==""? trim($this->post['packing_spec']):"";
  447. if($packing_spec===""){
  448. return error_show(1004,"参数packing_spec不能为空");
  449. }
  450. $packing_weight = isset($this->post['packing_weight'])&&$this->post['packing_weight']!==""? floatval($this->post['packing_weight']):"";
  451. if($packing_weight===""){
  452. return error_show(1004,"参数packing_weight不能为空");
  453. }
  454. $packing_list = isset($this->post['packing_list'])&&$this->post['packing_list']!==""? trim($this->post['packing_list']):"";
  455. if($packing_list===""){
  456. return error_show(1004,"参数packing_list不能为空");
  457. }
  458. $good_bar = isset($this->post['good_bar'])&&$this->post['good_bar']!==""? trim($this->post['good_bar']):"";
  459. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  460. if($supply_area===""){
  461. return error_show(1004,"参数supply_area不能为空");
  462. }
  463. $delivery_place = isset($this->post['delivery_place'])&&$this->post['delivery_place']!==""? $this->post['delivery_place']:"";
  464. if($delivery_place===""){
  465. return error_show(1004,"参数delivery_place不能为空");
  466. }
  467. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!==""? $this->post['origin_place']:"";
  468. if($origin_place===""){
  469. return error_show(1004,"参数origin_place不能为空");
  470. }
  471. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!==""? intval($this->post['delivery_day']):"";
  472. if($delivery_day===""){
  473. return error_show(1004,"参数delivery_day不能为空");
  474. }
  475. $lead_time = isset($this->post['lead_time'])&&$this->post['lead_time']!==""? intval($this->post['lead_time'])
  476. :"0";
  477. // if($lead_time===""){
  478. // return error_show(1004,"参数lead_time不能为空");
  479. // }
  480. $sample_day = isset($this->post['sample_day'])&&$this->post['sample_day']!==""? intval($this->post['sample_day']):"0";
  481. // if($sample_day===""){
  482. // return error_show(1004,"参数sample_day不能为空");
  483. // }
  484. $sample_fee = isset($this->post['sample_fee'])&&$this->post['sample_fee']!==""? floatval($this->post['sample_fee']):"0";
  485. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!==""? trim($this->post['good_img']):"";
  486. // if($good_img===""){
  487. // return error_show(1004,"参数good_img不能为空");
  488. // }
  489. $good_thumb_img = isset($this->post['good_thumb_img'])&&$this->post['good_thumb_img']!==""? trim($this->post['good_thumb_img']):"";
  490. if($good_thumb_img===""){
  491. return error_show(1004,"参数good_thumb_img不能为空");
  492. }
  493. $good_info_img = isset($this->post['good_info_img'])&&!empty($this->post['good_info_img'])? $this->post['good_info_img']:"";
  494. if($good_info_img===""){
  495. return error_show(1004,"参数good_info_img不能为空");
  496. }
  497. $temp=[
  498. "good_name"=>$good_name,
  499. "cat_id"=>$cat_id,
  500. 'brand_id'=>$brandid,
  501. "good_unit"=>$unit,
  502. "good_type"=>$good_type,
  503. "companyNo"=>$company_id,
  504. "moq"=>$moq,
  505. "is_exclusive"=>$is_exclusive,
  506. "customized"=>$customized,
  507. "tax"=>$tax,
  508. "supplierNo"=>$supplierNo,
  509. "is_auth"=>$is_auth,
  510. "auth_img"=>$auth_img,
  511. "after_sales"=>$after_sales,
  512. "craft_desc"=>$craft_desc,
  513. "good_remark"=>$good_remark,
  514. "weight"=>$weight,
  515. "packing_way"=>$packing_way,
  516. "packing_size"=>$packing_size,
  517. "packing_spec"=>$packing_spec,
  518. "packing_list"=>$packing_list,
  519. "packing_weight"=>$packing_weight,
  520. "good_bar"=>$good_bar,
  521. "supply_area"=>$supply_area,
  522. "delivery_place"=>$delivery_place,
  523. "origin_place"=>$origin_place,
  524. "delivery_day"=>$delivery_day,
  525. "lead_time"=>$lead_time,
  526. "sample_day"=>$sample_day,
  527. "sample_fee"=>$sample_fee,
  528. "good_img"=>$good_img,
  529. "good_thumb_img"=>$good_thumb_img,
  530. "good_info_img"=>json_encode($good_info_img),
  531. "status"=>"3",
  532. "updatetime"=>date("Y-m-d H:i:s")
  533. ];
  534. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($temp);
  535. if($up){
  536. return app_show(0,"更新成功");
  537. }else{
  538. return error_show(1005,"更新失败");
  539. }
  540. }
  541. public function editfee(){
  542. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  543. if($supcode==""){
  544. return error_show(1004,"参数spuCode不能为空");
  545. }
  546. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  547. if($data==false){
  548. return error_show(1004,"未找到商品数据");
  549. }
  550. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  551. $packing_fee = isset($this->post['packing_fee'])&&$this->post['packing_fee']!==""? floatval($this->post['packing_fee']):"0";
  552. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  553. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  554. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  555. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  556. $noble_metal = isset($this->post['noble_metal'])&&$this->post['noble_metal']!==""? intval($this->post['noble_metal']):"0";
  557. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  558. $is_gold_price= isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!==""? intval($this->post['is_gold_price']):"0";
  559. $market_price = isset($this->post['market_price'])&&$this->post['market_price']!==""? floatval($this->post['market_price']):"";
  560. if($market_price===""){
  561. return error_show(1004,"参数market_price不能为空");
  562. }
  563. $nake_price = isset($this->post['nake_price'])&&$this->post['nake_price']!==""? floatval($this->post['nake_price']):"";
  564. if($nake_price===""){
  565. return error_show(1004,"参数nake_price不能为空");
  566. }
  567. $is_step = isset($this->post['is_step'])&&$this->post['is_step']!==""? intval($this->post['is_step']):"";
  568. if($is_step===""){
  569. return error_show(1004,"参数is_step不能为空");
  570. }
  571. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])? $this->post['good_ladder']:"";
  572. $data=[
  573. "cert_fee"=>$cert_fee,
  574. "packing_fee"=>$packing_fee,
  575. "cost_fee"=>$cost_fee,
  576. "mark_fee"=>$mark_fee,
  577. "demo_fee"=>$demo_fee,
  578. "open_fee"=>$open_fee,
  579. "noble_metal"=>$noble_metal,
  580. "noble_weight"=>$noble_weight,
  581. "is_gold_price"=>$is_gold_price,
  582. "market_price"=>$market_price,
  583. "nake_price"=>$nake_price,
  584. "is_step"=>$is_step,
  585. "status"=>"2",
  586. "updatetime"=>date("Y-m-d H:i:s")
  587. ];
  588. Db::startTrans();
  589. try{
  590. $up = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save($data);
  591. if($up){
  592. $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")]);
  593. if($good_ladder!=="" && !empty($good_ladder)){
  594. foreach ($good_ladder as $value){
  595. $lemp=[];
  596. isset($value["id"])?$lemp['id']=$value['id']:"";
  597. $lemp['spuCode']=$supcode;
  598. $lemp['min_num'] = $value['min_num'];
  599. $lemp['nake_fee'] = $value['nake_fee'];
  600. $lemp['cost_fee'] = $value['cost_fee'];
  601. $lemp['delivery_fee'] = $value['delivery_fee'];
  602. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  603. isset($value["id"])? $lemp['addtime'] = date("Y-m-d H:i:s"):"";
  604. $lemp['updatetime'] =date("Y-m-d H:i:s");
  605. $count = Db::name("good_nake")->save($lemp);
  606. if($count==false){
  607. Db::rollback();
  608. return app_show(1004,"商品规格值修改失败");
  609. }
  610. }
  611. }
  612. Db::commit();
  613. return app_show(0,"更新成功");
  614. }else{
  615. Db::rollback();
  616. return error_show(1005,"更新失败");
  617. }
  618. }catch (\Exception $e){
  619. Db::rollback();
  620. return error_show(1005,$e->getMessage());
  621. }
  622. }
  623. public function exam(){
  624. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  625. if($supcode==""){
  626. return error_show(1004,"参数spuCode不能为空");
  627. }
  628. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  629. if($data==false){
  630. return error_show(1004,"未找到商品数据");
  631. }
  632. if($data['status']==1){
  633. return error_show(1004,"商品已审核通过");
  634. }
  635. $status = isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
  636. if($status===""){
  637. return error_show(1004,"参数status不能为空");
  638. }
  639. Db::startTrans();
  640. try {
  641. if($data['status']==3){
  642. $online = Db::name("good_platform")->where(["spuCode"=>$supcode,"is_online"=>0,"status"=>0, "is_del"=>0])->save(["is_online"=>0,"status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  643. }
  644. $data['status']=$status;
  645. $data['updatetime']=date("Y-m-d H:i:s");
  646. $up= Db::name("good_basic")->save($data);
  647. if($up){
  648. Db::commit();
  649. return app_show(0,"审核成功");
  650. }else{
  651. Db::rollback();
  652. return error_show(1004,"审核失败");
  653. }
  654. }catch (\Exception $e){
  655. Db::rollback();
  656. return error_show(1004,$e->getMessage());
  657. }
  658. }
  659. public function info(){
  660. $supcode = isset($this->post['spuCode'])&&$this->post['spuCode']!="" ? trim($this->post['spuCode']):"";
  661. if($supcode==""){
  662. return error_show(1004,"参数spuCode不能为空");
  663. }
  664. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->find();
  665. if($data==false){
  666. return error_show(1004,"未找到商品数据");
  667. }
  668. $unit =Db::name("unit")->where(["unit"=>$data['good_unit']])->find();
  669. $data['unit_id'] = isset($unit['id'])?$unit['id']:0;
  670. $data['cat_info'] = made($data['cat_id'],[]);
  671. $spec = Db::name("good_spec")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  672. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  673. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  674. $supplier = Db::name("supplier")->where(["code"=>$data['supplierNo']])->find();
  675. $data['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  676. $company = Db::name("business")->where(["companyNo"=>$data['companyNo']])->find();
  677. $data['company'] = isset($company['company'])?$company['company']:"";
  678. $brand=Db::name("brand")->where(["id"=>$data['brand_id']])->find();
  679. $data["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  680. $speclist=[];
  681. if(!empty($spec)){
  682. foreach ($spec as $value){
  683. $temp=[];
  684. $temp['id']=$value['id'];
  685. $temp['spuCode']=$value['spuCode'];
  686. $temp['spec_id']=$value['spec_id'];
  687. $temp['spec_value_id']=$value['spec_value_id'];
  688. $temp['is_del']=$value['is_del'];
  689. $sp = Db::name("specs")->where(["id"=>$value['spec_id']])->find();
  690. $temp['spec_name']=isset($sp["spec_name"]) ? $sp["spec_name"]:"";
  691. $spv = Db::name("spec_value")->where(["id"=>$value['spec_value_id']])->find();
  692. $temp['spec_value']=isset($spv["spec_value"]) ? $spv["spec_value"]:"";
  693. $speclist[]=$temp;
  694. }
  695. }
  696. $data["speclist"]=empty($speclist)?[]:$speclist;
  697. // $nake=[];
  698. $nakelist = Db::name("good_nake")->where(['spuCode'=>$supcode,"is_del"=>0])->select()->toArray();
  699. $data["nakelist"]=!empty($nakelist)?$nakelist:[];
  700. return app_show(0,"获取成功",$data);
  701. }
  702. public function delall(){
  703. $supcode = isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  704. if($supcode==""){
  705. return error_show(1004,"参数codes不能为空");
  706. }
  707. $data = Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->select()->toArray();
  708. if(empty($data)){
  709. return error_show(1004,"未找到商品数据");
  710. }
  711. $up= Db::name("good_basic")->where(["spuCode"=>$supcode,"is_del"=>0])->save(["is_del"=>1]);
  712. if($up){
  713. return app_show(0,"更新成功");
  714. }else{
  715. return error_show(1005,"更新失败");
  716. }
  717. }
  718. public function online(){
  719. $platform =isset($this->post['platform'])&&!empty($this->post['platform'])? $this->post['platform']:"";
  720. if($platform==""){
  721. return error_show(1004,"参数codes不能为空");
  722. }
  723. $spuCode =isset($this->post['codes'])&&!empty($this->post['codes'])? $this->post['codes']:"";
  724. if($spuCode===''){
  725. return error_show(1004,"参数codes不能为空");
  726. }
  727. $data = Db::name("good_basic")->where(["spuCode"=>$spuCode,"is_del"=>0])->find();
  728. if($data==false){
  729. return error_show(1004,"未找到商品数据");
  730. }
  731. $online_reason = isset($this->post['online_reason'])&&$this->post['online_reason']!==""? trim($this->post['online_reason']):"";
  732. if($online_reason===""){
  733. return error_show(1004,"参数online_reason不能为空");
  734. }
  735. $online_remark= isset($this->post['online_remark'])&&$this->post['online_remark']!==""? trim($this->post['online_remark']):"";
  736. if($online_remark===""){
  737. return error_show(1004,"参数online_remark不能为空");
  738. }
  739. $data=[];
  740. foreach ($spuCode as $value){
  741. $data[]=[
  742. "spuCode"=>$value,
  743. "skuCode"=>makeNo("SKU"),
  744. "platform_code"=>$platform,
  745. "online_reason"=>$online_reason,
  746. "online_remark"=>$online_remark,
  747. "exam_status"=>0,
  748. "is_online"=>0,
  749. "status"=>1,
  750. "is_del"=>0,
  751. "addtime"=>date("Y-m-d H:i:s"),
  752. "updatetime"=>date("Y-m-d H:i:s")
  753. ];
  754. }
  755. Db::startTrans();
  756. $create =Db::name("good_platform")->insertAll($data);
  757. if($create){
  758. Db::commit();
  759. return app_show(0,"提交成功");
  760. }else{
  761. Db::rollback();
  762. return error_show(1004,"提交失败");
  763. }
  764. }
  765. public function online_exam(){
  766. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  767. if($skuCode===""){
  768. return error_show(1004,"参数skuCode不能为空");
  769. }
  770. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  771. if($platform==false){
  772. return error_show(1004,"未找到数据");
  773. }
  774. $exam_status=isset($this->post['exam_status'])&&$this->post['exam_status']!==""?intval($this->post['exam_status']):"";
  775. if($exam_status===""){
  776. return error_show(1004,"参数exam_status不能为空");
  777. }
  778. if($exam_status==3){
  779. $online_time= isset($this->post['online_time'])&&$this->post['online_time']!==""?$this->post['online_time']:"";
  780. if($online_time===""){
  781. return error_show(1004,"参数online_time不能为空");
  782. }
  783. $platform['online_time']=$online_time;
  784. }
  785. $exam_remark = isset($this->post['exam_remark'])&&$this->post['exam_remark']!==""?trim($this->post['exam_remark']):"";
  786. $platform['exam_status']=$exam_status;
  787. $platform['updatetime']=date("Y-m-d H:i:s");
  788. Db::startTrans();
  789. try {
  790. $up = Db::name("good_platform")->save($platform);
  791. if($up){
  792. $data=[
  793. "skuCode"=>$platform['skuCode'],
  794. "exam_status"=>$exam_status,
  795. "exam_id"=>0,
  796. "exam_name"=>"",
  797. "exam_remark"=>$exam_remark,
  798. "addtime"=>date("Y-m-d H:i:s")
  799. ];
  800. $inr=Db::name("good_exam")->insert($data);
  801. if($inr){
  802. Db::commit();
  803. return app_show(0,"审核成功");
  804. }else{
  805. Db::rollback();
  806. return error_show(1004,"审核失败");
  807. }
  808. }else{
  809. Db::rollback();
  810. return error_show(1004,"审核失败");
  811. }
  812. }catch (\Exception $e){
  813. Db::rollback();
  814. return error_show(1004,$e->getMessage());
  815. }
  816. }
  817. public function editladder(){
  818. $skuCode = isset($this->post['skuCode'])&&$this->post['skuCode']!==""?trim($this->post['skuCode']):"";
  819. if($skuCode===""){
  820. return error_show(1004,"参数skuCode不能为空");
  821. }
  822. $platform = Db::name("good_platform")->where(["skuCode"=>$skuCode,"is_del"=>0])->find();
  823. if($platform==false){
  824. return error_show(1004,"未找到数据");
  825. }
  826. $good_ladder = isset($this->post['good_ladder'])&&!empty($this->post['good_ladder'])?$this->post['good_ladder']:"";
  827. if($good_ladder==""){
  828. return error_show(1004,"参数good_ladder不能为空");
  829. }
  830. $platform['exam_status']=4;
  831. $platform['updatetime']=date("Y-m-d H:i:s");
  832. Db::startTrans();
  833. try {
  834. foreach ($good_ladder as $value){
  835. $lemp=[];
  836. isset($value["id"])&&$value["id"]!=""?$lemp['id']=$value['id']:"";
  837. $lemp['skuCode']=$skuCode;
  838. $lemp['min_num'] = $value['min_num'];
  839. $lemp['max_num'] = 0;
  840. $lemp['sale_price'] = $value['sale_price'];
  841. $lemp['origin_price'] = $value['origin_price'];
  842. $lemp['market_price'] = $value['market_price'];
  843. $lemp['market_platform'] = $value['market_platform'];
  844. $lemp['origin_rate'] = $value['origin_rate'];
  845. $lemp['status'] = $value['status'];
  846. $lemp['is_del'] = isset($value['is_del'])?$value['is_del']:0;
  847. isset($value["id"])&&$value["id"]!=""?"": $lemp['addtime'] = date("Y-m-d H:i:s");
  848. $lemp['updatetime'] =date("Y-m-d H:i:s");
  849. // var_dump(isset($value["id"]));
  850. $count = Db::name("good_ladder")->save($lemp);
  851. if($count==false){
  852. Db::rollback();
  853. return app_show(1004,"商品起订价修改失败");
  854. }
  855. }
  856. $up = Db::name("good_platform")->save($platform);
  857. if($up){
  858. $data=[
  859. "skuCode"=>$platform['skuCode'],
  860. "exam_status"=>4,
  861. "exam_id"=>0,
  862. "exam_name"=>"",
  863. "exam_remark"=>'',
  864. "addtime"=>date("Y-m-d H:i:s")
  865. ];
  866. $inr=Db::name("good_exam")->insert($data);
  867. if($inr){
  868. Db::commit();
  869. return app_show(0,"审核成功");
  870. }else{
  871. Db::rollback();
  872. return error_show(1004,"审核失败");
  873. }
  874. }else{
  875. Db::rollback();
  876. return error_show(1004,"审核失败");
  877. }
  878. }catch (\Exception $e){
  879. Db::rollback();
  880. return error_show(1004,$e->getMessage());
  881. }
  882. }
  883. }