fetch(); } /* * 创建form表单 * */ public function create($id = 0) { $money_type = function () { $array = init_money_type(); $new = []; foreach ($array as $v => $k) { $new[] = ['value' => $v, 'label' => $k]; } return $new; }; $lala = function () { return \app\models\lala\LalaPink::validWhere()->field('id as value,name as label')->select()->toArray(); }; if ($id) $vipinfo = \app\models\lala\AutoPink::get($id); $field[] = Form::input('name', '服务名称', isset($vipinfo) ? $vipinfo->name : '')->col(Form::col(24)); $field[] = Form::select('lala_id', '适用活动', isset($vipinfo) ? explode(',', $vipinfo->lala_id) : [])->options($lala())->filterable(true)->multiple(true)->col(24); $field[] = Form::radio('is_forever', '是否为永久', isset($vipinfo) ? $vipinfo->is_forever : 0)->options([['label' => '永久', 'value' => 1], ['label' => '非永久', 'value' => 0]])->col(24); $field[] = Form::number('valid_date', '有效时间(天)', isset($vipinfo) ? $vipinfo->valid_date : 0)->min(0)->col(24); $field[] = Form::number('money', '开通价格', isset($vipinfo) ? $vipinfo->money : 0)->step(0.00000001)->col(12); $field[] = Form::select('money_type', '开通币种', isset($vipinfo) ? $vipinfo->money_type : 0)->options($money_type())->col(8); $field[] = Form::radio('is_show', '是否显示', isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])->col(8); $form = Form::make_post_form('添加自动拼购服务', $field, Url::buildUrl('save', ['id' => $id]), 2); $this->assign(compact('form')); return $this->fetch('public/form-builder'); } /* * 会员等级添加或者修改 * @param $id 修改的等级id * @return json * */ public function save($id = 0) { $data = UtilService::postMore([ ['name', ''], ['is_forever', 1], ['money', 0], ['money_type', ''], ['valid_date', 0], ['lala_id', []], ['is_show', ''], ]); if (!$data['name']) JsonService::fail('请输入业务名称'); if ($data['is_forever'] == 0 && !$data['valid_date']) JsonService::fail('请输入有效时间(天)'); if (!$data['money_type'] || !$data['money']) JsonService::fail('请输入开通价格'); $data['lala_id'] = implode(',', $data['lala_id']); \app\models\lala\AutoPink::beginTrans(); try { //修改 if ($id) { if (\app\models\lala\AutoPink::edit($data, $id)) { \app\models\lala\AutoPink::commitTrans(); JsonService::successful('修改成功'); } else { \app\models\lala\AutoPink::rollbackTrans(); JsonService::fail('修改失败'); } } else { //新增 $data['add_time'] = time(); if (\app\models\lala\AutoPink::create($data)) { \app\models\lala\AutoPink::commitTrans(); JsonService::successful('添加成功'); } else { \app\models\lala\AutoPink::rollbackTrans(); JsonService::fail('添加失败'); } } } catch (\Exception $e) { \app\models\lala\AutoPink::rollbackTrans(); JsonService::fail($e->getMessage()); } } /* * 获取系统设置的vip列表 * @param int page * @param int limit * */ public function get_system_vip_list() { $where = UtilService::getMore([ ['page', 0], ['limit', 10], ['title', ''], ['is_show', ''], ]); JsonService::successlayui(\app\models\lala\AutoPink::getList($where, $where['page'], $where['limit'], true)); } /* * 删除会员等级 * @param int $id * */ public function delete($id = 0) { if (\app\models\lala\AutoPink::edit(['is_del' => 1], $id)) JsonService::successful('删除成功'); else JsonService::fail('删除失败'); } /** * 设置单个产品上架|下架 * * @return json */ public function set_show($is_show = '', $id = '') { ($is_show == '' || $id == '') && Json::fail('缺少参数'); $res = \app\models\lala\AutoPink::where(['id' => $id])->update(['is_show' => (int)$is_show]); if ($res) { JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功'); } else { JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败'); } } /** * 快速编辑 * * @return json */ public function set_value($field = '', $id = '', $value = '') { $field == '' || $id == '' || $value == '' && JsonService::fail('缺少参数'); if (\app\models\lala\AutoPink::where(['id' => $id])->update([$field => $value])) JsonService::successful('保存成功'); else JsonService::fail('保存失败'); } }