ManyGreen.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 app\models\user\User;
  10. use crmeb\repositories\OrderRepository;
  11. use crmeb\repositories\ShortLetterRepositories;
  12. use crmeb\services\{ExpressService,
  13. JsonService,
  14. JsonService as Json,
  15. MiniProgramService,
  16. WechatService,
  17. FormBuilder as Form,
  18. CacheService,
  19. UtilService as Util};
  20. use app\admin\model\ump\StorePink;
  21. use crmeb\basic\BaseModel;
  22. use think\facade\Route as Url;
  23. use crmeb\services\YLYService;
  24. use think\facade\Log;
  25. use think\facade\Validate;
  26. /**
  27. * 订单管理控制器 同一个订单表放在一个控制器
  28. * Class StoreOrder
  29. * @package app\admin\controller\store
  30. */
  31. class ManyGreen extends AuthController
  32. {
  33. /**
  34. * @return mixed
  35. */
  36. public function index()
  37. {
  38. return $this->fetch();
  39. }
  40. public function list()
  41. {
  42. $where = Util::getMore([
  43. ['status', ''],
  44. ['page', 1],
  45. ['limit', 20],
  46. ['name', '']
  47. ]);
  48. return Json::successlayui(\app\admin\model\many\ManyGreen::list($where));
  49. }
  50. /**
  51. * 显示创建资源表单页.
  52. *
  53. * @return \think\Response
  54. */
  55. public function create($id = 0)
  56. {
  57. $f = [];
  58. $f[] = Form::select('uid', '赠送用户')->setOptions(function () {
  59. $model = new User();
  60. $list = $model->select();
  61. $menus = [];
  62. foreach ($list as $menu) {
  63. $menus[] = ['value' => $menu['uid'], 'label' => $menu['nickname']];
  64. }
  65. return $menus;
  66. })->filterable(1);
  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\ManyGreen();
  74. $data = Util::postMore([
  75. 'uid',
  76. ]);
  77. $validate = Validate::rule([
  78. 'uid' => 'require',
  79. ]);
  80. $validate->message([
  81. 'uid.require' => '赠送用户不能为空',
  82. ]);
  83. if (!$validate->check($data)) {
  84. return Json::fail($validate->getError());
  85. }
  86. $res = $model->save(['uid' => $data['uid'], 'type' => 2]);
  87. if ($res) return Json::successful('赠送成功');
  88. return Json::fail('赠送失败');
  89. }
  90. /**
  91. * 显示创建资源表单页.
  92. *
  93. * @return \think\Response
  94. */
  95. public function edit($id = 0)
  96. {
  97. $data = \app\admin\model\many\Many::find($id);
  98. $f = [];
  99. $f[] = Form::input('name', '名称',$data->getData('name'))->col(12);
  100. $f[] = Form::frameImageOne('image', '封面图(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
  101. $f[] = Form::input('money', '额度', $data->getData('money'));
  102. $f[] = Form::input('number', '数量',$data->getData('number'));
  103. $f[] = Form::dateTime('add_time', '开启时间', date('Y-m-d H:i:s', $data->getData('add_time')));
  104. $f[] = Form::dateTime('end_time', '结束时间', date('Y-m-d H:i:s', $data->getData('end_time')));
  105. $f[] = Form::input('sort', '排序',$data->getData('sort'));
  106. $f[] = Form::hidden('id', $id);
  107. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  108. $this->assign(compact('form'));
  109. return $this->fetch('public/form-builder');
  110. }
  111. /**
  112. * 修改
  113. * @return void
  114. * @throws \think\db\exception\DataNotFoundException
  115. * @throws \think\db\exception\DbException
  116. * @throws \think\db\exception\ModelNotFoundException
  117. */
  118. public function update()
  119. {
  120. $model = new \app\admin\model\many\Many();
  121. $data = Util::postMore([
  122. 'id',
  123. 'name',
  124. 'image',
  125. 'money',
  126. 'number',
  127. 'add_time',
  128. 'end_time',
  129. 'sort',
  130. ]);
  131. $validate = Validate::rule('name', 'require')->rule([
  132. 'name' => 'require',
  133. 'image' => 'require',
  134. 'money' => 'require',
  135. 'number' => 'require',
  136. 'add_time' => 'require',
  137. 'end_time' => 'require',
  138. ]);
  139. $validate->message([
  140. 'name.require' => '名称不能为空',
  141. 'image.require' => '图片不能为空',
  142. 'money.require' => '额度不能为空',
  143. 'number.require' => '数量不能为空',
  144. 'add_time.require' => '请选择进场时间',
  145. 'end_time.require' => '请选择结束时间',
  146. ]);
  147. if (!$validate->check($data)) {
  148. return Json::fail($validate->getError());
  149. }
  150. $details = $model->find($data['id']);
  151. $details['name'] = $data['name'];
  152. $details['image'] = $data['image'];
  153. $details['money'] = $data['money'];
  154. $details['number'] = $data['number'];
  155. $details['add_time'] = strtotime($data['add_time']);
  156. $details['end_time'] = strtotime($data['end_time']);
  157. $details['sort'] = $data['sort'];
  158. $res = $details->save();
  159. if ($res) return Json::successful('添加成功');
  160. return Json::fail('添加失败');
  161. }
  162. /**
  163. * 显示创建资源表单页.
  164. *
  165. * @return \think\Response
  166. */
  167. public function next($id = 0)
  168. {
  169. $f = [];
  170. $f[] = Form::dateTime('add_time', '开启时间');
  171. $f[] = Form::dateTime('end_time', '结束时间');
  172. $f[] = Form::hidden('id', $id);
  173. $form = Form::make_post_form('添加', $f, Url::buildUrl('next_save'));
  174. $this->assign(compact('form'));
  175. return $this->fetch('public/form-builder');
  176. }
  177. public function next_save()
  178. {
  179. $model = new \app\admin\model\many\Many();
  180. $data = Util::postMore([
  181. 'id',
  182. 'add_time',
  183. 'end_time',
  184. ]);
  185. $validate = Validate::rule([
  186. 'add_time' => 'require',
  187. 'end_time' => 'require',
  188. ]);
  189. $validate->message([
  190. 'add_time.require' => '请选择进场时间',
  191. 'end_time.require' => '请选择结束时间',
  192. ]);
  193. if (!$validate->check($data)) {
  194. return Json::fail($validate->getError());
  195. }
  196. $details = $model->find($data['id']);
  197. if ($details['end_time'] > time() or $details['status'] == 1) return Json::fail('未结束不能进行下一场');
  198. if ($details['suc'] == 2) return Json::fail('已众筹失败无法就行下一场');
  199. $details['stage'] += 1;
  200. $details['status'] = 1;
  201. $details['add_time'] = strtotime($data['add_time']);
  202. $details['end_time'] = strtotime($data['end_time']);
  203. $res = $details->save();
  204. if ($res) return Json::successful('成功');
  205. return Json::fail('失败');
  206. }
  207. /**
  208. * 删除
  209. * @param $id
  210. * @return void
  211. * @throws \Exception
  212. */
  213. public function delete($id)
  214. {
  215. if (!$id) Json::fail('删除失败');
  216. $model = new \app\admin\model\many\Many();
  217. $res = $model->where('id', $id)->delete();
  218. if ($res){
  219. return Json::success('删除成功!');
  220. }else{
  221. return Json::fail($model->getErrorInfo());
  222. }
  223. }
  224. }