WaterMembershioCard.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\water;
  8. use app\admin\controller\AuthController;
  9. use crmeb\services\{ExpressService,
  10. JsonService,
  11. JsonService as Json,
  12. MiniProgramService,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util};
  17. use think\facade\Route as Url;
  18. use think\facade\Validate;
  19. Use app\admin\model\water\WaterMembershioCard as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterMembershioCard extends AuthController
  26. {
  27. /**
  28. * @return mixed
  29. */
  30. public function index()
  31. {
  32. return $this->fetch();
  33. }
  34. public function list()
  35. {
  36. $where = Util::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ['name', ''],
  40. ['role', '']
  41. ]);
  42. return Json::successlayui(model::list($where));
  43. }
  44. /**
  45. * 显示创建资源表单页.
  46. *
  47. * @return \think\Response
  48. */
  49. public function create($id = 0)
  50. {
  51. $f = [];
  52. $f[] = Form::input('title', '名称')->col(12);
  53. $f[] = Form::input('price', '价格');
  54. $f[] = Form::input('ot_price', '原价');
  55. $f[] = Form::input('time', '天数');
  56. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  57. $this->assign(compact('form'));
  58. return $this->fetch('public/form-builder');
  59. }
  60. public function save()
  61. {
  62. $model = new model;
  63. $data = Util::postMore([
  64. 'title',
  65. 'price',
  66. 'ot_price',
  67. 'time',
  68. ]);
  69. $validate = Validate::rule([
  70. 'title' => 'require',
  71. 'price' => 'require',
  72. 'ot_price' => 'require',
  73. 'time' => 'require',
  74. ]);
  75. $validate->message([
  76. 'title.require' => '名称不能为空',
  77. 'price.require' => '请填写价格',
  78. 'ot_price.require' => '请填写原价',
  79. 'time.require' => '请填写时间',
  80. ]);
  81. if (!$validate->check($data)) {
  82. return Json::fail($validate->getError());
  83. }
  84. $res = $model->save($data);
  85. if ($res) return Json::successful('添加成功');
  86. return Json::fail('添加失败');
  87. }
  88. /**
  89. * 显示创建资源表单页.
  90. *
  91. * @return \think\Response
  92. */
  93. public function edit($id = 0)
  94. {
  95. $data = model::find($id);
  96. $f = [];
  97. $f[] = Form::input('title', '名称', $data['title'])->col(12);
  98. $f[] = Form::input('price', '价格', $data['price']);
  99. $f[] = Form::input('ot_price', '原价', $data['ot_price']);
  100. $f[] = Form::input('time', '天数', $data['time']);
  101. $f[] = Form::hidden('id', $id);
  102. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  103. $this->assign(compact('form'));
  104. return $this->fetch('public/form-builder');
  105. }
  106. /**
  107. * 修改
  108. * @return void
  109. * @throws \think\db\exception\DataNotFoundException
  110. * @throws \think\db\exception\DbException
  111. * @throws \think\db\exception\ModelNotFoundException
  112. */
  113. public function update()
  114. {
  115. $model = new model;
  116. $data = Util::postMore([
  117. 'title',
  118. 'price',
  119. 'ot_price',
  120. 'time',
  121. 'id'
  122. ]);
  123. $validate = Validate::rule([
  124. 'title' => 'require',
  125. 'price' => 'require',
  126. 'ot_price' => 'require',
  127. 'time' => 'require',
  128. ]);
  129. $validate->message([
  130. 'title.require' => '名称不能为空',
  131. 'price.require' => '请填写价格',
  132. 'ot_price.require' => '请填写原价',
  133. 'time.require' => '请填写时间',
  134. ]);
  135. $details = $model->find($data['id']);
  136. $details['name'] = $data['name'];
  137. $details['thickness'] = $data['thickness'];
  138. $res = $details->save();
  139. if ($res) return Json::successful('修改成功');
  140. return Json::fail('修改失败');
  141. }
  142. /**
  143. * 删除
  144. * @param $id
  145. * @return void
  146. * @throws \Exception
  147. */
  148. public function delete($id)
  149. {
  150. if (!$id) Json::fail('删除失败');
  151. $model = new model;
  152. $res = model::destroy($id);
  153. if ($res){
  154. return Json::success('删除成功!');
  155. }else{
  156. return Json::fail($model->getErrorInfo());
  157. }
  158. }
  159. }