PointPlan.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. namespace app\admin\controller\point_plan;
  3. use app\admin\controller\AuthController;
  4. use app\admin\model\system\SystemAttachment;
  5. use app\admin\model\system\SystemUserLevel;
  6. use Exception;
  7. use crmeb\services\{FormBuilder as Form,
  8. JsonService,
  9. UtilService as Util,
  10. JsonService as Json,
  11. UtilService
  12. };
  13. use FormBuilder\exception\FormBuilderException;
  14. use think\facade\Route as Url;
  15. use app\models\point_plan\{PointPlan as PointPlanModel, UserPointPlan};
  16. /**
  17. * 图文管理
  18. * Class WechatNews
  19. * @package app\admin\controller\wechat
  20. */
  21. class PointPlan extends AuthController
  22. {
  23. /**
  24. * TODO 显示后台管理员添加的图文
  25. * @return mixed
  26. * @throws Exception
  27. */
  28. public function index()
  29. {
  30. // $money_type = json_encode(sys_data('money_type'));
  31. // $this->assign(compact('money_type'));
  32. $this->assign('count_plan', PointPlanModel::count());
  33. return $this->fetch();
  34. }
  35. /**
  36. * 获取vote表
  37. *
  38. * @return void
  39. */
  40. public function get_list()
  41. {
  42. $where = Util::getMore([
  43. ['page', 1],
  44. ['limit', 20],
  45. ['title', ''],
  46. ['status', ''],
  47. ]);
  48. Json::successlayui(PointPlanModel::getList($where));
  49. }
  50. /**
  51. * 创建form表单
  52. *
  53. * @param int $id
  54. * @return string
  55. * @throws Exception
  56. * @throws FormBuilderException
  57. */
  58. public function create($id = 0)
  59. {
  60. $money_type = sys_data('money_type');
  61. $money_type_select = [];
  62. foreach ($money_type as $v) {
  63. $money_type_select[] = ['label' => $v['name'], 'value' => $v['code']];
  64. }
  65. if ($id) $info = PointPlanModel::get($id);
  66. $field[] = Form::input('plan_name', '计划标题', isset($info) ? $info->plan_name : '')->col(Form::col(24))->required();
  67. $field[] = Form::select('release_money_type', '释放币种', isset($info) ? $info->release_money_type : '')->options($money_type_select)->col(24)->required();
  68. $field[] = Form::select('buy_money_type', '认购币种', isset($info) ? $info->buy_money_type : '')->options($money_type_select)->col(24)->required();
  69. $field[] = Form::number('buy_num', '认购额度', isset($info) ? $info->buy_num : 0)->min(0)->col(24)->required();
  70. $field[] = Form::number('buy_price', '认购价格', isset($info) ? $info->buy_price : 0)->step(0.00000001)->col(24)->required();
  71. $field[] = Form::number('release_ratio', '收益倍数', isset($info) ? $info->release_ratio : 0)->min(0)->col(12)->step(0.01)->required();
  72. $field[] = Form::number('num', '节点名额', isset($info) ? $info->num : 0)->min(0)->col(12)->required();
  73. $field[] = Form::number('recommend_num', '考核推荐有效用户', isset($info) ? $info->recommend_num : 0)->min(0)->col(12)->required();
  74. $field[] = Form::number('group_num', '考核团队有效人数', isset($info) ? $info->group_num : 0)->min(0)->col(12)->required();
  75. $field[] = Form::number('exam_time', '考核期(天)', isset($info) ? $info->exam_time : 0)->min(0)->col(12)->required();
  76. $field[] = Form::number('layer_award_ratio', '团队奖比例', isset($info) ? $info->layer_award_ratio : 0)->min(0)->col(12)->required();
  77. $field[] = Form::number('layer_award_layer', '团队奖层数', isset($info) ? $info->layer_award_layer : 0)->min(0)->col(12)->required();
  78. $field[] = Form::number('release_day', '释放天数', isset($info) ? $info->release_day : 0)->min(0)->col(12)->required();
  79. $field[] = Form::dateTime('start_time', '开启认购时间', isset($info) ? date('Y-m-d H:i:s', $info->start_time) : '')->col(12);
  80. $form = Form::make_post_form('添加计划', $field, Url::buildUrl('save', ['id' => $id]), 2);
  81. $this->assign(compact('form'));
  82. return $this->fetch('public/form-builder');
  83. }
  84. /**
  85. * 添加或者修改
  86. * @param $id
  87. * @return void
  88. */
  89. public function save($id = 0)
  90. {
  91. $data = UtilService::postMore([
  92. ['plan_name', ''],
  93. ['release_money_type', ''],
  94. ['buy_money_type', ''],
  95. ['buy_num', 0],
  96. ['buy_price', 0],
  97. ['release_ratio', 0],
  98. ['num', 0],
  99. ['recommend_num', 0],
  100. ['group_num', 0],
  101. ['exam_time', 0],
  102. ['layer_award_ratio', 0],
  103. ['layer_award_layer', 0],
  104. ['release_day', ''],
  105. ['start_time', 0],
  106. ]);
  107. PointPlanModel::beginTrans();
  108. if (!$data['start_time']) {
  109. JsonService::fail('开启认购时间');
  110. }
  111. $data['start_time'] = strtotime($data['start_time']);
  112. try {
  113. //修改
  114. if ($id) {
  115. if (PointPlanModel::edit($data, $id)) {
  116. PointPlanModel::commitTrans();
  117. JsonService::successful('修改成功');
  118. } else {
  119. PointPlanModel::rollbackTrans();
  120. JsonService::fail('修改失败');
  121. }
  122. } else {
  123. //新增
  124. $data['add_time'] = time();
  125. $res = PointPlanModel::create($data);
  126. if ($res) {
  127. PointPlanModel::commitTrans();
  128. JsonService::successful('添加成功');
  129. } else {
  130. PointPlanModel::rollbackTrans();
  131. JsonService::fail('添加失败');
  132. }
  133. }
  134. } catch (\Exception $e) {
  135. PointPlanModel::rollbackTrans();
  136. JsonService::fail($e->getMessage());
  137. }
  138. }
  139. /**
  140. * 会员详情
  141. */
  142. public function see($id = '')
  143. {
  144. $this->assign([
  145. 'id' => $id,
  146. ]);
  147. return $this->fetch();
  148. }
  149. // /**
  150. // * 创建form表单
  151. // *
  152. // * @param int $id
  153. // * @return string
  154. // * @throws Exception
  155. // * @throws FormBuilderException
  156. // */
  157. // public function create_sub($id = 0, $vid = 0)
  158. // {
  159. // if (!$id && !$vid) {
  160. // $this->failed('参数异常');
  161. // }
  162. // if ($id) $info = VoteSub::get($id);
  163. // if (isset($info)) $vid = $info['vote_id'];
  164. //// var_dump($id);
  165. // $field[] = Form::hidden('vote_id', $vid);
  166. // $field[] = Form::input('vote_sub_name', '投票标题', isset($info) ? $info->vote_sub_name : '')->col(Form::col(24))->required();
  167. // $field[] = Form::number('vote_num', '投票数量', isset($info) ? $info->vote_num : 0)->min(0)->col(12)->step(0.00000001)->required();
  168. // $field[] = Form::number('max_vote_num', '个人投票上限', isset($info) ? $info->max_vote_num : 0)->min(0)->col(12)->step(0.00000001)->required();
  169. // $field[] = Form::dateTime('start_time', '开始时间', isset($info) ? date('Y-m-d H:i:s', $info->start_time) : '');
  170. // $field[] = Form::dateTime('end_time', '结束时间', isset($info) ? date('Y-m-d H:i:s', $info->end_time) : '');
  171. // if ((isset($info) && $info['status'] != 2 && $info['status'] != 3) || !isset($info))
  172. // $field[] = Form::radio('status', '状态', isset($info) ? $info->status : 0)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  173. // $form = Form::make_post_form('添加子投票', $field, Url::buildUrl('save_sub', ['id' => $id]), 2);
  174. // $this->assign(compact('form'));
  175. // return $this->fetch('public/form-builder');
  176. // }
  177. // /**
  178. // * 添加或者修改
  179. // * @param $id
  180. // * @return void
  181. // */
  182. // public function save_sub($id = 0)
  183. // {
  184. // $data = UtilService::postMore([
  185. // ['vote_sub_name', ''],
  186. // ['vote_id', ''],
  187. // ['vote_num', ''],
  188. // ['max_vote_num', ''],
  189. // ['end_time', ''],
  190. // ['start_time', ''],
  191. // ['status', 0],
  192. // ]);
  193. // VoteSub::beginTrans();
  194. // try {
  195. // if (!$data['vote_id']) JsonService::fail('请选择投票');
  196. // if (!$data['start_time']) JsonService::fail('请输入开始时间');
  197. // if (!$data['end_time']) JsonService::fail('请输入结束时间');
  198. // $data['start_time'] = strtotime($data['start_time']);
  199. // $data['end_time'] = strtotime($data['end_time']);
  200. // if ($data['end_time'] <= $data['start_time']) JsonService::fail('结束时间要大于开始时间');
  201. // if (!$id) $data['loop'] = VoteSub::where('vote_id', $data['vote_id'])->max('loop') + 1;
  202. // //修改
  203. // if ($id) {
  204. // if (VoteSub::edit($data, $id)) {
  205. // VoteSub::commitTrans();
  206. // JsonService::successful('修改成功');
  207. // } else {
  208. // VoteSub::rollbackTrans();
  209. // JsonService::fail('修改失败');
  210. // }
  211. // } else {
  212. // //新增
  213. // $data['add_time'] = time();
  214. // $res = VoteSub::create($data);
  215. // if ($res) {
  216. // VoteModel::commitTrans();
  217. // JsonService::successful('添加成功');
  218. // } else {
  219. // VoteModel::rollbackTrans();
  220. // JsonService::fail('添加失败');
  221. // }
  222. // }
  223. // } catch (\Exception $e) {
  224. // VoteModel::rollbackTrans();
  225. // JsonService::fail($e->getMessage());
  226. // }
  227. // }
  228. // public function see_people($id = 0)
  229. // {
  230. // $this->assign([
  231. // 'id' => $id,
  232. // ]);
  233. // return $this->fetch();
  234. // }
  235. //
  236. // public function people_list()
  237. // {
  238. // $where = Util::getMore([
  239. // ['page', 1],
  240. // ['limit', 20],
  241. // ['id', 0],
  242. // ]);
  243. // Json::successlayui(UserVote::getUserList($where));
  244. // }
  245. /**
  246. * 获取voteSub表
  247. *
  248. * @return void
  249. */
  250. public function get_sub_list()
  251. {
  252. $where = Util::getMore([
  253. ['page', 1],
  254. ['limit', 20],
  255. ['id', 0],
  256. ]);
  257. Json::successlayui(UserPointPlan::getList($where));
  258. }
  259. }