123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- namespace app\admin\controller\auction;
- use app\admin\controller\AuthController;
- use app\admin\controller\Union;
- use app\admin\model\user\User;
- use app\admin\model\user\UserBill;
- use app\models\auction\AuctionProduct;
- use app\models\auction\AuctionTime;
- use crmeb\services\{ExpressService,
- JsonService,
- MiniProgramService,
- upload\Upload,
- WechatService,
- FormBuilder as Form,
- CacheService,
- UtilService as Util,
- JsonService as Json};
- use app\admin\model\system\{
- SystemAttachment as SystemAttachmentModel, SystemAttachmentCategory as Category
- };
- use app\admin\model\auction\AuctionOrder as model;
- use think\facade\Db;
- use think\facade\Route as Url;
- /**
- * 竞拍管理
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class AuctionOrder extends AuthController
- {
- public function index()
- {
- $list = \app\admin\model\auction\Auction::select();
- $gu = \app\admin\model\auction\AuctionGu::select();
- $this->assign([
- 'year' => get_month(),
- 'auction'=> $list,
- 'gu' => $gu
- ]);
- return $this->fetch();
- }
- /**
- * 获取列表
- * @return void
- */
- public function list()
- {
- $where = Util::getMore([
- ['is_show', ''],
- ['page', 1],
- ['limit', 20],
- ['auction_id', ''],
- ['store_name', ''],
- ['data', ''],
- ['status', ''],
- ['gu_id', ''],
- ['product_name'],
- ['excel', 0],
- ['is_gs', ''],
- ['uid']
- ]);
- if ($this->adminInfo['roles'] == 8){
- if ($this->adminInfo['uid']){
- $where['uid'] = $this->adminInfo['uid'];
- }
- }
- $data = model::list($where);
- foreach ($data['data'] as $key => $val){
- if ($data['data'][$key]['uid'] == 0) $data['data'][$key]['nickname'] = '管理';
- }
- return Json::successlayui($data);
- }
- public function auction_list()
- {
- $list = model::select()->toArray();
- Json::successful($list);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0)
- {
- $data = \app\admin\model\auction\Auction::select()->toArray();
- $this->assign(['id' => $id, 'list' => $data]);
- return $this->fetch();
- }
- /**
- * 添加
- * @param $id
- * @return void
- */
- public function save($id)
- {
- $data = Util::postMore([
- 'name',
- 'is_show',
- 'image',
- 'price',
- 'deduct',
- 'rise',
- 'info',
- 'sort',
- 'auction_id'
- ]);
- $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
- * @throws \Exception
- */
- public function delete($id)
- {
- if (!$id) Json::fail('删除失败');
- $res = model::where('id', $id)->delete();
- if ($res){
- return Json::success('删除成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return void
- */
- public function set_status($id, $status)
- {
- if (empty($id)) Json::fail('修改失败');
- $res = model::update(['is_show' => $status, 'id' => $id]);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- /**
- * 编辑页面
- * @param $id
- * @return string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function edit($id)
- {
- if (!$id) Json::fail('数据不存在');
- $data = \app\admin\model\auction\Auction::select()->toArray();
- $this->assign(['id' => $id, 'list' => $data]);
- return $this->fetch();
- }
- public function get_list($id)
- {
- if (!$id) Json::fail('数据不存在');
- $model = new model();
- $info = $model->find($id);
- return JsonService::successful($info);
- }
- /**
- * 修改
- * @param $id
- * @return void
- */
- public function update($id)
- {
- $data = Util::postMore([
- 'id',
- 'name',
- 'is_show',
- 'image',
- 'price',
- 'deduct',
- 'rise',
- 'info',
- 'sort',
- 'auction_id'
- ]);
- $res = model::update($data);
- if ($res){
- return Json::success('修改成功!');
- }else{
- return Json::fail(\app\admin\model\auction\Auction::getErrorInfo());
- }
- }
- /**
- * 通过
- * @param $id
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function qd($id)
- {
- if (!$id) return Json::fail('没有数据');
- $data = model::find($id);// 订单数据
- if($data['status'] < 3 and $data['status'] > 0){
- $data['status'] = 3;
- try {
- Db::startTrans();
- $data->save();
- $product = AuctionProduct::find($data['product_id']);
- if (!$product) return app('json')->fail('数据不存在');
- $uid = $product['uid']; // 所属人id
- $product['uid'] = $data['uid'];// 商品拥有人更新
- $product['add_time'] = time();
- $product['order'] = $data['order_id'];
- $product['is_show'] = 0;
- $res = $product->save();
- AuctionTime::where([['product_id', '=', $product['id']]])->delete();
- \app\models\auction\AuctionOrder::return($data['id']); // 买家
- Db::commit();
- return Json::success('修改成功!');
- } catch (\Exception $e) {
- Db::rollback();
- return Json::fail('失败');
- }
- }
- return Json::fail('该订单不能通过');
- }
- }
|