PointPlan.php 11 KB

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