Activity.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace app\admin\controller\ump;
  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;
  16. use think\facade\Route as Url;
  17. use app\models\activity\{Activity as ActivityModel, ActivityJoin};
  18. /**
  19. * 图文管理
  20. * Class WechatNews
  21. * @package app\admin\controller\wechat
  22. */
  23. class Activity extends AuthController
  24. {
  25. /**
  26. * TODO 显示后台管理员添加的图文
  27. * @return mixed
  28. * @throws Exception
  29. */
  30. public function index()
  31. {
  32. $this->assign('count_plan', ActivityModel::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. ]);
  46. Json::successlayui(ActivityModel::getList((int)$where['page'], (int)$where['limit']));
  47. }
  48. /**
  49. * 创建form表单
  50. *
  51. * @param int $id
  52. * @return string
  53. * @throws Exception
  54. * @throws FormBuilderException
  55. */
  56. public function create($id = 0)
  57. {
  58. $money_type = sys_data('money_type');
  59. $money_type_select = [];
  60. foreach ($money_type as $v) {
  61. $money_type_select[] = ['label' => $v['name'], 'value' => $v['code']];
  62. }
  63. if ($id) $info = ActivityJoin::get($id);
  64. $field[] = Form::input('name', '活动标题', isset($info) ? $info->name : '')->col(Form::col(24))->required();
  65. $field[] = Form::number('l1_money', '一级缴纳', isset($info) ? $info->l1_money : '')->step(0.00000001)->col(12)->required();
  66. $field[] = Form::select('l1_money_type', '缴纳币种', isset($info) ? $info->l1_money_type : '')->options($money_type_select)->col(12)->required();
  67. $field[] = Form::number('l2_money', '二级缴纳', isset($info) ? $info->l2_money : '')->step(0.00000001)->col(12)->required();
  68. $field[] = Form::select('l2_money_type', '缴纳币种', isset($info) ? $info->l2_money_type : '')->options($money_type_select)->col(12)->required();
  69. $field[] = Form::number('l3_money', '三级缴纳', isset($info) ? $info->l3_money : '')->step(0.00000001)->col(12)->required();
  70. $field[] = Form::select('l3_money_type', '缴纳币种', isset($info) ? $info->l3_money_type : '')->options($money_type_select)->col(12)->required();
  71. $field[] = Form::number('explode_num', '分裂人数', isset($info) ? $info->explode_num : 0)->min(0)->step(1)->col(12)->required();
  72. $field[] = Form::radio('group_type', '活动类型', isset($info) ? $info->group_type : 0)->options([['label' => '小公排', 'value' => 0], ['label' => '大公排', 'value' => 1]])->col(12)->required();
  73. $form = Form::make_post_form('添加计划', $field, Url::buildUrl('save', ['id' => $id]), 2);
  74. $this->assign(compact('form'));
  75. return $this->fetch('public/form-builder');
  76. }
  77. /**
  78. * 添加或者修改
  79. * @param $id
  80. * @return void
  81. */
  82. public function save($id = 0)
  83. {
  84. $data = UtilService::postMore([
  85. ['name', ''],
  86. ['l1_money', ''],
  87. ['l1_money_type', 0],
  88. ['l2_money', ''],
  89. ['l2_money_type', 0],
  90. ['l3_money', ''],
  91. ['l3_money_type', 0],
  92. ['group_type', 0],
  93. ['explode_num', ''],
  94. ]);
  95. ActivityModel::beginTrans();
  96. try {
  97. //修改
  98. if ($id) {
  99. if (ActivityModel::edit($data, $id)) {
  100. ActivityModel::commitTrans();
  101. JsonService::successful('修改成功');
  102. } else {
  103. ActivityModel::rollbackTrans();
  104. JsonService::fail('修改失败');
  105. }
  106. } else {
  107. //新增
  108. $res = ActivityModel::create($data);
  109. if ($res) {
  110. ActivityModel::commitTrans();
  111. JsonService::successful('添加成功');
  112. } else {
  113. ActivityModel::rollbackTrans();
  114. JsonService::fail('添加失败');
  115. }
  116. }
  117. } catch (\Exception $e) {
  118. ActivityModel::rollbackTrans();
  119. JsonService::fail($e->getMessage());
  120. }
  121. }
  122. /**
  123. * 会员详情
  124. */
  125. public function see($id = '')
  126. {
  127. $this->assign([
  128. 'id' => $id,
  129. ]);
  130. return $this->fetch();
  131. }
  132. /**
  133. * 获取voteSub表
  134. *
  135. * @return void
  136. */
  137. public function get_sub_list()
  138. {
  139. $where = Util::getMore([
  140. ['page', 1],
  141. ['limit', 20],
  142. ['id', 0],
  143. ]);
  144. Json::successlayui(ActivityJoin::getList($where));
  145. }
  146. /**
  147. * @param $id
  148. * @return string|void
  149. * @throws \Exception
  150. */
  151. public function detail($id)
  152. {
  153. if (!$id) $this->failed('数据不存在');
  154. $info = ActivityModel::get($id);
  155. if (!$info) $this->failed('数据不存在!');
  156. $this->assign([
  157. 'content' => htmlspecialchars_decode($info['content']),
  158. 'field' => 'detail',
  159. 'action' => Route::buildUrl('change_field', ['id' => $id, 'field' => 'detail'])
  160. ]);
  161. return $this->fetch('public/edit_content');
  162. }
  163. /**
  164. * @param $id
  165. */
  166. public function change_field($id)
  167. {
  168. if (!$id) JsonService::fail('数据不存在');
  169. $seckill = ActivityModel::get($id);
  170. if (!$seckill) JsonService::fail('数据不存在!');
  171. $data['content'] = request()->post('detail');
  172. $res = ActivityModel::edit($data, $id);
  173. if ($res)
  174. JsonService::successful('修改成功');
  175. else
  176. JsonService::fail('修改失败');
  177. }
  178. }