123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- namespace app\admin\controller\auction;
- use app\admin\controller\AuthController;
- use app\admin\controller\Union;
- use app\admin\model\User;
- use crmeb\services\{ExpressService,
- FormBuilder,
- JsonService,
- MiniProgramService,
- upload\Upload,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util,
- JsonService as Json};
- use app\admin\model\system\{SystemAdmin,
- SystemAttachment as SystemAttachmentModel,
- SystemAttachmentCategory as Category};
- use think\Db;
- use think\facade\Route as Url;
- use think\facade\Validate;
- /**
- * 竞拍管理
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class AuctionGu extends AuthController
- {
- public function index()
- {
- $this->assign('admin', $this->adminInfo);
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['status', ''],
- ['page', 1],
- ['limit', 20],
- ['auction'],
- ['uid'],
- ['null']
- ]);
- if ($this->adminInfo['roles'] == 8){
- if ($this->adminInfo['uid']){
- $where['uid'] = $this->adminInfo['uid'];
- }
- }
- $data = \app\admin\model\auction\AuctionGu::list($where);
- return Json::successlayui($data);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $f = [];
- $f[] = Form::input('name', '场馆名称')->col(12);
- $f[] = Form::input('max_hanging', '最大挂售额度')->col(12);
- $f[] = Form::frameImageOne('image', '主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')))->icon('image')->width('100%')->height('500px');
- $f[] = Form::frameImages('slider_image', '轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')))->maxLength(3)->icon('images')->width('100%')->height('500px');
- $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- $f[] = Form::select('uid', '绑定用户')->setOptions(function () {
- $model = new \app\models\user\User();
- $list = $model->select();
- $menus = [];
- foreach ($list as $menu) {
- $menus[] = ['value' => $menu['uid'], 'label' => $menu['nickname']];
- }
- return $menus;
- })->filterable(1)->col(12);
- $f[] = Form::input('sort', '排序', '0')->col(12);
- $f[] = Form::textarea('info', '介绍');
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function save()
- {
- $mode = new \app\admin\model\auction\AuctionGu();
- $data = Util::postMore([
- 'name',
- 'image',
- 'sort',
- 'info',
- 'uid',
- 'slider_image',
- 'max_hanging'
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'name' => 'require',
- 'image' => 'require',
- 'uid' => 'require',
- 'slider_image' => 'require',
- 'max_hanging' => 'require'
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- 'image.require' => '图片不能为空',
- 'uid.require' => '请绑定用户',
- 'slider_image.require' => '轮播图不能为空',
- 'max_hanging.require' => '挂售额度不能为空',
- ]);
- $data['slider_image'] = json_encode($data['slider_image']);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $user = \app\models\user\User::where('uid', $data['uid'])->find();
- if ($user['spread_uid']){
- $user['spread_uid'] = 0; // 更新用户上级
- $user->save();
- }
- $res = $mode->save($data);
- if ($res){
- return Json::success('添加成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $model = new \app\admin\model\auction\AuctionGu();
- $res = $model->where('id', $id)->delete();
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- public function set_status($id, $status)
- {
- if (empty($id))return Json::fail('修改失败');
- $res = \app\admin\model\auction\AuctionGu::update(['status' => $status, 'id' => $id]);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- public function edit($id)
- {
- if (!$id) Json::fail('数据不存在');
- $data = \app\admin\model\auction\AuctionGu::find($id);
- $f = [];
- $f[] = Form::input('name', '场馆名称',$data->getData('name'))->col(12);
- if ($this->adminInfo['roles'] == 8){
- $f[] = Form::hidden('max_hanging', $data->getData('max_hanging'))->col(12);
- }else{
- $f[] = Form::input('max_hanging', '最大挂售额度',$data->getData('max_hanging'))->col(12);
- }
- $f[] = Form::frameImageOne('image', '场次主图片(305*305px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'image')), $data->getData('image'))->icon('image')->width('100%')->height('500px');
- $f[] = Form::frameImages('slider_image', '商品轮播图(640*640px)', Url::buildUrl('admin/widget.images/index', array('fodder' => 'slider_image')), json_decode($data->getData('slider_image'), 1))->maxLength(5)->icon('images')->width('100%')->height('500px');
- $f[] = Form::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- $f[] = Form::select('uid', '绑定用户',(string)$data->getData('uid'))->setOptions(function () {
- $model = new \app\models\user\User();
- $list = $model->select();
- $menus = [];
- foreach ($list as $menu) {
- $menus[] = ['value' => $menu['uid'], 'label' => $menu['nickname']];
- }
- return $menus;
- })->filterable(1)->col(12);
- $f[] = Form::input('sort', '排序' ,$data->getData('sort'))->col(12);
- $f[] = Form::textarea('info', '介绍',$data->getData('info'));
- $form = Form::make_post_form('修改', $f, Url::buildUrl('update', compact('id')));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function get_auction($id)
- {
- if (!$id) Json::fail('数据不存在');
- $info = \app\admin\model\auction\AuctionGu::find($id)->toArray();
- $data['productInfo'] = $info;
- return JsonService::successful($data);
- }
- public function update()
- {
- $data = Util::postMore([
- 'id',
- 'name',
- 'image',
- 'sort',
- 'info',
- 'uid',
- 'status',
- 'slider_image',
- 'max_hanging'
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'name' => 'require',
- 'image' => 'require',
- 'uid' => 'require',
- 'slider_image' => 'require',
- 'max_hanging' => 'require'
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- 'image.require' => '图片不能为空',
- 'uid.require' => '请绑定用户',
- 'slider_image.require' => '轮播图不能为空',
- 'max_hanging.require' => '挂售额度不能为空',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $data['slider_image'] = json_encode($data['slider_image']);
- $user = \app\models\user\User::where('uid', $data['uid'])->find();
- if ($user['spread_uid']){
- $user['spread_uid'] = 0; // 更新用户上级
- $user->save();
- }
- $res = \app\admin\model\auction\AuctionGu::update($data);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- // public function edit($id)
- // {
- // if (!$id) Json::fail('数据不存在');
- //
- //
- // $list = \app\admin\model\auction\Auction::get($id);
- // if (!$list) Json::fail('数据不存在');
- //
- // $f = array();
- // $f[] = Form::input('id', 'ID', $list->getData('id'))->disabled(1);
- // $f[] = Form::input('nickname', '名称', $list->getData('nickname'));
- // $f[] = Form::uploadImageOne('image', '图片','/index.php/admin/widget.images/upload',$list->getData('image'));
- // $f[] = Form::radio('is_promoter', '推广员',$list->getData('status'))->options([['value' => 1, 'label' => '启用'], ['value' => 0, 'label' => '禁用']]);
- // $f[] = Form::dateTime('time', '推广员',$list->getData('add_time'));
- //
- // $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $id)), 5);
- // $this->assign(compact('form'));
- // return $this->fetch('public/form-builder');
- // }
- }
|