Fare.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\Fare as AppFare;
  11. class Fare extends Manage{
  12. public function initialize() {
  13. parent::initialize();
  14. $this->assign('pathMaps',[['name'=>'运费设置','url'=>url("popupshop/fare/index")]]);
  15. }
  16. /**
  17. * 运费管理
  18. */
  19. public function index(){
  20. $view['info'] = AppFare::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  21. return view('index',$view);
  22. }
  23. /**
  24. * 编辑/保存
  25. */
  26. public function save(){
  27. if(request()->isAjax()){
  28. $data = [
  29. 'first_weight' => input('post.first_weight/d'),
  30. 'first_price' => input('post.first_price/d'),
  31. 'second_weight' => input('post.second_weight/d'),
  32. 'second_price' => input('post.second_price/d'),
  33. ];
  34. $validate = $this->validate($data,'fare.save');
  35. if(true !== $validate){
  36. return enjson(0,$validate);
  37. }
  38. $rel = AppFare::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  39. if(empty($rel)){
  40. $data['member_miniapp_id'] = $this->member_miniapp_id;
  41. $result = AppFare::insert($data);
  42. }else{
  43. $result = AppFare::update($data,['member_miniapp_id' => $this->member_miniapp_id]);
  44. }
  45. if($result){
  46. return enjson(200,'操作成功',['url' => url('popupshop/fare/index')]);
  47. }else{
  48. return enjson(0);
  49. }
  50. }
  51. }
  52. }