123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- /**
- *
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\admin\controller\card;
- use app\admin\controller\AuthController;
- use crmeb\services\{ExpressService,
- JsonService,
- JsonService as Json,
- MiniProgramService,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util};
- use Monolog\Handler\IFTTTHandler;
- use think\facade\Route as Url;
- use think\facade\Validate;
- Use app\admin\model\card\Card as model;
- /**
- * 订单管理控制器 同一个订单表放在一个控制器
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class Card extends AuthController
- {
- /**
- * @return mixed
- */
- public function index()
- {
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['name', ''],
- ]);
- return Json::successlayui(model::list($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $list = [
- 'id' => '',
- 'name' => '',
- 'time' => '',
- 'image' =>'',
- 'introduce' => '',
- 'start_week' => '',
- 'end_week' => '',
- 'price' => '',
- 'details_image' => '',
- 'info' => '',
- ];
- if ($id){
- $data = \app\admin\model\card\Card::where('id', $id)->find()->toArray();
- foreach ($data as $k => $v){
- $list[$k] = $v;
- if ($k == 'introduce'){
- $list[$k] = html_entity_decode($v);
- }
- }
- }
- $this->assign('list', $list);
- $this->assign('id', $id);
- return $this->fetch();
- }
- public function save()
- {
- $model = new model;
- $data = Util::postMore([
- 'id',
- 'name',
- 'time',
- 'price',
- 'start_week',
- 'end_week',
- 'introduce',
- 'image',
- 'details_image',
- 'info',
- ]);
- if ($data['id']){
- $list = \app\admin\model\card\Card::where('id', $data['id'])->find();
- $list['name'] = $data['name'];
- $list['time'] = $data['time'];
- $list['price'] = $data['price'];
- $list['start_week'] = $data['start_week'];
- $list['end_week'] = $data['end_week'];
- $list['introduce'] = $data['introduce'];
- $list['image'] = $data['image'];
- $list['details_image'] = $data['details_image'];
- $list['info'] = $data['info'];
- $res = $list->save();
- }else{
- $res = $model->save($data);
- }
- if ($res) return Json::successful('添加图文成功!');
- return Json::fail('添加失败');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function edit($id = 0)
- {
- $data = model::find($id);
- $f = [];
- $f[] = Form::input('name', '分类名称', $data['name'])->required();
- $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
- ['value' => 1, 'label' => '陪诊'],
- ['value' => 2, 'label' => '代办'],
- ])->filterable(true)->required();
- $f[] = Form::input('price', '金额', $data['price'])->required();
- $f[] = Form::radio('status', '状态', (string)$data['status'])->options([['value' => 0, 'label' => '禁用'], ['value' => 1, 'label' => '正常']]);
- $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 修改
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function update()
- {
- $model = new model;
- $data = Util::postMore([
- 'name',
- 'type',
- 'price',
- 'status',
- 'id'
- ]);
- $details = $model->find($data['id']);
- $details['name'] = $data['name'];
- $details['type'] = $data['type'];
- $details['price'] = $data['price'];
- $details['status'] = $data['status'];
- $res = $details->save();
- if ($res) return Json::successful('修改成功');
- return Json::fail('修改失败');
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) return Json::fail('删除失败');
- $model = new model;
- $res = model::destroy($id);
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail($model->getErrorInfo());
- }
- }
- /**
- * 设置单个产品上架|下架
- *
- * @return json
- */
- public function set_show($is_show = '', $id = '')
- {
- ($is_show == '' || $id == '') && Json::fail('缺少参数');
- $res = model::where(['id' => $id])->update(['status' => (int)$is_show]);
- if ($res) {
- return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功');
- } else {
- return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
- }
- }
- }
|