WaterThickness.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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\WaterThickness as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterThickness 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. ]);
  41. return Json::successlayui(model::list($where));
  42. }
  43. /**
  44. * 显示创建资源表单页.
  45. *
  46. * @return \think\Response
  47. */
  48. public function create($id = 0)
  49. {
  50. $f = [];
  51. $f[] = Form::input('name', '名称')->col(12);
  52. $f[] = Form::input('weight', '重量');
  53. if ($id) $f[] = Form::hidden('id', $id);
  54. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  55. $this->assign(compact('form'));
  56. return $this->fetch('public/form-builder');
  57. }
  58. public function save()
  59. {
  60. $model = new model;
  61. $data = Util::postMore([
  62. 'name',
  63. 'thickness',
  64. ]);
  65. $validate = Validate::rule('name', 'require')->rule([
  66. 'name' => 'require',
  67. 'thickness' => 'require',
  68. ]);
  69. $validate->message([
  70. 'name.require' => '名称不能为空',
  71. 'thickness.require' => '厚度不能为空',
  72. ]);
  73. if (!$validate->check($data)) {
  74. return Json::fail($validate->getError());
  75. }
  76. $res = $model->save($data);
  77. if ($res) return Json::successful('添加成功');
  78. return Json::fail('添加失败');
  79. }
  80. /**
  81. * 显示创建资源表单页.
  82. *
  83. * @return \think\Response
  84. */
  85. public function edit($id = 0)
  86. {
  87. $data = model::find($id);
  88. $f = [];
  89. $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
  90. $f[] = Form::input('thickness', '额度', $data->getData('thickness'));
  91. $f[] = Form::hidden('id', $id);
  92. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  93. $this->assign(compact('form'));
  94. return $this->fetch('public/form-builder');
  95. }
  96. /**
  97. * 修改
  98. * @return void
  99. * @throws \think\db\exception\DataNotFoundException
  100. * @throws \think\db\exception\DbException
  101. * @throws \think\db\exception\ModelNotFoundException
  102. */
  103. public function update()
  104. {
  105. $model = new model;
  106. $data = Util::postMore([
  107. 'id',
  108. 'name',
  109. 'thickness',
  110. ]);
  111. $validate = Validate::rule('name', 'require')->rule([
  112. 'name' => 'require',
  113. 'thickness' => 'require',
  114. ]);
  115. $validate->message([
  116. 'name.require' => '名称不能为空',
  117. 'thickness.require' => '额度不能为空',
  118. ]);
  119. if (!$validate->check($data)) {
  120. return Json::fail($validate->getError());
  121. }
  122. $details = $model->find($data['id']);
  123. $details['name'] = $data['name'];
  124. $details['thickness'] = $data['thickness'];
  125. $res = $details->save();
  126. if ($res) return Json::successful('修改成功');
  127. return Json::fail('修改失败');
  128. }
  129. /**
  130. * 显示创建资源表单页.
  131. *
  132. * @return \think\Response
  133. */
  134. public function next($id = 0)
  135. {
  136. $f = [];
  137. $f[] = Form::dateTime('add_time', '开启时间');
  138. $f[] = Form::dateTime('end_time', '结束时间');
  139. $f[] = Form::hidden('id', $id);
  140. $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
  141. $this->assign(compact('form'));
  142. return $this->fetch('public/form-builder');
  143. }
  144. public function next_save()
  145. {
  146. $model = new model;
  147. $data = Util::postMore([
  148. 'id',
  149. 'add_time',
  150. 'end_time',
  151. ]);
  152. $validate = Validate::rule([
  153. 'add_time' => 'require',
  154. 'end_time' => 'require',
  155. ]);
  156. $validate->message([
  157. 'add_time.require' => '请选择开启时间',
  158. 'end_time.require' => '请选择结束时间',
  159. ]);
  160. if (!$validate->check($data)) {
  161. return Json::fail($validate->getError());
  162. }
  163. $details = $model->find($data['id']);
  164. if ($details['status'] == 1) return Json::fail('未结束不能进行下一场');
  165. if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
  166. if (strtotime($data['end_time']) < strtotime($data['add_time'])) return Json::fail('结束时间不能小于开启时间');
  167. $details['stage'] += 1;
  168. $details['status'] = 1;
  169. $details['number'] = 0;//重置额度
  170. $details['money'] = intval($details['money'] * 1.3);//提搞额度130%
  171. $details['suc'] = 0;
  172. $details['add_time'] = strtotime($data['add_time']);
  173. $details['end_time'] = strtotime($data['end_time']);
  174. $res = $details->save();
  175. if ($res) return Json::successful('成功');
  176. return Json::fail('失败');
  177. }
  178. /**
  179. * 删除
  180. * @param $id
  181. * @return void
  182. * @throws \Exception
  183. */
  184. public function delete($id)
  185. {
  186. if (!$id) Json::fail('删除失败');
  187. $model = new model;
  188. $res = model::destroy($id);
  189. if ($res){
  190. return Json::success('删除成功!');
  191. }else{
  192. return Json::fail($model->getErrorInfo());
  193. }
  194. }
  195. }