LalaPink.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. *
  4. * @author: wuhaotian<442384644@qq.com>
  5. * @day: 2019/12/07
  6. */
  7. namespace app\admin\controller\ump;
  8. use app\admin\controller\AuthController;
  9. use app\admin\model\user\UserGroup as GroupModel;
  10. use app\models\lala\LalaPinkJoin;
  11. use app\models\lala\LalaPinkLog;
  12. use crmeb\services\JsonService;
  13. use crmeb\services\UtilService;
  14. use crmeb\services\FormBuilder as Form;
  15. use Exception;
  16. use think\facade\Route as Url;
  17. /**
  18. * Class UserGroup
  19. * @package app\admin\controller\user
  20. */
  21. class LalaPink extends AuthController
  22. {
  23. /**
  24. * 会员分组页面
  25. * @return string
  26. */
  27. public function index()
  28. {
  29. return $this->fetch();
  30. }
  31. /**
  32. * 分组列表
  33. */
  34. public function groupList()
  35. {
  36. $where = UtilService::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ]);
  40. JsonService::successlayui(\app\models\lala\LalaPink::getList([], $where['page'], $where['limit']));
  41. }
  42. /**
  43. * 添加/修改分组页面
  44. * @param int $id
  45. * @return string
  46. * @throws Exception
  47. */
  48. public function addGroup(int $id = 0): string
  49. {
  50. $group = \app\models\lala\LalaPink::get($id);
  51. $f = array();
  52. $money_type = function () {
  53. $array = init_money_type();
  54. $new = [];
  55. foreach ($array as $v => $k) {
  56. $new[] = ['value' => $v, 'label' => $k];
  57. }
  58. return $new;
  59. };
  60. $f[] = Form::input('name', '活动名称', $group ? $group->getData('name') : '');
  61. $f[] = Form::frameImageOne('image', '会员背景', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), isset($group) ? $group->background_image : '')->icon('image')->width('100%')->height('500px');
  62. $f[] = Form::frameImages('imgs', '轮播图', Url::buildUrl('admin/widget.images/index', array('fodder' => 'imgs')), $group ? explode(',', $group->getData('imgs')) : [])->maxLength(5)->icon('image')->width('100%')->height('500px');
  63. $f[] = Form::number('cost', '支付', $group ? $group->getData('cost') : '')->min(0)->step(0.00000001);
  64. $f[] = Form::select('cost_money_type', '支付币种', $group ? $group->getData('cost_money_type') : '')->setOptions($money_type());
  65. $f[] = Form::number('cost_2', '币种2支付', $group ? $group->getData('cost_2') : '')->min(0)->step(0.00000001);
  66. $f[] = Form::select('cost_2_money_type', '支付币种2', $group ? $group->getData('cost_2_money_type') : '')->setOptions($money_type());
  67. $f[] = Form::number('bingo', '中奖', $group ? $group->getData('bingo') : '')->min(0)->step(0.00000001);
  68. $f[] = Form::select('bingo_money_type', '中奖币种', $group ? $group->getData('bingo_money_type') : '')->setOptions($money_type());
  69. $f[] = Form::number('ticket', '门票', $group ? $group->getData('ticket') : '')->min(0)->step(0.00000001);
  70. $f[] = Form::select('ticket_money_type', '门票币种', $group ? $group->getData('ticket_money_type') : '')->setOptions($money_type());
  71. $f[] = Form::number('join_award_ratio', '参与奖比例', $group ? $group->getData('join_award_ratio') : '')->min(0)->step(0.01);
  72. $f[] = Form::number('system_money_ratio', '系统奖池比例', $group ? $group->getData('system_money_ratio') : '')->min(0)->step(0.01);
  73. $f[] = Form::number('join_number', '参与人数', $group ? $group->getData('join_number') : '')->min(0)->step(1);
  74. $f[] = Form::number('bingo_number', '中奖人数', $group ? $group->getData('bingo_number') : '')->min(0)->step(1);
  75. $f[] = Form::number('join_limit', '每日参与次数限制', $group ? $group->getData('join_limit') : '')->min(0)->step(1);
  76. $f[] = Form::radio('status', '状态', $group ? (int)$group->getData('status') : 1)->setOptions([['label' => '关闭', 'value' => 0], ['label' => '开启', 'value' => 1]]);
  77. $f[] = Form::select('sp_exchange_origin', '特殊兑换源币种', $group ? $group->getData('sp_exchange_origin') : '')->setOptions($money_type());
  78. $f[] = Form::number('sp_exchange_origin_cost', '源值', $group ? $group->getData('sp_exchange_origin_cost') : '')->min(0)->step(0.00000001);
  79. $f[] = Form::select('sp_exchange_target', '特殊兑换目标币种', $group ? $group->getData('sp_exchange_target') : '')->setOptions($money_type());
  80. $f[] = Form::number('sp_exchange_target_get', '目标值', $group ? $group->getData('sp_exchange_target_get') : '')->min(0)->step(0.00000001);
  81. $f[] = Form::number('sp_exchange_bingo_time', '特殊兑换中奖次数', $group ? $group->getData('sp_exchange_bingo_time') : '')->min(0)->step(1);
  82. $f[] = Form::number('bingo_limit', '中奖前置拼团次数', $group ? $group->getData('bingo_limit') : '')->min(0)->step(1);
  83. $form = Form::make_post_form('添加活动', $f, Url::buildUrl('saveGroup', array('id' => $id)));
  84. $this->assign(compact('form'));
  85. return $this->fetch('public/form-builder');
  86. }
  87. /**
  88. * 添加/修改
  89. * @param int $id
  90. */
  91. public function saveGroup($id = 0)
  92. {
  93. // var_dump(111);
  94. $data = UtilService::postMore([
  95. ['name', ''],
  96. ['cost', ''],
  97. ['cost_2', ''],
  98. ['image', ''],
  99. ['cost_money_type', ''],
  100. ['cost_2_money_type', ''],
  101. ['bingo', ''],
  102. ['bingo_money_type', ''],
  103. ['ticket', ''],
  104. ['ticket_money_type', ''],
  105. ['join_award_ratio', ''],
  106. ['system_money_ratio', ''],
  107. ['join_number', ''],
  108. ['bingo_number', ''],
  109. ['join_limit', ''],
  110. ['status', 1],
  111. ['sp_exchange_origin', ''],
  112. ['sp_exchange_origin_cost', ''],
  113. ['sp_exchange_target', ''],
  114. ['sp_exchange_target_get', ''],
  115. ['sp_exchange_bingo_time', 0],
  116. ['bingo_limit', 0],
  117. ['imgs', []],
  118. ], $this->request);
  119. // var_dump($data);
  120. $data['background_image'] = $data['image'];
  121. unset($data['image']);
  122. $data['imgs'] = implode(',', $data['imgs']);
  123. if ($id) {
  124. if (\app\models\lala\LalaPink::where('id', $id)->update($data)) {
  125. JsonService::success('修改成功');
  126. } else {
  127. JsonService::fail('修改失败或者您没有修改什么!');
  128. }
  129. } else {
  130. $data['add_time'] = time();
  131. if ($res = \app\models\lala\LalaPink::create($data)) {
  132. JsonService::success('保存成功', ['id' => $res->id]);
  133. } else {
  134. JsonService::fail('保存失败!');
  135. }
  136. }
  137. }
  138. /**
  139. * @param $id
  140. * @return string|void
  141. * @throws \Exception
  142. */
  143. public function detail($id)
  144. {
  145. if (!$id) $this->failed('数据不存在');
  146. $info = \app\models\lala\LalaPink::get($id);
  147. if (!$info) $this->failed('数据不存在!');
  148. $this->assign([
  149. 'content' => htmlspecialchars_decode($info['detail']),
  150. 'field' => 'detail',
  151. 'action' => Url::buildUrl('change_field', ['id' => $id, 'field' => 'detail'])
  152. ]);
  153. return $this->fetch('public/edit_content');
  154. }
  155. /**
  156. * @param $id
  157. */
  158. public function change_field($id)
  159. {
  160. if (!$id) JsonService::fail('数据不存在');
  161. $seckill = \app\models\lala\LalaPink::get($id);
  162. if (!$seckill) JsonService::fail('数据不存在!');
  163. $data['detail'] = request()->post('detail');
  164. $res = \app\models\lala\LalaPink::edit($data, $id);
  165. if ($res)
  166. JsonService::successful('修改成功');
  167. else
  168. JsonService::fail('修改失败');
  169. }
  170. /**
  171. * 会员分组页面
  172. * @return string
  173. */
  174. public function join_index()
  175. {
  176. return $this->fetch();
  177. }
  178. /**
  179. * 分组列表
  180. */
  181. public function joinList()
  182. {
  183. $where = UtilService::getMore([
  184. ['id', ''],
  185. ['uid', ''],
  186. ['page', 1],
  187. ['limit', 20],
  188. ]);
  189. JsonService::successlayui(LalaPinkJoin::getListAdmin($where, $where['page'], $where['limit']));
  190. }
  191. /**
  192. * 添加/修改分组页面
  193. * @param int $id
  194. * @return string
  195. * @throws Exception
  196. */
  197. public function setStatus(int $id = 0): string
  198. {
  199. $group = LalaPinkJoin::get($id);
  200. if (!$group || !$id) $this->failed('找不到记录');
  201. if ($group['status'] != 0) $this->failed('记录已结算');
  202. $f = array();
  203. $f[] = Form::radio('set_status', '设置状态', $group['set_status'])->setOptions([['label' => '必中', 'value' => 1], ['label' => '失败', 'value' => 2], ['label' => '不设置', 'value' => 0]]);
  204. $form = Form::make_post_form('设置状态', $f, Url::buildUrl('saveStatus', array('id' => $id)));
  205. $this->assign(compact('form'));
  206. return $this->fetch('public/form-builder');
  207. }
  208. /**
  209. * 添加/修改
  210. * @param int $id
  211. */
  212. public function saveStatus($id = 0)
  213. {
  214. $data = UtilService::postMore([
  215. ['set_status', 1],
  216. ], $this->request);
  217. if ($id) {
  218. if (LalaPinkJoin::where('id', $id)->update($data)) {
  219. JsonService::success('修改成功');
  220. } else {
  221. JsonService::fail('修改失败或者您没有修改什么!');
  222. }
  223. } else {
  224. JsonService::fail('设置失败!');
  225. }
  226. }
  227. }