123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- <?php
- namespace app\admin\controller\auction;
- use app\admin\controller\AuthController;
- use app\admin\controller\Union;
- use app\admin\model\auction\AuctionGu;
- use app\admin\model\auction\AuctionProduct as model;
- use app\admin\model\store\StoreProductAttrResult;
- use app\admin\model\store\StoreProductAttrValue;
- use app\admin\model\User;
- use app\models\store\StoreProduct;
- use app\models\store\StoreProductAttr;
- 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()
- {
- $list = AuctionGu::select();
- $this->assign('admin', $this->adminInfo);
- $this->assign('list', $list);
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['status', ''],
- ['page', 1],
- ['limit', 20],
- ['auction'],
- ['auction_id'],
- ['uid']
- ]);
- if ($this->adminInfo['roles'] == 8){
- if ($this->adminInfo['uid']){
- $where['uid'] = $this->adminInfo['uid'];
- }
- }
- $data = \app\admin\model\auction\Auction::list($where);
- return Json::successlayui($data);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $f = [];
- $f[] = Form::input('nickname', '场次名称')->col(12);
- $f[] = Form::input('anticipate', '预约价格')->col(12);
- $f[] = Form::input('threshold', '预约门槛')->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]])->col(12);
- $f[] = Form::select('auction_gu_id', '绑定场馆')->setOptions(function () {
- $model = new AuctionGu();
- $list = $model->select();
- $menus = [];
- foreach ($list as $menu) {
- $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
- }
- return $menus;
- })->filterable(1)->col(12);
- $f[] = Form::dateTimes('add_time', '认购开始时间');
- $f[] = Form::dateTimes('end_time', '认购结束时间');
- $f[] = Form::dateTimes('radd_time', '支付开始时间');
- $f[] = Form::dateTimes('rend_time', '支付结束时间');
- $f[] = Form::input('sort', '排序', '0');
- $f[] = Form::input('sort', '排序', '0')->col(12);
- $f[] = Form::input('goods_time', '放货时间(分钟)', '0')->col(12);
- $f[] = Form::checkbox('site', '开场日期', [1,3,5])->options([
- ['value' => 1, 'label' => '周一'],
- ['value' => 2, 'label' => '周二'],
- ['value' => 3, 'label' => '周三'],
- ['value' => 4, 'label' => '周四'],
- ['value' => 5, 'label' => '周五'],
- ['value' => 6, 'label' => '周六'],
- ['value' => 7, 'label' => '周七'],
- ]);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- // $data = [];
- // $model = new AuctionGu();
- // $auction = $model->select();
- // if ($id > 0) $data = \app\admin\model\auction\Auction::find($id)->toArray();
- //
- // $this->assign(['id' => $id, 'dataList' => $data, 'auction' => $auction]);
- // return $this->fetch();
- }
- public function save()
- {
- $mode = new \app\admin\model\auction\Auction();
- $data = Util::postMore([
- 'nickname',
- 'image',
- 'status',
- 'sort',
- 'add_time',
- 'end_time',
- 'radd_time',
- 'rend_time',
- 'info',
- 'anticipate',
- 'auction_gu_id',
- 'site',
- 'goods_time',
- 'threshold'
- ]);
- $validate = Validate::rule('nickname', 'require')->rule([
- 'nickname' => 'require',
- 'image' => 'require',
- 'status' => 'require',
- 'anticipate' => 'require',
- 'add_time' => 'require',
- 'end_time' => 'require',
- 'radd_time' => 'require',
- 'rend_time' => 'require',
- 'auction_gu_id' => 'require',
- 'site' => 'require',
- 'goods_time' => 'require|integer|>:0',
- 'threshold' => 'require'
- ]);
- $validate->message([
- 'nickname.require' => '名称不能为空',
- 'image.require' => '图片不能为空',
- 'status.require' => '状态不能为空',
- 'anticipate.require' => '请填写预约价格',
- 'add_time.require' => '请选择认购开始时间价格',
- 'end_time.require' => '请选择认购结束时间价格',
- 'radd_time.require' => '请选择支付开始时间',
- 'rend_time.require' => '请选择支付结束时间',
- 'auction_gu_id.require' => '请选择绑定场馆',
- 'site.require' => '请选择开场日期',
- 'goods_time.require' => '请输入放货时间',
- 'goods_time.integer' => '放货时间为整数',
- 'goods_time.gt' => '放货时间大于0',
- 'threshold' => '请填写门槛'
- ]);
- $data['site'] = implode($data['site'], ',');
- if ($data['site'] == '1,3,5' or $data['site'] == '2,4,6') {
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $res = $mode->save($data);
- if ($res){
- return Json::success('添加成功!');
- }else{
- return Json::fail('添加失败');
- }
- }else{
- return Json::fail('请选择正确的日期,1,3,5 或者 2,4,6');
- }
- }
- /**
- * 删除
- * @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());
- }
- }
- public function edit($id)
- {
- if (!$id) Json::fail('数据不存在');
- $data = \app\admin\model\auction\Auction::find($id);
- $f = [];
- $f[] = Form::input('nickname', '场次名称', $data->getData('nickname'))->col(12);
- $f[] = Form::input('anticipate', '预约价格', $data->getData('anticipate'))->col(12);
- $f[] = Form::input('threshold', '预约门槛', $data->getData('threshold'))->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::radio('status', '状态', $data->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]])->col(12);
- if ($this->adminInfo['roles'] == 1){
- $f[] = Form::select('auction_gu_id', '绑定场馆', (string)$data->getData('auction_gu_id'))->setOptions(function () {
- $model = new AuctionGu();
- $list = $model->select();
- $menus = [];
- foreach ($list as $menu) {
- $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
- }
- return $menus;
- })->filterable(1)->col(12);
- }else{
- $f[] = Form::hidden('auction_gu_id', $data->getData('auction_gu_id'));
- }
- $f[] = Form::dateTimes('add_time', '认购开始时间', $data->getData('add_time'));
- $f[] = Form::dateTimes('end_time', '认购结束时间', $data->getData('end_time'));
- $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'))->col(12);
- $f[] = Form::input('goods_time', '放货时间(分钟)', $data->getData('goods_time'))->col(12);
- $f[] = Form::checkbox('site', '开场日期', explode(',', $data->getData('site')))->options([
- ['value' => 1, 'label' => '周一'],
- ['value' => 2, 'label' => '周二'],
- ['value' => 3, 'label' => '周三'],
- ['value' => 4, 'label' => '周四'],
- ['value' => 5, 'label' => '周五'],
- ['value' => 6, 'label' => '周六'],
- ['value' => 7, 'label' => '周七'],
- ]);
- $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('数据不存在');
- $model = new \app\admin\model\auction\Auction();
- $info = $model->find($id);
- $data['productInfo'] = $info;
- return JsonService::successful($data);
- }
- public function update()
- {
- $data = Util::postMore([
- 'id',
- 'nickname',
- 'image',
- 'status',
- 'sort',
- 'add_time',
- 'end_time',
- 'radd_time',
- 'rend_time',
- 'info',
- 'anticipate',
- 'auction_gu_id',
- 'site',
- 'goods_time',
- 'threshold',
- ]);
- $validate = Validate::rule('nickname', 'require')->rule([
- 'nickname' => 'require',
- 'image' => 'require',
- 'status' => 'require',
- 'anticipate' => 'require',
- 'add_time' => 'require',
- 'end_time' => 'require',
- 'radd_time' => 'require',
- 'rend_time' => 'require',
- 'auction_gu_id' => 'require',
- 'site' => 'require',
- 'goods_time' => 'require|integer|>:0',
- 'threshold' => 'require'
- ]);
- $validate->message([
- 'nickname.require' => '名称不能为空',
- 'image.require' => '图片不能为空',
- 'status.require' => '状态不能为空',
- 'anticipate.require' => '请填写预约价格',
- 'threshold.require' => '请填写预约门槛',
- 'add_time.require' => '请选择认购开始时间价格',
- 'end_time.require' => '请选择认购结束时间价格',
- 'radd_time.require' => '请选择支付开始时间',
- 'rend_time.require' => '请选择支付结束时间',
- 'auction_gu_id.require' => '请选择绑定场馆',
- 'site.require' => '请选择开场日期',
- 'goods_time.require' => '请输入放货时间',
- 'goods_time.integer' => '时间为整数',
- 'goods_time.gt' => '放货时间大于0',
- ]);
- $data['site'] = implode($data['site'], ',');
- if ($data['site'] == '1,3,5' or $data['site'] == '2,4,6') {
- if (!$validate->check($data)) {
- return Json::fail($validate->getError());
- }
- $res = \app\admin\model\auction\Auction::update($data);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }else{
- return Json::fail('请选择正确的日期,1,3,5 或者 2,4,6');
- }
- }
- /**
- * 商品列表
- * @param $id
- * @return void
- */
- public function product($id)
- {
- $list = \app\admin\model\auction\Auction::select();
- $this->assign([
- 'auction'=> $list,
- 'id' => $id
- ]);
- $this->assign('admin', $this->adminInfo);
- return $this->fetch('');
- }
- /**
- * 商品
- * @param $id
- * @return void
- */
- public function product_list($id)
- {
- $where = Util::getMore([
- ['is_show', ''],
- ['page', 1],
- ['limit', 20],
- ['store_name', ''],
- ['auction_id'],
- ['is_show']
- ]);
- $data = model::list($where, $id);
- foreach ($data['data'] as $key => $val){
- if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
- }
- return Json::successlayui($data);
- }
- /**
- * 商品添加
- * @param $id
- * @return string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function product_edit($id, $auction_id)
- {
- if (!$id) Json::fail('数据不存在');
- $this->assign(['id' => $id, 'auction_id' => $auction_id]);
- return $this->fetch();
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function product_create($id = 0)
- {
- $this->assign(['id' => $id]);
- return $this->fetch();
- }
- public function fz($id, $auction_id)
- {
- if (!$id) Json::fail('数据不存在');
- $this->assign(['id' => $id, 'auction_id' => $auction_id]);
- return $this->fetch();
- }
- public function product_save($id)
- {
- $data = Util::postMore([
- 'name',
- 'is_show',
- 'image',
- 'price',
- 'deduct',
- 'rise',
- 'info',
- 'sort',
- 'auction_id',
- 'hanging_price',
- 'slider_image',
- 'description',
- 'fictitious_price',
- 'give'
- ]);
- $data['slider_image'] = json_encode($data['slider_image']);
- $data['description'] = htmlspecialchars($data['description']);
- $auction = \app\admin\model\auction\Auction::where('id' ,$data['auction_id'])->find();
- $auction_gu = \app\admin\model\auction\AuctionGu::where('id' ,$auction['auction_gu_id'])->find();
- $data['uid'] = $auction_gu['uid'];
- $model = new model();
- $res = $model->save($data);
- if ($res){
- return Json::success('添加成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- /**
- * 商品修改
- * @param $id
- * @return void
- */
- public function product_update($id)
- {
- $data = Util::postMore([
- 'id',
- 'name',
- 'image',
- 'price',
- 'deduct',
- 'rise',
- 'info',
- 'sort',
- 'auction_id',
- 'hanging_price',
- 'slider_image',
- 'description',
- 'fictitious_price',
- 'give'
- ]);
- $data['slider_image'] = json_encode($data['slider_image']);
- $data['description'] = htmlspecialchars($data['description']);
- $res = model::update($data);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- public function fzsp($id)
- {
- $data = Util::postMore([
- 'name',
- 'image',
- 'price',
- 'deduct',
- 'rise',
- 'info',
- 'sort',
- 'auction_id',
- 'hanging_price',
- 'slider_image',
- 'description',
- 'give',
- 'fictitious_price'
- ]);
- $data['slider_image'] = json_encode($data['slider_image']);
- $data['description'] = htmlspecialchars($data['description']);
- $auction = \app\admin\model\auction\Auction::where('id' ,$data['auction_id'])->find();
- $auction_gu = \app\admin\model\auction\AuctionGu::where('id' ,$auction['auction_gu_id'])->find();
- $data['uid'] = $auction_gu['uid'];
- $res = model::create($data);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- }
|