Many.php 9.0 KB

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