LuckOrder.php 8.3 KB

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