|
@@ -0,0 +1,220 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author: xaboy<365615158@qq.com>
|
|
|
+ * @day: 2017/11/11
|
|
|
+ */
|
|
|
+
|
|
|
+namespace app\admin\controller\water;
|
|
|
+
|
|
|
+use app\admin\controller\AuthController;
|
|
|
+use crmeb\services\{ExpressService,
|
|
|
+ JsonService,
|
|
|
+ JsonService as Json,
|
|
|
+ MiniProgramService,
|
|
|
+ WechatService,
|
|
|
+ FormBuilder as Form,
|
|
|
+ CacheService,
|
|
|
+ UtilService as Util};
|
|
|
+use think\facade\Route as Url;
|
|
|
+use think\facade\Validate;
|
|
|
+Use app\admin\model\water\WaterMaterialScience as model;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订单管理控制器 同一个订单表放在一个控制器
|
|
|
+ * Class StoreOrder
|
|
|
+ * @package app\admin\controller\store
|
|
|
+ */
|
|
|
+class WaterMaterialScience extends AuthController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
+ $where = Util::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ['limit', 20],
|
|
|
+ ['name', '']
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return Json::successlayui(model::list($where));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示创建资源表单页.
|
|
|
+ *
|
|
|
+ * @return \think\Response
|
|
|
+ */
|
|
|
+ public function create($id = 0)
|
|
|
+ {
|
|
|
+ $f = [];
|
|
|
+ $f[] = Form::input('name', '名称')->col(12);
|
|
|
+ $f[] = Form::input('weight', '重量');
|
|
|
+ if ($id) $f[] = Form::hidden('id', $id);
|
|
|
+ $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
|
|
|
+ $this->assign(compact('form'));
|
|
|
+ return $this->fetch('public/form-builder');
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function save()
|
|
|
+ {
|
|
|
+ $model = new model;
|
|
|
+ $data = Util::postMore([
|
|
|
+ 'name',
|
|
|
+ 'thickness',
|
|
|
+ ]);
|
|
|
+ $validate = Validate::rule('name', 'require')->rule([
|
|
|
+ 'name' => 'require',
|
|
|
+ 'thickness' => 'require',
|
|
|
+ ]);
|
|
|
+ $validate->message([
|
|
|
+ 'name.require' => '名称不能为空',
|
|
|
+ 'thickness.require' => '厚度不能为空',
|
|
|
+ ]);
|
|
|
+ if (!$validate->check($data)) {
|
|
|
+ return Json::fail($validate->getError());
|
|
|
+ }
|
|
|
+ $res = $model->save($data);
|
|
|
+ if ($res) return Json::successful('添加成功');
|
|
|
+ return Json::fail('添加失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示创建资源表单页.
|
|
|
+ *
|
|
|
+ * @return \think\Response
|
|
|
+ */
|
|
|
+ public function edit($id = 0)
|
|
|
+ {
|
|
|
+ $data = model::find($id);
|
|
|
+ $f = [];
|
|
|
+ $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
|
|
|
+ $f[] = Form::input('thickness', '额度', $data->getData('thickness'));
|
|
|
+ $f[] = Form::hidden('id', $id);
|
|
|
+ $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
|
|
|
+ $this->assign(compact('form'));
|
|
|
+ return $this->fetch('public/form-builder');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function update()
|
|
|
+ {
|
|
|
+ $model = new model;
|
|
|
+ $data = Util::postMore([
|
|
|
+ 'id',
|
|
|
+ 'name',
|
|
|
+ 'thickness',
|
|
|
+ ]);
|
|
|
+ $validate = Validate::rule('name', 'require')->rule([
|
|
|
+ 'name' => 'require',
|
|
|
+ 'thickness' => 'require',
|
|
|
+ ]);
|
|
|
+ $validate->message([
|
|
|
+ 'name.require' => '名称不能为空',
|
|
|
+ 'thickness.require' => '额度不能为空',
|
|
|
+ ]);
|
|
|
+ if (!$validate->check($data)) {
|
|
|
+ return Json::fail($validate->getError());
|
|
|
+ }
|
|
|
+ $details = $model->find($data['id']);
|
|
|
+ $details['name'] = $data['name'];
|
|
|
+ $details['thickness'] = $data['thickness'];
|
|
|
+ $res = $details->save();
|
|
|
+ if ($res) return Json::successful('修改成功');
|
|
|
+ return Json::fail('修改失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示创建资源表单页.
|
|
|
+ *
|
|
|
+ * @return \think\Response
|
|
|
+ */
|
|
|
+ public function next($id = 0)
|
|
|
+ {
|
|
|
+ $f = [];
|
|
|
+ $f[] = Form::dateTime('add_time', '开启时间');
|
|
|
+ $f[] = Form::dateTime('end_time', '结束时间');
|
|
|
+ $f[] = Form::hidden('id', $id);
|
|
|
+ $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
|
|
|
+ $this->assign(compact('form'));
|
|
|
+ return $this->fetch('public/form-builder');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function next_save()
|
|
|
+ {
|
|
|
+ $model = new model;
|
|
|
+ $data = Util::postMore([
|
|
|
+ 'id',
|
|
|
+ 'add_time',
|
|
|
+ 'end_time',
|
|
|
+ ]);
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'add_time' => 'require',
|
|
|
+ 'end_time' => 'require',
|
|
|
+ ]);
|
|
|
+ $validate->message([
|
|
|
+ 'add_time.require' => '请选择开启时间',
|
|
|
+ 'end_time.require' => '请选择结束时间',
|
|
|
+ ]);
|
|
|
+ if (!$validate->check($data)) {
|
|
|
+ return Json::fail($validate->getError());
|
|
|
+ }
|
|
|
+ $details = $model->find($data['id']);
|
|
|
+ if ($details['status'] == 1) return Json::fail('未结束不能进行下一场');
|
|
|
+ if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
|
|
|
+ if (strtotime($data['end_time']) < strtotime($data['add_time'])) return Json::fail('结束时间不能小于开启时间');
|
|
|
+ $details['stage'] += 1;
|
|
|
+ $details['status'] = 1;
|
|
|
+ $details['number'] = 0;//重置额度
|
|
|
+ $details['money'] = intval($details['money'] * 1.3);//提搞额度130%
|
|
|
+ $details['suc'] = 0;
|
|
|
+ $details['add_time'] = strtotime($data['add_time']);
|
|
|
+ $details['end_time'] = strtotime($data['end_time']);
|
|
|
+ $res = $details->save();
|
|
|
+ if ($res) return Json::successful('成功');
|
|
|
+ return Json::fail('失败');
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @param $id
|
|
|
+ * @return void
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public function delete($id)
|
|
|
+ {
|
|
|
+ if (!$id) Json::fail('删除失败');
|
|
|
+ $model = new model;
|
|
|
+
|
|
|
+ $res = model::destroy($id);
|
|
|
+ if ($res){
|
|
|
+ return Json::success('删除成功!');
|
|
|
+ }else{
|
|
|
+ return Json::fail($model->getErrorInfo());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|