Many.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\many;
  8. use app\admin\controller\AuthController;
  9. use crmeb\repositories\OrderRepository;
  10. use crmeb\repositories\ShortLetterRepositories;
  11. use crmeb\services\{ExpressService,
  12. JsonService,
  13. JsonService as Json,
  14. MiniProgramService,
  15. WechatService,
  16. FormBuilder as Form,
  17. CacheService,
  18. UtilService as Util};
  19. use app\admin\model\ump\StorePink;
  20. use crmeb\basic\BaseModel;
  21. use think\facade\Route as Url;
  22. use crmeb\services\YLYService;
  23. use think\facade\Log;
  24. use think\facade\Validate;
  25. /**
  26. * 订单管理控制器 同一个订单表放在一个控制器
  27. * Class StoreOrder
  28. * @package app\admin\controller\store
  29. */
  30. class Many extends AuthController
  31. {
  32. /**
  33. * @return mixed
  34. */
  35. public function index()
  36. {
  37. return $this->fetch();
  38. }
  39. public function list()
  40. {
  41. $where = Util::getMore([
  42. ['status', ''],
  43. ['page', 1],
  44. ['limit', 20],
  45. ['name', '']
  46. ]);
  47. return Json::successlayui(\app\admin\model\many\Many::list($where));
  48. }
  49. /**
  50. * 显示创建资源表单页.
  51. *
  52. * @return \think\Response
  53. */
  54. public function create($id = 0)
  55. {
  56. $f = [];
  57. $f[] = Form::input('name', '名称')->col(12);
  58. // $f[] = Form::frameImageOne('image', '封面图(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
  59. $f[] = Form::input('money', '额度');
  60. $f[] = Form::input('increase', '自动增长额度', 0);
  61. $f[] = Form::input('second', '自动增长时间(秒)', 0);
  62. $f[] = Form::input('upper_limit', '参与上限');
  63. $f[] = Form::input('single', '单次上限');
  64. $f[] = Form::input('lower_limit', '单次下限');
  65. $f[] = Form::dateTime('add_time', '开启时间');
  66. $f[] = Form::dateTime('end_time', '结束时间');
  67. $f[] = Form::input('sort', '排序',0);
  68. if ($id) $f[] = Form::hidden('id', $id);
  69. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  70. $this->assign(compact('form'));
  71. return $this->fetch('public/form-builder');
  72. }
  73. public function save()
  74. {
  75. $model = new \app\admin\model\many\Many();
  76. $data = Util::postMore([
  77. 'name',
  78. // 'image',
  79. 'money',
  80. 'upper_limit',
  81. 'add_time',
  82. 'end_time',
  83. 'sort',
  84. 'increase',
  85. 'second',
  86. 'single',
  87. 'lower_limit'
  88. ]);
  89. $validate = Validate::rule('name', 'require')->rule([
  90. 'name' => 'require',
  91. // 'image' => 'require',
  92. 'money' => 'require',
  93. 'upper_limit' => 'require',
  94. 'add_time' => 'require',
  95. 'end_time' => 'require',
  96. 'single' => 'require',
  97. 'lower_limit' => 'require',
  98. ]);
  99. $validate->message([
  100. 'name.require' => '名称不能为空',
  101. // 'image.require' => '图片不能为空',
  102. 'money.require' => '额度不能为空',
  103. 'upper_limit.require' => '上限不能为空',
  104. 'add_time.require' => '请选择进场时间',
  105. 'end_time.require' => '请选择结束时间',
  106. 'single.require' => '请填写单次上限',
  107. 'lower_limit.require' => '请填写单次下限',
  108. ]);
  109. if (!$validate->check($data)) {
  110. return Json::fail($validate->getError());
  111. }
  112. $data['add_time'] = strtotime($data['add_time']);
  113. $data['end_time'] = strtotime($data['end_time']);
  114. $res = $model->save($data);
  115. if ($res) return Json::successful('添加成功');
  116. return Json::fail('添加失败');
  117. }
  118. /**
  119. * 显示创建资源表单页.
  120. *
  121. * @return \think\Response
  122. */
  123. public function edit($id = 0)
  124. {
  125. $data = \app\admin\model\many\Many::find($id);
  126. $f = [];
  127. $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
  128. // $f[] = Form::frameImageOne('image', '封面图(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  129. $f[] = Form::input('money', '额度', $data->getData('money'));
  130. $f[] = Form::input('increase', '自动增长额度', $data->getData('increase'));
  131. $f[] = Form::input('second', '自动增长时间(秒)', $data->getData('second'));
  132. $f[] = Form::input('upper_limit', '参与上限', $data->getData('upper_limit'));
  133. $f[] = Form::input('single', '单次上限', $data->getData('single'));
  134. $f[] = Form::input('lower_limit', '单次下限', $data->getData('lower_limit'));
  135. $f[] = Form::dateTime('add_time', '开启时间', date('Y-m-d H:i:s', $data->getData('add_time')));
  136. $f[] = Form::dateTime('end_time', '结束时间', date('Y-m-d H:i:s', $data->getData('end_time')));
  137. $f[] = Form::input('sort', '排序',$data->getData('sort'));
  138. $f[] = Form::hidden('id', $id);
  139. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  140. $this->assign(compact('form'));
  141. return $this->fetch('public/form-builder');
  142. }
  143. /**
  144. * 修改
  145. * @return void
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\DbException
  148. * @throws \think\db\exception\ModelNotFoundException
  149. */
  150. public function update()
  151. {
  152. $model = new \app\admin\model\many\Many();
  153. $data = Util::postMore([
  154. 'id',
  155. 'name',
  156. // 'image',
  157. 'money',
  158. 'upper_limit',
  159. 'add_time',
  160. 'end_time',
  161. 'sort',
  162. 'increase',
  163. 'second',
  164. 'single',
  165. 'lower_limit'
  166. ]);
  167. $validate = Validate::rule('name', 'require')->rule([
  168. 'name' => 'require',
  169. // 'image' => 'require',
  170. 'money' => 'require',
  171. 'upper_limit' => 'require',
  172. 'add_time' => 'require',
  173. 'end_time' => 'require',
  174. 'single' => 'require',
  175. 'lower_limit' => 'require',
  176. ]);
  177. $validate->message([
  178. 'name.require' => '名称不能为空',
  179. // 'image.require' => '图片不能为空',
  180. 'money.require' => '额度不能为空',
  181. 'upper_limit.require' => '上限不能为空',
  182. 'add_time.require' => '请选择进场时间',
  183. 'end_time.require' => '请选择结束时间',
  184. 'single.require' => '请填写单次上限',
  185. 'lower_limit.require' => '请填写单次下限',
  186. ]);
  187. if (!$validate->check($data)) {
  188. return Json::fail($validate->getError());
  189. }
  190. $details = $model->find($data['id']);
  191. $details['name'] = $data['name'];
  192. $details['single'] = $data['single'];
  193. $details['lower_limit'] = $data['lower_limit'];
  194. // $details['image'] = $data['image'];
  195. $details['money'] = $data['money'];
  196. $details['increase'] = $data['increase'];
  197. $details['second'] = $data['second'];
  198. $details['upper_limit'] = $data['upper_limit'];
  199. $details['add_time'] = strtotime($data['add_time']);
  200. $details['end_time'] = strtotime($data['end_time']);
  201. $details['sort'] = $data['sort'];
  202. $res = $details->save();
  203. if ($res) return Json::successful('修改成功');
  204. return Json::fail('修改失败');
  205. }
  206. /**
  207. * 显示创建资源表单页.
  208. *
  209. * @return \think\Response
  210. */
  211. public function next($id = 0)
  212. {
  213. $f = [];
  214. $f[] = Form::dateTime('add_time', '开启时间');
  215. $f[] = Form::dateTime('end_time', '结束时间');
  216. $f[] = Form::hidden('id', $id);
  217. $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
  218. $this->assign(compact('form'));
  219. return $this->fetch('public/form-builder');
  220. }
  221. public function next_save()
  222. {
  223. $model = new \app\admin\model\many\Many();
  224. $data = Util::postMore([
  225. 'id',
  226. 'add_time',
  227. 'end_time',
  228. ]);
  229. $validate = Validate::rule([
  230. 'add_time' => 'require',
  231. 'end_time' => 'require',
  232. ]);
  233. $validate->message([
  234. 'add_time.require' => '请选择开启时间',
  235. 'end_time.require' => '请选择结束时间',
  236. ]);
  237. if (!$validate->check($data)) {
  238. return Json::fail($validate->getError());
  239. }
  240. $details = $model->find($data['id']);
  241. if ($details['status'] == 1) return Json::fail('未结束不能进行下一场');
  242. if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
  243. if (strtotime($data['end_time']) < strtotime($data['add_time'])) return Json::fail('结束时间不能小于开启时间');
  244. $details['stage'] += 1;
  245. $details['status'] = 1;
  246. $details['number'] = 0;//重置额度
  247. $details['money'] = intval($details['money'] * 1.3);//提搞额度130%
  248. $details['suc'] = 0;
  249. $details['add_time'] = strtotime($data['add_time']);
  250. $details['end_time'] = strtotime($data['end_time']);
  251. $res = $details->save();
  252. if ($res) return Json::successful('成功');
  253. return Json::fail('失败');
  254. }
  255. /**
  256. * 删除
  257. * @param $id
  258. * @return void
  259. * @throws \Exception
  260. */
  261. public function delete($id)
  262. {
  263. if (!$id) Json::fail('删除失败');
  264. $model = new \app\admin\model\many\Many();
  265. $res = \app\admin\model\many\Many::destroy($id);
  266. if ($res){
  267. return Json::success('删除成功!');
  268. }else{
  269. return Json::fail($model->getErrorInfo());
  270. }
  271. }
  272. }