Many.php 8.5 KB

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