123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575 |
- <?php
- namespace app\api\controller\auction;
- use app\models\auction\Auction;
- use app\models\auction\AuctionApply;
- use app\models\auction\AuctionBooking;
- use app\models\auction\AuctionGu;
- use app\models\auction\AuctionOrder;
- use app\models\auction\AuctionPay;
- use app\models\auction\AuctionProduct;
- use app\models\auction\AuctionTime;
- use app\models\store\StoreProduct;
- use app\models\user\User;
- use app\models\user\UserBill;
- use app\Request;
- use Monolog\Handler\Curl\Util;
- use think\facade\Cache;
- use crmeb\services\{
- CacheService,
- ExpressService,
- SystemConfigService
- };
- use crmeb\services\UtilService;
- use crmeb\repositories\OrderRepository;
- use think\facade\Db;
- use think\facade\Validate;
- class AuctionController
- {
- /**
- * 场馆列表
- * @param Request $request
- * @return mixed
- */
- public function list(Request $request)
- {
- $data = UtilService::getMore([
- [['page', 'd'], 0],
- [['limit', 'd'], 0],
- ['advance'],
- ['auction_gu_id']
- ], $request);
- if (!$data['auction_gu_id']) return app('json')->fail('数据传入错误');
- $auctionModel = new \app\models\auction\Auction();
- return app('json')->successful($auctionModel->list($data, $request->uid()));
- }
- /**
- * 预约场馆
- * @param Request $request
- * @return void
- */
- public function subscribe(Request $request)
- {
- $data = UtilService::postMore([
- ['id']
- ]);
- if (!$data['id']) return app('json')->fail('数据传入错误');
- Db::startTrans();
- $auction = Auction::lock(true)->find($data['id']);
- $user = User::find($request->uid());
- if (!$auction)return app('json')->fail('没有此数据');
- if ($user['shop_integral'] < $auction['threshold']) return app('json')->fail('未到预约门槛');
- if (time() < strtotime($auction['add_time'])){
- return app('json')->fail('预约未开始');
- }
- if (time() > strtotime($auction['end_time'])){
- return app('json')->fail('预约时间已过');
- }
- if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
- return app('json')->fail('当前场次已预约');
- }
- $product = AuctionProduct::alias('a')
- ->field('a.*')
- ->where([['a.uid', '<>', $request->uid()], ['a.is_show', '=', 1], ['b.add_time', '<=', strtotime('today')], ['a.auction_id', '=', $data['id']], ['succeed_time', '<', strtotime('today')]])
- ->leftJoin('auction_time b', 'a.id = b.product_id')
- ->limit(1)
- ->orderRaw('rand()')
- ->select();
- if (count($product) == 0) {
- $product = AuctionProduct::where([['uid', '<>', $request->uid()], ['is_admin', '=', 1],['is_show', '=', 1], ['auction_id', '=', $data['id']], ['succeed_time', '<', strtotime('today')]])
- ->limit(1)
- ->orderRaw('rand()')
- ->select();
- if (count($product) == 0) {
- return app('json')->fail('商品已认购完');
- }
- }
- if ($user['is_auth'] != 2) return app('json')->fail('未实名认证');
- // if ($user['shop_integral'] <= 0) return app('json')->fail('账户内没有购物券,无法进行预约');
- if ($user['anticipate'] < $auction['anticipate']) return app('json')->fail('广告值不足');
- $user['anticipate'] = $user['anticipate'] - $auction['anticipate'];// 扣除广告值
- try {
- $user->save();
- AuctionOrder::create([
- 'uid' => $request->uid(),
- 'collection_id' => $product[0]['uid'],// 商品拥有有人
- 'order_id' => getNewOrderId(),
- 'name' => $product[0]['name'],
- 'product_id' => $product[0]['id'],
- 'auction_id' => $auction['id'],
- 'image'=> $product[0]['image'],
- 'price' => $product[0]['hanging_price'],
- 'frequency' => $auction['frequency']
- ]);
- AuctionProduct::where('id', $product[0]['id'])->update(['succeed_time' => strtotime('today')]);
- AuctionBooking::booking($user['uid'], $auction);
- UserBill::expend('预约认购', $user['uid'], 'anticipate','reduce_anticipate', $auction['anticipate'], 0, $user['anticipate'], '预约扣除广告值'); // 写入记录
- Db::commit();
- return app('json')->successful('认购成功');
- } catch (\Exception $e) {
- Db::rollback();
- return app('json')->fail('认购失败');
- }
- }
- /**
- * 进入场馆
- * @param Request $request
- * @return void
- */
- public function advance(Request $request)
- {
- $data = UtilService::getMore([
- ['id']
- ]);
- if (!$data['id']) return app('json')->fail('数据传入错误');
- $auction = Auction::find($data['id']);
- $booking = AuctionBooking::where([['auction_id', '=',$auction['id']], ['frequency', '=', $auction['frequency']]])->find();
- $radd_time = strtotime($auction['radd_time']) - 360; // 提前6分钟进场
- if (!$booking){
- return app('json')->fail('未预约');
- }
- if ($radd_time > time()){
- return app('json')->fail('未到进入时间');
- }
- if (strtotime($auction['rend_time']) < time()){
- return app('json')->fail('进场时间已过');
- }
- return app('json')->successful('可进入');
- }
- /**
- * 用户下级
- * @param Request $request
- * @return mixed
- */
- public function lower(Request $request){
- $data = UtilService::getMore([
- [['page', 'd'], 0],
- [['limit', 'd'], 0],
- ], $request);
- $user = User::where('spread_uid', $request->uid())->page($data['page'], $data['limit'])->field('uid,nickname,avatar')->order('uid DESC')->select();
- $user = empty($user) ? [] : $user->toArray();
- if ($user) {
- foreach ($user as $k => $v){
- $user[$k]['count'] = User::where('spread_uid',$v['uid'])->count(); // 粉丝人数
- $user[$k]['money'] = AuctionOrder::where('uid', $v['uid'])
- ->whereBetweenTime('create_time', date('Y-m-d 00:00:00'), date('Y-m-d 00:00:00', strtotime('+1 day')))
- ->where('status', 3)
- ->sum('price');
- }
- }
- $count = User::where('spread_uid', $request->uid())->count(); // 粉丝人数
- $active = User::where('spread_uid', $request->uid())->whereBetweenTime('last_time', date('Y-m-d H:i:s', strtotime('-1 week')), date('Y-m-d H:i:s'))->count(); // 活跃人数
- $money = AuctionOrder::where('uid', 'in', User::where('spread_uid', $request->uid())->column('uid'))
- ->where('status', 3)
- ->sum('price');
- $data = [
- 'user' => $user, // 下级用户
- 'count' => $count, // 下级用户人数
- 'active' => $active,// 活跃人数
- 'money' => $money // 总金额
- ];
- return app('json')->successful($data);
- }
- /**
- * 转广告值给下级
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function transfer_accounts(Request $request){
- $data = UtilService::getMore([
- ['uid'],
- ['anticipate'],
- ['payment'],
- ['type']
- ], $request);
- if (!$data['uid'] or !$data['anticipate']) return app('json')->fail('数据传入错误');
- if (!$data['payment']) return app('json')->fail('请填写支付密码');
- $user = User::find($request->uid());
- $userList = User::select();
- $uid = get_downline($userList, $user['uid']);
- if ($user['payment'] != md5($data['payment'])) return app('json')->fail('支付密码错误');
- if (!in_array($data['uid'],$uid)) return app('json')->fail('该用户不是你下级');
- if ($data['anticipate'] < 10) return app('json')->fail('最少转账10');
- if ($data['type'] == 1){
- if ($user['anticipate'] < $data['anticipate']) return app('json')->fail('广告值不足');
- $me = User::find($data['uid']);
- $user['anticipate'] -= $data['anticipate'];// 扣除广告值
- $me['anticipate'] += $data['anticipate'];// 增加广告值
- $title = ['广告值减少', '广告值增加'];
- $category = 'anticipate';
- $type = ['zz_anticipate', 'js_anticipate'];
- $mark = '广告值';
- }elseif ($data['type'] == 2){
- //趣豆
- if ($user['integral'] < $data['anticipate']) return app('json')->fail('趣豆不足');
- $me = User::find($data['uid']);
- $user['integral'] -= $data['anticipate'];// 扣除趣豆
- $me['integral'] += $data['anticipate'];// 增加趣豆
- $title = ['趣豆减少', '趣豆增加'];
- $category = 'integral';
- $type = ['zz_integral', 'js_integral'];
- $mark = '趣豆';
- }elseif ($data['type'] == 3){
- //金豆
- if ($user['golden_bean'] < $data['anticipate']) return app('json')->fail('金豆不足');
- $me = User::find($data['uid']);
- $user['golden_bean'] -= $data['anticipate'];// 扣除金豆
- $me['golden_bean'] += $data['anticipate'];// 增加金豆
- $title = ['金豆减少', '金豆增加'];
- $category = 'golden_bean';
- $type = ['zz_golden_bean', 'js_golden_bean'];
- $mark = '金豆';
- }elseif ($data['type'] == 4){
- //购物券
- if ($user['shop_integral'] < $data['anticipate']) return app('json')->fail('金豆不足');
- $me = User::find($data['uid']);
- $user['shop_integral'] -= $data['anticipate'];// 扣除购物券
- $me['shop_integral'] += $data['anticipate'];// 增加购物券
- $title = ['购物券减少', '购物券增加'];
- $category = 'shop_integral';
- $type = ['zz_shop_integral', 'js_shop_integral'];
- $mark = '购物券';
- }
- try {
- Db::startTrans();
- UserBill::expend($title[0],$user['uid'], $category, $type[0], $data['anticipate'], 0, $user['anticipate'], '转账给('.$me['nickname'].'-'.$me['uid'].')'.$data['anticipate'].$mark);
- UserBill::income($title[1],$me['uid'], $category, $type[1], $data['anticipate'], 0, $me['anticipate'], '接收('.$user['nickname'].'-'.$user['uid'].')的'.$data['anticipate'].$mark);
- $user->save();
- $me->save();
- Db::commit();
- return app('json')->successful('成功');
- } catch (\Exception $e) {
- Db::rollback();
- return app('json')->fail('失败');
- }
- }
- /**
- * 会馆
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function auction_gu(Request $request)
- {
- $data = UtilService::getMore([
- [['page', 'd'], 0],
- [['limit', 'd'], 0],
- ], $request);
- $uid = getParent($request->uid());
- $uid[] = $request->uid();
- $list = [];
- if ($uid){
- $list = AuctionGu::where('a.uid', 'in', $uid)
- ->where('a.status', 1)
- ->alias('a')
- ->field('a.*,u.nickname,u.avatar')
- ->leftJoin('user u', 'a.uid = u.uid')
- ->order('sort DESC')
- ->page($data['page'], $data['limit'])
- ->select();
- }
- $list = !empty($list) ? $list->toArray() : [];
- return app('json')->successful($list);
- }
- /**
- * 用户管理会馆
- * @param Request $request
- * @return mixed
- */
- public function user_gu(Request $request)
- {
- $data = UtilService::getMore([
- [['page', 'd'], 0],
- [['limit', 'd'], 0],
- ], $request);
- $list = AuctionGu::where('uid', $request->uid())->page($data['page'], $data['limit'])->select();
- $list = count($list) ? $list->toArray() : [];
- return app('json')->successful($list);
- }
- /**
- * 添加收款方式
- * @param Request $request
- * @return void
- */
- public function pay(Request $request)
- {
- $data = UtilService::postMore([
- ['payment'],
- ['image'],
- ['bank'],
- ['name'],
- ['type'],
- ['phone'],
- ['bank_name']
- ], $request);
- if (!$data['type']) return app('json')->fail('数据传入错误');
- $data['uid'] =$request->uid();
- $model = new AuctionPay();
- $pay = $model->where([['uid', '=', $request->uid()], ['type', '=', $data['type']]])->find();
- $res = Validate::rule([
- 'phone' => 'mobile'
- ]);
- $res->message([
- 'phone.mobile' => '请填写正确手机格式'
- ]);
- if (!$res->check($data)){
- return app('json')->fail($res->getError());
- }
- if (!empty($pay)){
- if ($data['type'] == 1 ){
- // 微信收款方式
- if (!$data['payment']) return app('json')->fail('微信账号不能为空');
- if (!$data['image']) return app('json')->fail('二维码不能为空');
- if (!$data['name']) return app('json')->fail('姓名不能为空');
- if (!$data['phone']) return app('json')->fail('请填写手机号');
- $pay['payment'] = $data['payment'];
- $pay['image'] = $data['image'];
- $pay['name'] = $data['name'];
- $pay['phone'] = $data['phone'];
- }elseif ($data['type'] == 2){
- // 支付宝收款方式
- if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
- if (!$data['name']) return app('json')->fail('姓名不能为空');
- if (!$data['phone']) return app('json')->fail('请填写手机号');
- $pay['payment'] = $data['payment'];
- $pay['name'] = $data['name'];
- $pay['phone'] = $data['phone'];
- }elseif ($data['type'] == 3){
- // 银行卡收款方式
- if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
- if (!$data['name']) return app('json')->fail('姓名不能为空');
- if (!$data['bank']) return app('json')->fail('开户行不能为空');
- if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
- if (!$data['phone']) return app('json')->fail('请填写手机号');
- $pay['payment'] = $data['payment'];
- $pay['bank'] = $data['bank'];
- $pay['bank_name'] = $data['bank_name'];
- $pay['phone'] = $data['phone'];
- $pay['name'] = $data['name'];
- }
- $res = $pay->save();
- if ($res) return app('json')->successful('修改成功');
- return app('json')->fail('修改失败');
- }else{
- if ($data['type'] == 1 ){
- // 微信收款方式
- if (!$data['payment']) return app('json')->fail('微信账号不能为空');
- if (!$data['image']) return app('json')->fail('二维码不能为空');
- if (!$data['name']) return app('json')->fail('姓名不能为空');
- if (!$data['phone']) return app('json')->fail('请填写手机号');
- }elseif ($data['type'] == 2){
- // 支付宝收款方式
- if (!$data['payment']) return app('json')->fail('支付宝账号不能为空');
- if (!$data['name']) return app('json')->fail('姓名不能为空');
- if (!$data['phone']) return app('json')->fail('请填写手机号');
- }elseif ($data['type'] == 3){
- // 银行卡收款方式
- if (!$data['payment']) return app('json')->fail('银行卡号不能为空');
- if (!$data['name']) return app('json')->fail('姓名不能为空');
- if (!$data['bank']) return app('json')->fail('开户行不能为空');
- if (!$data['bank_name']) return app('json')->fail('开户支行不能为空');
- if (!$data['phone']) return app('json')->fail('请填写手机号');
- }
- $res = $model->save($data);
- if ($res) return app('json')->successful('添加成功');
- return app('json')->fail('添加失败');
- }
- }
- /**
- * 收款方式详情
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function pay_list(Request $request)
- {
- $model = new AuctionPay();
- $list = $model->where('uid', $request->uid())->select();
- $list = empty($list)? []: $list->toArray();
- $data['wx'] = [];
- $data['zfb'] = [];
- $data['bank'] = [];
- foreach ($list as $k => $v){
- if ($v['type'] == 1){
- $data['wx'] = $v;
- }elseif ($v['type'] == 2){
- $data['zfb'] = $v;
- }elseif ($v['type'] == 3){
- $data['bank'] = $v;
- }
- }
- return app('json')->successful($data);
- }
- /**
- * 馆长申请
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function apply(Request $request)
- {
- $data = AuctionApply::where('status', '>', 0)->where('uid', $request->uid())->find();
- if (!$data){
- $res = AuctionApply::create([
- 'uid' => $request->uid()
- ]);
- if ($res)return app('json')->successful('申请成功');
- return app('json')->fail('申请失败');
- }
- return app('json')->fail('已申请,请等待管理员操作');
- }
- /**
- * 馆长申请
- * @param Request $request
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function apply_status(Request $request)
- {
- $data = AuctionApply::where('uid', $request->uid())->find();
- if (!$data){
- return app('json')->success(['status' => 0, 'str' => '未提交申请']); // 未提交申请
- }
- $data = AuctionApply::where([['status', '=', 1], ['uid', '=', $request->uid()]])->find();
- if ($data){
- return app('json')->success(['status' => 1, 'str' => '待审核']);// 待审核
- }
- $data = AuctionApply::where([['status', '=', 2], ['uid', '=', $request->uid()]])->find();
- if ($data){
- return app('json')->success(['status' => 2 ,'str' => '已完成']);// 已完成
- }
- $data = AuctionApply::where([['status', '=', 0], ['uid', '=', $request->uid()]])->find();
- if ($data){
- return app('json')->success(['status' => 3, 'str' => '失败']);// 失败
- }
- }
- /**
- * 倒计时
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function count_down(Request $request)
- {
- $data = UtilService::postMore([
- ['id'],
- ], $request);
- $list = Auction::where('id', $data['id'])->find();
- if (!$list) return app('json')->fail('场次不存在');// 失败
- $user = $request->user();
- $time = strtotime(date('Y-m-d', time()));// 今天
- $today = strtotime(date('Y-m-d', strtotime('+1day')));// 明天
- $datas = [];
- $datas['time'] = strtotime($list['radd_time']) - 60;
- $datas['times'] = strtotime($list['radd_time']);
- return app('json')->success($datas);// 失败
- }
- /**
- * 金豆兑换
- * @param Request $request
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function exchange_golden(Request $request)
- {
- $data = UtilService::postMore([
- ['price'],
- ['type']
- ], $request);
- if (empty($data['price'])) return app('json')->fail('传入兑换数量');
- if (empty($data['type'])) return app('json')->fail('传入兑换类型');
- $user = User::where('uid', $request->uid())->find();
- if ($data['type'] == 1){
- // 金豆兑换广告值
- $proportion = 2;
- $price = $data['price'] * $proportion;
- if ($user['golden_bean'] < $price) return app('json')->fail('金豆不足');
- $user['golden_bean'] -= $price;
- $user['anticipate'] += $data['price'];
- $user->save();
- UserBill::expend('金豆兑换广告值', $request->uid(), 'golden_bean', 'dh_golden_bean', $price, '', $user['golden_bean'], '金豆兑换'.$data['price'].'广告值');
- UserBill::income('广告值兑换', $request->uid(), 'anticipate', 'dh_anticipate', $data['price'], '', $user['anticipate'], '金豆兑换'.$data['price'].'广告值');
- }elseif ($data['type'] == 2) {
- // 金豆兑换趣豆
- $proportion = sys_config('integral');
- $price = $data['price'] * $proportion;
- if ($user['golden_bean'] < $price) return app('json')->fail('金豆不足');
- $user['golden_bean'] -= $price;
- $user['integral'] += $data['price'];
- $user->save();
- UserBill::expend('金豆兑换趣豆', $request->uid(), 'golden_bean', 'dh_golden_bean', $price, '', $user['golden_bean'], '金豆兑换'.$data['price'].'趣豆');
- UserBill::income('趣豆兑换', $request->uid(), 'integral', 'dh_integral', $data['price'], '', $user['integral'], '金豆兑换'.$data['price'].'趣豆');
- }else{
- return app('json')->fail('兑换类型不存在');
- }
- return app('json')->success('兑换成功');
- }
- }
|