| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- namespace app\admin\controller\auction;
- use app\admin\controller\AuthController;
- use app\admin\model\User;
- use app\models\auction\AuctionSection;
- use crmeb\services\{ExpressService,
- JsonService,
- JsonService as Json,
- MiniProgramService,
- upload\Upload,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util};
- use app\admin\model\system\{
- SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
- };
- use think\facade\Route as Url;
- use think\facade\Validate;
- /**
- * 竞拍管理
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class Auction extends AuthController
- {
- public function index()
- {
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['status', ''],
- ['page', 1],
- ['limit', 20],
- ['auction']
- ]);
- $data = \app\admin\model\auction\Auction::list($where);
- return Json::successlayui($data);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $f = [];
- $f[] = Form::input('name', '场次名称')->col(12);
- $f[] = Form::input('advert', '预约广告值')->col(12);
- $f[] = Form::input('lowest', '额度门槛');
- $f[] = Form::input('minimum', '广告值门槛');
- $f[] = Form::input('dispatch', '派单百分比%', 100)->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::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- $f[] = Form::dateTimes('radd_time', '入场时间');
- $f[] = Form::dateTimes('rend_time', '结束时间');
- $f[] = Form::input('sort', '排序',0);
- $f[] = Form::textarea('info', '介绍');
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 修改页面
- * @param $id
- * @return string
- * @throws \FormBuilder\exception\FormBuilderException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit($id)
- {
- $data = \app\admin\model\auction\Auction::find($id);
- $f = [];
- $f[] = Form::input('name', '场次名称', $data->getData('name'))->col(12);
- $f[] = Form::input('advert', '预约广告值', $data->getData('advert'))->col(12);
- $f[] = Form::input('lowest', '额度门槛', $data->getData('lowest'));
- $f[] = Form::input('minimum', '广告值门槛', $data->getData('minimum'));
- $f[] = Form::input('dispatch', '派单百分比%', $data->getData('dispatch'));
- $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::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
- $f[] = Form::dateTimes('radd_time', '入场时间', $data->getData('radd_time'));
- $f[] = Form::dateTimes('rend_time', '结束时间', $data->getData('rend_time'));
- $f[] = Form::input('sort', '排序', $data->getData('sort'));
- $f[] = Form::textarea('info', '介绍', $data->getData('info'));
- $f[] = Form::hidden('id', $id);
- $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\Auction();
- $data = Util::postMore([
- 'id',
- 'name',
- 'image',
- 'status',
- 'sort',
- 'radd_time',
- 'rend_time',
- 'info',
- 'advert',
- 'lowest',
- 'minimum',
- 'dispatch'
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'image' => 'require',
- 'status' => 'require',
- 'advert' => 'require',
- 'radd_time' => 'require',
- 'rend_time' => 'require',
- 'lowest' => 'require',
- 'minimum' => 'require',
- 'dispatch' => 'require',
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- 'image.require' => '图片不能为空',
- 'status.require' => '状态不能为空',
- 'advert.require' => '请填写预约广告值',
- 'radd_time.require' => '请选择进场时间',
- 'rend_time.require' => '请选择结束时间',
- 'lowest.require' => '请填写额度门槛',
- 'minimum.require' => '请选择广告值门槛',
- 'dispatch.require' => '请填写派单量',
- ]);
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- if ($data['id']){
- $details = $mode->find($data['id']);
- unset($data['id']);
- $res = $details->save($data);
- }else{
- $res = $mode->save($data);
- }
- if ($res){
- return Json::success('成功!');
- }else{
- return Json::fail('失败');
- }
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $model = new \app\admin\model\auction\Auction();
- $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\Auction::update(['status' => $status, 'id' => $id]);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- /**
- * 区间
- * @param $id
- * @return string
- * @throws \Exception
- */
- public function auction_section($id)
- {
- $this->assign('id', $id);
- return $this->fetch();
- }
- /**
- * 区间列表
- * @param $id
- * @return void
- */
- public function section_list ($id)
- {
- $where = Util::getMore([
- ['status', ''],
- ['page', 1],
- ['limit', 20],
- ['auction']
- ]);
- $list['data'] = AuctionSection::where('auction_id', $id)->page($where['page'], $where['limit'])->select();
- $list['data'] = empty($list['data']) ? [] : $list['data']->toArray();
- $list['count'] = AuctionSection::where('auction_id', $id)->count();
- return Json::successlayui($list);
- }
- /**
- * 区间添加
- * @param $id
- * @return string
- * @throws \Exception
- */
- public function section_create($id)
- {
- $f = [];
- $f[] = Form::input('name', '场次名称');
- $f[] = Form::number('low', '最低价格');
- $f[] = Form::number('high', '最高价格');
- $f[] = Form::hidden('auction_id', $id);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('section_save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 区间添加
- * @param $id
- * @return string
- * @throws \Exception
- */
- public function section_edit($id)
- {
- $data = AuctionSection::where('id', $id)->find();
- $f = [];
- $f[] = Form::input('name', '场次名称', $data->getData('name'));
- $f[] = Form::number('low', '最低价格', $data->getData('low'));
- $f[] = Form::number('high', '最高价格', $data->getData('high'));
- $f[] = Form::hidden('auction_id', $data->getData('auction_id'));
- $f[] = Form::hidden('id', $id);
- $form = Form::make_post_form('修改', $f, Url::buildUrl('section_save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- public function section_save()
- {
- $data = Util::postMore([
- ['name'],
- ['low'],
- ['high'],
- ['id'],
- ['auction_id']
- ]);
- if (empty($data['name'])) return Json::fail('名称不能为空');
- if (empty($data['low'])) return Json::fail('设置最低价格');
- if (empty($data['high'])) return Json::fail('设置最高价格');
- if ($data['id']){
- $id = $data['id'];
- unset( $data['id']);
- $res = AuctionSection::where('id', $id)->save($data);
- }else{
- $res = AuctionSection::insert($data);
- }
- if (!$res){
- return Json::fail('失败');
- }
- return Json::success('成功');
- }
- /**
- * 删除
- * @param $id
- * @return void
- * @throws \Exception
- */
- public function section_delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $model = new AuctionSection();
- $res = $model->where('id', $id)->delete();
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- }
|