Goodup.php 81 KB

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