Goodup.php 67 KB

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