AutoPink.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace app\admin\controller\ump;
  3. use app\admin\controller\AuthController;
  4. use think\facade\Route as Url;
  5. use crmeb\traits\CurdControllerTrait;
  6. use app\admin\model\user\UserLevel as UserLevelModel;
  7. use app\admin\model\system\{SystemUserLevel, SystemUserTask};
  8. use crmeb\services\{UtilService, JsonService, FormBuilder as Form};
  9. /**
  10. * 会员设置
  11. * Class UserLevel
  12. * @package app\admin\controller\user
  13. */
  14. class AutoPink extends AuthController
  15. {
  16. use CurdControllerTrait;
  17. /*
  18. * 等级展示
  19. * */
  20. public function index()
  21. {
  22. return $this->fetch();
  23. }
  24. /*
  25. * 创建form表单
  26. * */
  27. public function create($id = 0)
  28. {
  29. $money_type = function () {
  30. $array = init_money_type();
  31. $new = [];
  32. foreach ($array as $v => $k) {
  33. $new[] = ['value' => $v, 'label' => $k];
  34. }
  35. return $new;
  36. };
  37. $lala = function () {
  38. return \app\models\lala\LalaPink::validWhere()->field('id as value,name as label')->select()->toArray();
  39. };
  40. if ($id) $vipinfo = \app\models\lala\AutoPink::get($id);
  41. $field[] = Form::input('name', '服务名称', isset($vipinfo) ? $vipinfo->name : '')->col(Form::col(24));
  42. $field[] = Form::select('lala_id', '适用活动', isset($vipinfo) ? explode(',', $vipinfo->lala_id) : [])->options($lala())->filterable(true)->multiple(true)->col(24);
  43. $field[] = Form::radio('is_forever', '是否为永久', isset($vipinfo) ? $vipinfo->is_forever : 0)->options([['label' => '永久', 'value' => 1], ['label' => '非永久', 'value' => 0]])->col(24);
  44. $field[] = Form::number('valid_date', '有效时间(天)', isset($vipinfo) ? $vipinfo->valid_date : 0)->min(0)->col(24);
  45. $field[] = Form::number('money', '开通价格', isset($vipinfo) ? $vipinfo->money : 0)->step(0.00000001)->col(12);
  46. $field[] = Form::select('money_type', '开通币种', isset($vipinfo) ? $vipinfo->money_type : 0)->options($money_type())->col(8);
  47. $field[] = Form::radio('is_show', '是否显示', isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])->col(8);
  48. $form = Form::make_post_form('添加自动拼购服务', $field, Url::buildUrl('save', ['id' => $id]), 2);
  49. $this->assign(compact('form'));
  50. return $this->fetch('public/form-builder');
  51. }
  52. /*
  53. * 会员等级添加或者修改
  54. * @param $id 修改的等级id
  55. * @return json
  56. * */
  57. public function save($id = 0)
  58. {
  59. $data = UtilService::postMore([
  60. ['name', ''],
  61. ['is_forever', 1],
  62. ['money', 0],
  63. ['money_type', ''],
  64. ['valid_date', 0],
  65. ['lala_id', []],
  66. ['is_show', ''],
  67. ]);
  68. if (!$data['name']) JsonService::fail('请输入业务名称');
  69. if ($data['is_forever'] == 0 && !$data['valid_date']) JsonService::fail('请输入有效时间(天)');
  70. if (!$data['money_type'] || !$data['money']) JsonService::fail('请输入开通价格');
  71. $data['lala_id'] = implode(',', $data['lala_id']);
  72. \app\models\lala\AutoPink::beginTrans();
  73. try {
  74. //修改
  75. if ($id) {
  76. if (\app\models\lala\AutoPink::edit($data, $id)) {
  77. \app\models\lala\AutoPink::commitTrans();
  78. JsonService::successful('修改成功');
  79. } else {
  80. \app\models\lala\AutoPink::rollbackTrans();
  81. JsonService::fail('修改失败');
  82. }
  83. } else {
  84. //新增
  85. $data['add_time'] = time();
  86. if (\app\models\lala\AutoPink::create($data)) {
  87. \app\models\lala\AutoPink::commitTrans();
  88. JsonService::successful('添加成功');
  89. } else {
  90. \app\models\lala\AutoPink::rollbackTrans();
  91. JsonService::fail('添加失败');
  92. }
  93. }
  94. } catch (\Exception $e) {
  95. \app\models\lala\AutoPink::rollbackTrans();
  96. JsonService::fail($e->getMessage());
  97. }
  98. }
  99. /*
  100. * 获取系统设置的vip列表
  101. * @param int page
  102. * @param int limit
  103. * */
  104. public function get_system_vip_list()
  105. {
  106. $where = UtilService::getMore([
  107. ['page', 0],
  108. ['limit', 10],
  109. ['title', ''],
  110. ['is_show', ''],
  111. ]);
  112. JsonService::successlayui(\app\models\lala\AutoPink::getList($where, $where['page'], $where['limit'], true));
  113. }
  114. /*
  115. * 删除会员等级
  116. * @param int $id
  117. * */
  118. public function delete($id = 0)
  119. {
  120. if (\app\models\lala\AutoPink::edit(['is_del' => 1], $id))
  121. JsonService::successful('删除成功');
  122. else
  123. JsonService::fail('删除失败');
  124. }
  125. /**
  126. * 设置单个产品上架|下架
  127. *
  128. * @return json
  129. */
  130. public function set_show($is_show = '', $id = '')
  131. {
  132. ($is_show == '' || $id == '') && Json::fail('缺少参数');
  133. $res = \app\models\lala\AutoPink::where(['id' => $id])->update(['is_show' => (int)$is_show]);
  134. if ($res) {
  135. JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  136. } else {
  137. JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  138. }
  139. }
  140. /**
  141. * 快速编辑
  142. *
  143. * @return json
  144. */
  145. public function set_value($field = '', $id = '', $value = '')
  146. {
  147. $field == '' || $id == '' || $value == '' && JsonService::fail('缺少参数');
  148. if (\app\models\lala\AutoPink::where(['id' => $id])->update([$field => $value]))
  149. JsonService::successful('保存成功');
  150. else
  151. JsonService::fail('保存失败');
  152. }
  153. }