LuckDraw.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\luck;
  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 LuckDraw 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\luck\LuckDraw::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\luck\LuckDraw::find($id);
  126. $f = [];
  127. $f[] = Form::input('title', '名称',$data->getData('title'))->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('count', '数量', $data->getData('count'));
  130. $f[] = Form::input('price', '价格', $data->getData('price'));
  131. $f[] = Form::input('probability', '概率', $data->getData('probability'));
  132. $f[] = Form::hidden('id', $id);
  133. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  134. $this->assign(compact('form'));
  135. return $this->fetch('public/form-builder');
  136. }
  137. /**
  138. * 修改
  139. * @return void
  140. * @throws \think\db\exception\DataNotFoundException
  141. * @throws \think\db\exception\DbException
  142. * @throws \think\db\exception\ModelNotFoundException
  143. */
  144. public function update()
  145. {
  146. $model = new \app\admin\model\luck\LuckDraw();
  147. $data = Util::postMore([
  148. 'id',
  149. 'title',
  150. // 'image',
  151. 'count',
  152. 'price',
  153. 'probability',
  154. ]);
  155. $validate = Validate::rule([
  156. 'title' => 'require',
  157. // 'image' => 'require',
  158. 'count' => 'require',
  159. 'price' => 'require',
  160. 'probability' => 'require',
  161. ]);
  162. $validate->message([
  163. 'title.require' => '名称不能为空',
  164. // 'image.require' => '图片不能为空',
  165. 'count.require' => '数量不能为空',
  166. 'price.require' => '价格不能为空',
  167. 'probability.require' => '请填写概率',
  168. ]);
  169. if (!$validate->check($data)) {
  170. return Json::fail($validate->getError());
  171. }
  172. $details = $model->find($data['id']);
  173. $details['title'] = $data['title'];
  174. $details['count'] = $data['count'];
  175. $details['price'] = $data['price'];
  176. $details['probability'] = $data['probability'];
  177. $res = $details->save();
  178. if ($res) return Json::successful('修改成功');
  179. return Json::fail('修改失败');
  180. }
  181. /**
  182. * 显示创建资源表单页.
  183. *
  184. * @return \think\Response
  185. */
  186. public function next($id = 0)
  187. {
  188. $f = [];
  189. $f[] = Form::dateTime('add_time', '开启时间');
  190. $f[] = Form::dateTime('end_time', '结束时间');
  191. $f[] = Form::hidden('id', $id);
  192. $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
  193. $this->assign(compact('form'));
  194. return $this->fetch('public/form-builder');
  195. }
  196. public function next_save()
  197. {
  198. $model = new \app\admin\model\many\Many();
  199. $data = Util::postMore([
  200. 'id',
  201. 'add_time',
  202. 'end_time',
  203. ]);
  204. $validate = Validate::rule([
  205. 'add_time' => 'require',
  206. 'end_time' => 'require',
  207. ]);
  208. $validate->message([
  209. 'add_time.require' => '请选择开启时间',
  210. 'end_time.require' => '请选择结束时间',
  211. ]);
  212. if (!$validate->check($data)) {
  213. return Json::fail($validate->getError());
  214. }
  215. $details = $model->find($data['id']);
  216. if ($details['status'] == 1) return Json::fail('未结束不能进行下一场');
  217. if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
  218. if (strtotime($data['end_time']) < strtotime($data['add_time'])) return Json::fail('结束时间不能小于开启时间');
  219. $details['stage'] += 1;
  220. $details['status'] = 1;
  221. $details['number'] = 0;//重置额度
  222. $details['money'] = intval($details['money'] * 1.3);//提搞额度130%
  223. $details['suc'] = 0;
  224. $details['add_time'] = strtotime($data['add_time']);
  225. $details['end_time'] = strtotime($data['end_time']);
  226. $res = $details->save();
  227. if ($res) return Json::successful('成功');
  228. return Json::fail('失败');
  229. }
  230. /**
  231. * 删除
  232. * @param $id
  233. * @return void
  234. * @throws \Exception
  235. */
  236. public function delete($id)
  237. {
  238. if (!$id) Json::fail('删除失败');
  239. $model = new \app\admin\model\many\Many();
  240. $res = \app\admin\model\many\Many::destroy($id);
  241. if ($res){
  242. return Json::success('删除成功!');
  243. }else{
  244. return Json::fail($model->getErrorInfo());
  245. }
  246. }
  247. }