123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace app\admin\controller\system;
- use app\admin\controller\AuthController;
- use crmeb\services\{JsonService as Json, FormBuilder as Form};
- use crmeb\services\UtilService as Util;
- use app\models\system\{Card as CardModel,CardInfo};
- use think\facade\Route as Url;
- class Card extends AuthController
- {
- public function index()
- {
- $this->assign([
- 'key' => $this->request->get('key', ''),
- 'type' => $this->request->param('type', ''),
- ]);
- return $this->fetch();
- }
- public function lst()
- {
- $where = Util::getMore([
- ['status', -1],
- ['key', $this->request->param('key', '')],
- ['data', ''],
- ['type', -1],
- ['page', 1],
- ['limit', 20],
- ['excel', 0]
- ]);
- return Json::successlayui(CardModel::lst($where));
- }
- public function create()
- {
- $f = [];
- $f[] = Form::input('title', '批次名称');
- $f[] = Form::number('totle_num', '生成数量', 500);
- $f[] = Form::number('amount', '卡券金额');
- $f[] = Form::textarea('remark','备注');
- $f[] = Form::hidden('status',1);
- $f[] = Form::radio('type','卡券类型',0)->options([['label'=>'充值卡','value'=>1],['label'=>'会员卡','value'=>0]]);
- $form = Form::make_post_form('修改订单', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function edit($id)
- {
- if (!$id) return $this->failed('数据不存在');
- $product = CardModel::find($id);
- if (!$product) return Json::fail('数据不存在!');
- $f = [];
- $f[] = Form::input('title', '批次名称',$product->title)->disabled(true);
- $f[] = Form::number('amount', '卡券金额')->disabled(true);
- $f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
- $form = Form::make_post_form('修改订单', $f, Url::buildUrl('update',['id'=>$id]));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function save()
- {
- $data = Util::postMore([
- ['title',''],
- ['totle_num',0],
- ['amount',0],
- ['remark',''],
- ['status',1],
- ['type',0],
- ]);
- if(!CardModel::do_create($data))
- {
- return Json::fail(CardModel::getErrorInfo());
- }
- return Json::successful('生成成功!');
- }
- public function update($id)
- {
- if (!$id) return $this->failed('数据不存在');
- $product = CardModel::find($id);
- if (!$product) return Json::fail('数据不存在!');
- $status = input('post.status',0);
- if($product->status <>1)
- {
- return Json::fail('非正常状态不可修改');
- }
- CardModel::where('id',$id)->update(['status'=>$status]);
- CardInfo::where('card_id',$id)->update(['status'=>1]);
- return Json::successful('修改完成!');
- }
- public function info()
- {
- $this->assign([
- 'key' => $this->request->get('key', ''),
- 'type' => $this->request->param('type', ''),
- ]);
- return $this->fetch();
- }
- public function excal($id)
- {
- $where = Util::getMore([
- ['status', 0],
- ['card_id',$id],
- ['page', 1],
- ['limit', 20],
- ['excel', 1]
- ]);
- return CardInfo::lst($where);
- }
- public function info_lst()
- {
- $where = Util::getMore([
- ['status', 0],
- ['key', $this->request->param('key', '')],
- ['data', ''],
- ['type', -1],
- ['page', 1],
- ['limit', 20],
- ['excel', 0]
- ]);
- return Json::successlayui(CardInfo::lst($where));
- }
- public function use_card()
- {
- $this->assign([
- 'key' => $this->request->get('key', ''),
- 'type' => $this->request->param('type', ''),
- ]);
- return $this->fetch();
- }
- public function use_card_lst()
- {
- $where = Util::getMore([
- ['status', 1],
- ['key', $this->request->param('key', '')],
- ['data', ''],
- ['type', -1],
- ['page', 1],
- ['limit', 20],
- ['excel', 0]
- ]);
- return Json::successlayui(CardInfo::lst($where));
- }
- }
|