Config.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 商城配置
  7. */
  8. namespace app\popupshop\controller;
  9. use app\common\controller\Manage;
  10. use app\popupshop\model\Config as Configs;
  11. use think\facade\Request;
  12. class Config extends Manage{
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. $this->assign('pathMaps',[['name' => '应用配置','url' => url("popupshop/config/index")]]);
  17. }
  18. /**
  19. * 应用配置
  20. * @return void
  21. */
  22. public function index(){
  23. if(request()->isAjax()){
  24. $data = [
  25. 'is_wechat_touser' => Request::param('is_wechat_touser/d',0),
  26. 'tax' => Request::param('tax/d'),
  27. 'profit' => Request::param('profit/d'),
  28. 'cycle' => Request::param('cycle/d',0),
  29. 'lack_cash' => Request::param('lack_cash/d',0),
  30. 'lock_sale_day' => Request::param('lock_sale_day/d',0),
  31. 'num_referee_people' => Request::param('num_referee_people/d',0),
  32. ];
  33. $validate = $this->validate($data,'config.setting');
  34. if(true !== $validate){
  35. return json(['code'=>0,'msg'=>$validate]);
  36. }
  37. $rel = Configs::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  38. if(empty($rel)){
  39. $data['member_miniapp_id'] = $this->member_miniapp_id;
  40. $result = Configs::create($data);
  41. }else{
  42. $result = Configs::where(['member_miniapp_id' => $this->member_miniapp_id])->update($data);
  43. }
  44. if($result){
  45. return json(['code'=>200,'data' => ['url' => url('popupshop/config/index')],'msg'=>'操作成功']);
  46. }else{
  47. return json(['code'=>0,'msg'=>'操作失败']);
  48. }
  49. }else{
  50. $view['info'] = Configs::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  51. return view()->assign($view);
  52. }
  53. }
  54. }