// +---------------------------------------------------------------------- namespace app\controller\api\v2\activity; use app\controller\store\AuthController; use app\services\activity\coupon\StoreCouponIssueServices; use app\services\product\product\StoreProductCouponServices; use think\facade\Db; use think\Request; /** * 优惠券 * Class StoreCoupons * @package app\controller\api\v2\store */ class StoreCoupons extends AuthController { protected $services; public function __construct(StoreCouponIssueServices $services) { $this->services = $services; } /** * 可领取优惠券列表 * @param \app\Request $request * @return mixed */ public function lst(Request $request) { $where = $request->getMore([ [['type', 'd'], ''], [['product_id', 'd'], 0], [['brand_id', 'd'], 0], ['defaultOrder', ''], ['timeOrder', ''], ['priceOrder', ''] ]); return app('json')->successful($this->services->getIssueCouponList($request->uid(), $where, '*', true)); } /** * 获取新人券 * @return mixed */ public function getNewCoupon(Request $request) { $userInfo = $request->user(); $data = []; /** @var StoreCouponIssueServices $couponService */ $couponService = app()->make(StoreCouponIssueServices::class); $data['list'] = $couponService->getNewCoupon(); $data['image'] = ''; if ($userInfo->add_time === $userInfo->last_time) { $data['show'] = 1; } else { $data['show'] = 0; } //会员领取优惠券 //$couponService->sendMemberCoupon($userInfo->uid); return app('json')->success($data); } /** * 赠送下单之后订单中 关联优惠劵 * @param Request $request * @param $orderId * @return mixed */ public function getOrderProductCoupon(Request $request, $orderId) { $uid = (int)$request->uid(); if (!$orderId) { return app('json')->fail('参数错误'); } /** @var StoreProductCouponServices $storeProductCoupon */ $storeProductCoupon = app()->make(StoreProductCouponServices::class); $list = $storeProductCoupon->getOrderProductCoupon($uid, $orderId); return app('json')->success($list); } /** * 获取每日新增的优惠券 * @return mixed */ public function getTodayCoupon(Request $request) { $uid = 0; if ($request->hasMacro('uid')) $uid = (int)$request->uid(); /** @var StoreCouponIssueServices $couponService */ $couponService = app()->make(StoreCouponIssueServices::class); $data['list'] = $couponService->getTodayCoupon($uid); $data['image'] = ''; return app('json')->success($data); } //wmc api //台桌列表 public function getTableList(Request $request, $cate_id) { $list = Db::name('table_qrcode') ->where('cate_id', $cate_id) ->where('is_use', 0) ->select()->toArray(); return app('json')->success('ok', $list); } //台桌详情 public function getTableDetail(Request $request, $id) { $info = Db::name('table_qrcode') ->where('id', $id) ->find(); //营销经理列表 $info['yingxiao'] = Db::name('user') ->field('uid,nickname') ->where('group_id', 2) ->select(); return app('json')->success('ok', $info); } //台桌预定 public function tableYuDing(Request $request) { $uid = (int)$request->uid(); // if(!$uid){ // return app('json')->fail('预定失败,请先登录'); // } $post = $request->postMore([ ['table_id', 0], ['user_id', $uid], ['phone', 0], ['yuding_date', 0], ['come_date', 0], ['create', time()], ['admin_id', ''], ['remark', ''], ['store_id',1] ]); //校验这个桌子有无在使用 $info = Db::name('table_qrcode') ->where('id', $post['table_id']) ->find(); if(!$info){ return app('json')->fail('预定失败'); } if($info['is_use'] != 0){ return app('json')->fail('预定失败,台桌正在使用中'); } //插入预定表 Db::name('table_yuding')->insert($post); //改桌子状态 Db::name('table_qrcode')->where('id',$post['table_id'])->update(['is_use'=>2]); return app('json')->success('预定成功'); } //存酒记录 public function getcunjiu(Request $request) { $uid = (int)$request->uid(); if(!$uid){ $list = []; }else{ $list = Db::name('store_drink_save') ->order('id desc') ->where('uid', $uid) ->select()->toArray(); foreach ($list as &$v){ $v['table_number'] = Db::name('table_qrcode') ->where('id', $v['table_id']) ->value('table_number'); $v['c_time'] = date('Y-m-d H:i:s',$v['create']); } } return app('json')->success('ok', $list); } //取酒记录 public function getqujiu(Request $request) { $uid = (int)$request->uid(); if(!$uid){ $list = []; }else{ $list = Db::name('store_drink_log') ->alias('a') ->order('a.id desc') ->leftJoin('eb_store_drink_save b', 'a.pid = b.id') ->field('b.*,a.content') ->where('a.uid', $uid) ->where('a.type',2) ->select()->toArray(); foreach ($list as &$v){ $v['table_number'] = Db::name('table_qrcode') ->where('id', $v['table_id']) ->value('table_number'); $v['c_time'] = date('Y-m-d H:i:s',$v['create']); $str = $v['content']; $startPos = strpos($str, '】'); $endPos = strpos($str, '瓶', $startPos); if ($startPos!== false && $endPos!== false) { $number = substr($str, $startPos + 5, $endPos - $startPos - 5); } $v['num'] = $number; } } return app('json')->success('操作成功',$list); } }