Many.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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::dateTime('add_time', '开启时间');
  65. $f[] = Form::dateTime('end_time', '结束时间');
  66. $f[] = Form::input('sort', '排序',0);
  67. if ($id) $f[] = Form::hidden('id', $id);
  68. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  69. $this->assign(compact('form'));
  70. return $this->fetch('public/form-builder');
  71. }
  72. public function save()
  73. {
  74. $model = new \app\admin\model\many\Many();
  75. $data = Util::postMore([
  76. 'name',
  77. // 'image',
  78. 'money',
  79. 'upper_limit',
  80. 'add_time',
  81. 'end_time',
  82. 'sort',
  83. 'increase',
  84. 'second',
  85. 'single',
  86. ]);
  87. $validate = Validate::rule('name', 'require')->rule([
  88. 'name' => 'require',
  89. // 'image' => 'require',
  90. 'money' => 'require',
  91. 'upper_limit' => 'require',
  92. 'add_time' => 'require',
  93. 'end_time' => 'require',
  94. 'single' => 'require',
  95. ]);
  96. $validate->message([
  97. 'name.require' => '名称不能为空',
  98. // 'image.require' => '图片不能为空',
  99. 'money.require' => '额度不能为空',
  100. 'upper_limit.require' => '上限不能为空',
  101. 'add_time.require' => '请选择进场时间',
  102. 'end_time.require' => '请选择结束时间',
  103. 'single.require' => '请填写单次上限',
  104. ]);
  105. if (!$validate->check($data)) {
  106. return Json::fail($validate->getError());
  107. }
  108. $data['add_time'] = strtotime($data['add_time']);
  109. $data['end_time'] = strtotime($data['end_time']);
  110. $res = $model->save($data);
  111. if ($res) return Json::successful('添加成功');
  112. return Json::fail('添加失败');
  113. }
  114. /**
  115. * 显示创建资源表单页.
  116. *
  117. * @return \think\Response
  118. */
  119. public function edit($id = 0)
  120. {
  121. $data = \app\admin\model\many\Many::find($id);
  122. $f = [];
  123. $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
  124. // $f[] = Form::frameImageOne('image', '封面图(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  125. $f[] = Form::input('money', '额度', $data->getData('money'));
  126. $f[] = Form::input('increase', '自动增长额度', $data->getData('increase'));
  127. $f[] = Form::input('second', '自动增长时间(秒)', $data->getData('second'));
  128. $f[] = Form::input('upper_limit', '参与上限', $data->getData('upper_limit'));
  129. $f[] = Form::input('single', '单次上限', $data->getData('single'));
  130. $f[] = Form::dateTime('add_time', '开启时间', date('Y-m-d H:i:s', $data->getData('add_time')));
  131. $f[] = Form::dateTime('end_time', '结束时间', date('Y-m-d H:i:s', $data->getData('end_time')));
  132. $f[] = Form::input('sort', '排序',$data->getData('sort'));
  133. $f[] = Form::hidden('id', $id);
  134. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  135. $this->assign(compact('form'));
  136. return $this->fetch('public/form-builder');
  137. }
  138. /**
  139. * 修改
  140. * @return void
  141. * @throws \think\db\exception\DataNotFoundException
  142. * @throws \think\db\exception\DbException
  143. * @throws \think\db\exception\ModelNotFoundException
  144. */
  145. public function update()
  146. {
  147. $model = new \app\admin\model\many\Many();
  148. $data = Util::postMore([
  149. 'id',
  150. 'name',
  151. // 'image',
  152. 'money',
  153. 'upper_limit',
  154. 'add_time',
  155. 'end_time',
  156. 'sort',
  157. 'increase',
  158. 'second',
  159. 'single'
  160. ]);
  161. $validate = Validate::rule('name', 'require')->rule([
  162. 'name' => 'require',
  163. // 'image' => 'require',
  164. 'money' => 'require',
  165. 'upper_limit' => 'require',
  166. 'add_time' => 'require',
  167. 'end_time' => 'require',
  168. 'single' => 'require',
  169. ]);
  170. $validate->message([
  171. 'name.require' => '名称不能为空',
  172. // 'image.require' => '图片不能为空',
  173. 'money.require' => '额度不能为空',
  174. 'upper_limit.require' => '上限不能为空',
  175. 'add_time.require' => '请选择进场时间',
  176. 'end_time.require' => '请选择结束时间',
  177. 'single.require' => '请填写单次上限',
  178. ]);
  179. if (!$validate->check($data)) {
  180. return Json::fail($validate->getError());
  181. }
  182. $details = $model->find($data['id']);
  183. $details['name'] = $data['name'];
  184. $details['single'] = $data['single'];
  185. // $details['image'] = $data['image'];
  186. $details['money'] = $data['money'];
  187. $details['increase'] = $data['increase'];
  188. $details['second'] = $data['second'];
  189. $details['upper_limit'] = $data['upper_limit'];
  190. $details['add_time'] = strtotime($data['add_time']);
  191. $details['end_time'] = strtotime($data['end_time']);
  192. $details['sort'] = $data['sort'];
  193. $res = $details->save();
  194. if ($res) return Json::successful('修改成功');
  195. return Json::fail('修改失败');
  196. }
  197. /**
  198. * 显示创建资源表单页.
  199. *
  200. * @return \think\Response
  201. */
  202. public function next($id = 0)
  203. {
  204. $f = [];
  205. $f[] = Form::dateTime('add_time', '开启时间');
  206. $f[] = Form::dateTime('end_time', '结束时间');
  207. $f[] = Form::hidden('id', $id);
  208. $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
  209. $this->assign(compact('form'));
  210. return $this->fetch('public/form-builder');
  211. }
  212. public function next_save()
  213. {
  214. $model = new \app\admin\model\many\Many();
  215. $data = Util::postMore([
  216. 'id',
  217. 'add_time',
  218. 'end_time',
  219. ]);
  220. $validate = Validate::rule([
  221. 'add_time' => 'require',
  222. 'end_time' => 'require',
  223. ]);
  224. $validate->message([
  225. 'add_time.require' => '请选择开启时间',
  226. 'end_time.require' => '请选择结束时间',
  227. ]);
  228. if (!$validate->check($data)) {
  229. return Json::fail($validate->getError());
  230. }
  231. $details = $model->find($data['id']);
  232. if ($details['status'] == 1) return Json::fail('未结束不能进行下一场');
  233. if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
  234. if (strtotime($data['end_time']) < strtotime($data['add_time'])) return Json::fail('结束时间不能小于开启时间');
  235. $details['stage'] += 1;
  236. $details['status'] = 1;
  237. $details['number'] = 0;//重置额度
  238. $details['money'] = intval($details['money'] * 1.3);//提搞额度130%
  239. $details['suc'] = 0;
  240. $details['add_time'] = strtotime($data['add_time']);
  241. $details['end_time'] = strtotime($data['end_time']);
  242. $res = $details->save();
  243. if ($res) return Json::successful('成功');
  244. return Json::fail('失败');
  245. }
  246. /**
  247. * 删除
  248. * @param $id
  249. * @return void
  250. * @throws \Exception
  251. */
  252. public function delete($id)
  253. {
  254. if (!$id) Json::fail('删除失败');
  255. $model = new \app\admin\model\many\Many();
  256. $res = \app\admin\model\many\Many::destroy($id);
  257. if ($res){
  258. return Json::success('删除成功!');
  259. }else{
  260. return Json::fail($model->getErrorInfo());
  261. }
  262. }
  263. }