From fd4e802258e921398f5dbcbae9fb0f29ec913701 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Mon, 6 Dec 2021 18:56:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 34 ++++++- app/controller/api/Business.php | 64 +++++++++++- app/controller/api/Consumer.php | 83 ++++++++++++++- app/controller/api/Coupon.php | 87 ++++++++++++++++ app/controller/api/User.php | 17 ++++ app/model/BusinessFlow.php | 1 + app/repository/BusinessRepository.php | 2 + app/repository/CouponRepository.php | 16 +++ app/repository/DictionaryRepository.php | 28 ++++++ app/traits/CouponMainTrait.php | 40 ++++++++ app/traits/CouponTrait.php | 122 +++++++++++++++++++++-- app/traits/account/BusinessFlowTrait.php | 47 ++++++++- route/api.php | 17 ++-- view/manager/coupon/add.html | 8 +- view/manager/coupon/edit.html | 23 ++++- 15 files changed, 554 insertions(+), 35 deletions(-) create mode 100644 app/traits/CouponMainTrait.php diff --git a/app/common.php b/app/common.php index 87816b1..52e6feb 100644 --- a/app/common.php +++ b/app/common.php @@ -826,7 +826,9 @@ if (!function_exists('getEarthSquareRangePoint')) { } } - +/** + * 获取两个地点之鉴的距离 + * */ if (!function_exists('get_distance')) { function get_distance($lat1, $lng1, $lat2, $lng2) { @@ -842,4 +844,32 @@ if (!function_exists('get_distance')) { $calculatedDistance = $earthRadius * $stepTwo; return round($calculatedDistance); } -} \ No newline at end of file +} + +/** + * 格式化优惠券的使用周期 + * */ +if (!function_exists('encodeCouponCycle')) { + function encodeCouponCycle(array $week) + { + $font =[ + "0"=>"星期天", + "1"=>"星期一", + "2"=>"星期二", + "3"=>"星期三", + "4"=>"星期四", + "5"=>"星期五", + "6"=>"星期六", + ]; + + $str = []; + foreach ($week as $value){ + if (isset($font[$value])) { + $str[] = $font[$value]; + } + } + return implode(",",$str); + } +} + + diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index 1e434b6..b07c6cf 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -6,13 +6,12 @@ use app\model\BusinessCircle; use app\model\Category; use app\repository\AccountRepository; use app\repository\BusinessRepository; +use app\repository\CouponRepository; use app\repository\DictionaryRepository; use app\validate\BusinessValidate; +use think\Collection; use think\exception\ValidateException; -use app\model\{ - Business as BusinessModel, - Account as AccountModel -}; +use app\model\{Business as BusinessModel, Account as AccountModel, CouponMain}; use think\response\Json; /** @@ -23,6 +22,10 @@ use think\response\Json; */ class Business extends Base { + + protected $noNeedLogin = [ + 'couponDetail', + ]; /** * 商家认证注册 * @@ -217,6 +220,59 @@ class Business extends Base $data = BusinessCircle::getList(); return $this->json(1,"ok",$data); } + + /** + * 商家优惠券详情 + * */ + public function couponDetail() + { + $accountId = $this->request->user['user_id'] ?? 0; + $account = AccountRepository::getInstance()->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + + $couponMainId = input("id/d"); + $couponMain = CouponMain::findOne(["id"=>$couponMainId]); + if(empty($couponMain)){ + return $this->json(4001,"优惠券不存在"); + } + if(!$business = BusinessRepository::getInstance()->findOneByWhere(["code"=>$couponMain["business_code"]])){ + return $this->json(4001,"优惠券商家信息不存在"); + } + + $list = $business->toArray(); + $list = DictionaryRepository::getInstance()->parseAreaText($list); + + $data = []; + + $data["businessAddress"] = $list['province_text'] . $list['city_text'] . $list['county_text'] . $business['business_address']; + $data["businessName"] = $list['business_name']; + $data["count"] = $couponMain->count; + $data["couponName"] = $couponMain->name; + $data["deductionMoney"] = $couponMain->deduction_money; + $data["startTime"] = $couponMain->start_time; + $data["endTime"] = $couponMain->end_time; + $data["id"] = $couponMain->id; + $data["imageUrl"] = $this->request->domain(). $couponMain->image_url; + $data["intro"] = $couponMain->intro;//简介 + $data["lat"] = $couponMain->lat; + $data["lng"] = $couponMain->lng; + $data["money"] = $couponMain->money; + $data["usingRule"] = DictionaryRepository::getInstance()->getUsingRuleByCouponMainId($couponMain->id); + $data["punishRule"] = '';//处罚规则 已取消 + + //未登录可以领取 0可领取 1已领取 + if (empty($account)) { + $data["receiveStatus"] = CouponMain::COMMON_OFF;//领取状态 + }else{ + $data["receiveStatus"] = AccountRepository::getInstance()->getCouponReceiveStatus($account->user_code,$couponMain);//领取状态 + } + $data["receivedCount"] = $couponMain->received_count;//已领取数量 + $data["typeName"] = $couponMain->type_name; + + return $this->json(0,"success",$data); + } + } diff --git a/app/controller/api/Consumer.php b/app/controller/api/Consumer.php index 93e5334..1580e9e 100644 --- a/app/controller/api/Consumer.php +++ b/app/controller/api/Consumer.php @@ -3,9 +3,13 @@ namespace app\controller\api; use app\model\CouponMain; use app\model\Slide; +use app\repository\AccountRepository; +use app\repository\BusinessRepository; use app\repository\CouponRepository; use app\repository\OperationRepository; use think\Collection; +use think\Exception; +use think\exception\ValidateException; use think\response\Json; /** @@ -30,6 +34,7 @@ class Consumer extends Base $params = [ 'businessType' => $this->request->param('businessType/d', 0), // 商家类型 'couponType' => $this->request->param('couponType/d', 0), // 优惠卷类型 + 'businessCode' => $this->request->param('businessCode/s'), // 商家code 'dis' => $this->request->param('dis/d', -1), // 距离,单位为km 'lng' => $this->request->param('lng/f', 0), // 经度 104.752890 'lat' => $this->request->param('lat/f', 0), // 纬度 31.465040 @@ -51,12 +56,12 @@ class Consumer extends Base $whereMap[] = ['status', '=', CouponMain::status_on]; $whereMap[] = ['on_shelf', '=', CouponMain::on_shelf_on]; - $whereMap[] = ['start_time', '> TIME', $nowDate]; - $whereMap[] = ['end_time', '< TIME', $nowDate]; + //$whereMap[] = ['start_time', '< TIME', $nowDate]; + $whereMap[] = ['end_time', '> TIME', $nowDate]; $whereMap[] = ['using_count', '>', 0]; if (!empty($params['keyword'])) { - $whereMap[] = ['name', 'like', "%{$params['keyword']}%"]; + $whereMap[] = ['name', 'like', "%".$params['keyword']."%"]; } if ($params['businessType'] > 0) { $whereMap[] = ['business_type', '=', $params['businessType']]; @@ -64,6 +69,9 @@ class Consumer extends Base if ($params['couponType'] > 0) { $whereMap[] = ['type', '=', $params['couponType']]; } + if (!empty($params['businessCode'])) { + $whereMap[] = ['business_code', '=', $params['businessCode']]; + } if ($params['dis'] > 0) { $pointList = getEarthSquareRangePoint($params['lat'],$params['lng'], $params['dis']); @@ -76,7 +84,9 @@ class Consumer extends Base } } - $res = $repo->findCouponMainList($whereMap, [], $params['page'], $params['size'], function ($q) use($lngRange, $latRange, $params) { + + + $res = $repo->findCouponMainList($whereMap,[], $params['page'], $params['size'], function ($q) use($lngRange, $latRange, $params) { return $q->when(!empty($lngRange) && !empty($latRange), function($query) use($lngRange, $latRange){ $query->where(function ($queryB) use($lngRange) { $queryB->whereOr($lngRange); @@ -85,8 +95,20 @@ class Consumer extends Base ->field("*, abs( (IFNULL(lat,0) - {$params['lat']}) * (IFNULL(lng,0) - {$params['lng']}) ) as square"); }, $sortOrder); + $accountRepo= AccountRepository::getInstance(); - $res['list']->each(function ($item)use($params){ + $accountId = $this->request->user['user_id'] ?? 0; + $flowArray = []; + if ($accountId) { + $account = $accountRepo->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + if (!empty($account)) { + $flowArray = $accountRepo->getBusinessFlowCodeArray($account->user_code); + } + } + + $res['list']->each(function ($item)use($params,$flowArray){ unset($item->square); $distance = (get_distance($params["lat"], $params["lng"], $item["lat"],$item["lng"])); if ($distance >= 1000) { @@ -95,6 +117,14 @@ class Consumer extends Base $item->distance_text = $distance . "m"; } + //是否收藏了该优惠券的商家 + $item->isFlow = in_array($item->business_code,$flowArray); + + $item->couponId = $item->id; + $item->businessCode = $item->business_code; + $item->businessName = $item->business_name; + $item->cover = $this->request->domain().$item->image_url; + $item->couponName = $item->name; }); return $this->json(0, 'success', $res); @@ -127,4 +157,47 @@ class Consumer extends Base }, $orders); return $this->json(1,"ok",$list["list"]); } + + + /** + * 关注/取消关注一个商家 + * */ + public function flowBusiness() + { + + $accountId = $this->request->user['user_id'] ?? 0; + + + $accountRepo = AccountRepository::getInstance(); + try { + $account = $accountRepo->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + if (empty($account)) { + throw new ValidateException('用户无效!'); + } + + $businessCode = input("businessCode/s"); + $business = BusinessRepository::getInstance()->findOneByWhere(["code"=>$businessCode]); + if(empty($business)){ + throw new ValidateException('商家无效!'); + } + $businessFlow = $accountRepo->hasBusinessFlow($account->user_code,$businessCode); + + //如果关注了 就删除 + if($businessFlow){ + $businessFlow->delete(); + }else{ + //没有关注就添加 + $accountRepo->createBusinessFlow($account->user_code,$businessCode,$business->business_name); + } + return $this->json(); + + } catch (ValidateException $e) { + return $this->json(4001, $e->getError()); + } catch (Exception $e) { + return $this->json(5001, '服务器繁忙!'); + } + + } } \ No newline at end of file diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index bd2d04c..3fb0b07 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -2,7 +2,12 @@ namespace app\controller\api; use app\exception\RepositoryException; +use app\model\CouponMain; +use app\repository\AccountRepository; use app\repository\CouponRepository; +use think\Exception; +use think\facade\Db; +use think\facade\Log; /** * 优惠卷相关 @@ -65,5 +70,87 @@ class Coupon extends Base } catch (RepositoryException | \Exception $e) { return $this->json(5001, '优惠卷查询失败!'); } + } + + /** + * 领取优惠券 + * */ + public function receiveCoupon() + { + $accountId = $this->request->user['user_id'] ?? 0; + $lat = input("lat/f",0); + $lng = input("lng/f",0); + $account = AccountRepository::getInstance()->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + if(empty($account)){ + return $this->json(6001,"无效的用户"); + } + + if ($lat <= 0 || $lng <= 0) { + return $this->json(4001, "请授权定位"); + } + + $couponMainId = input("couponId/d", 0); + $couponMain = CouponMain::findOne(["id" => $couponMainId],[],function ($q){ + //执行领取 开启锁 + return $q->with("business")->lock(true); + }); + + //检查优惠券状态 + $checkCouponMainReceiveStatus = CouponRepository::getInstance()->checkCouponMainReceiveStatus($couponMain); + if( $checkCouponMainReceiveStatus !== true ){ + return $checkCouponMainReceiveStatus; + } + + try { + //检查是否可以领取 0可领取 1已领取 + AccountRepository::getInstance()->getCouponReceiveStatusText($account->user_code,$couponMain);//领取状态 + }catch (RepositoryException $e){ + return $this->json(4001,$e->getMessage()); + } + + + + //检查通过 执行领取 + $time = time(); + Db::startTrans(); + try { + //写入领取记录 + $data = [ + "coupon_id" =>$couponMain->id, + "name" =>$couponMain->name, + "type_id" =>$couponMain->type, + "type_name" =>$couponMain->type_name, + "business_code" =>$couponMain->business_code, + "business_name" =>$couponMain->business?$couponMain->business->business_name:'', + "consumer_code" =>$account->user_code, + "consumer_name" =>$account->nick_name, + "money" => $couponMain->money, + "content" => createUuid(),//未知作用 + "received_time" => date("Y-m-d H:i:s",$time), + "lat" => $lat, + "lng" => $lng, + "end_time" => date($couponMain->end_time . " 00:00:00"), + "edition" => couponMain::COMMON_ON,//版本 未知作用 + "is_verificated" => couponMain::COMMON_OFF,//版本 未知作用 + ]; + CouponRepository::getInstance()->receiveCoupon($data); + Db::commit(); + return $this->json(); + }catch (RepositoryException $e){ + Log::error("优惠券领取失败RepositoryException:".$e->getMessage()); + Db::rollback(); + return $this->json(5001,"领取失败"); + }catch (Exception $e){ + Log::error("优惠券领取失败:".$e->getMessage()); + Db::rollback(); + return $this->json(5001,"领取失败"); + } + + + + + } } \ No newline at end of file diff --git a/app/controller/api/User.php b/app/controller/api/User.php index 78d40f4..050ce38 100644 --- a/app/controller/api/User.php +++ b/app/controller/api/User.php @@ -231,8 +231,25 @@ class User extends Base * */ public function businessFlowList() { + return false; $page = $this->request->param('page/d', 1); $size = $this->request->param('size/d', 30); + + $accountRepo = AccountRepository::getInstance(); + try { + $account = $accountRepo->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + if (empty($account)) { + throw new ValidateException('用户无效!'); + } + }catch (ValidateException $e) { + return $this->json(4001, $e->getError()); + } catch (Exception $e) { + return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); + } $data = AccountRepository::getInstance()->getBusinessFlowList(); } + + } \ No newline at end of file diff --git a/app/model/BusinessFlow.php b/app/model/BusinessFlow.php index 126769b..0f95b24 100644 --- a/app/model/BusinessFlow.php +++ b/app/model/BusinessFlow.php @@ -5,6 +5,7 @@ namespace app\model; //用户关注的商家 class BusinessFlow extends Base { + public function account() { return $this->hasOne(Account::class,"user_code","user_code"); diff --git a/app/repository/BusinessRepository.php b/app/repository/BusinessRepository.php index 5ec6fa4..ac4fb6f 100644 --- a/app/repository/BusinessRepository.php +++ b/app/repository/BusinessRepository.php @@ -9,6 +9,7 @@ use app\model\Deduction; use app\model\Recharge; use app\service\Repository; use app\traits\CouponBillTrait; +use app\traits\CouponMainTrait; use think\Collection; use think\Model; @@ -22,6 +23,7 @@ use think\Model; class BusinessRepository extends Repository { use CouponBillTrait; + use CouponMainTrait; /** * 根据条件查询列表 diff --git a/app/repository/CouponRepository.php b/app/repository/CouponRepository.php index 516eeef..ff0d196 100644 --- a/app/repository/CouponRepository.php +++ b/app/repository/CouponRepository.php @@ -8,6 +8,7 @@ use app\model\CouponMain; use app\model\CouponType; use app\model\UsingRule; use app\service\Repository; +use app\traits\CouponMainTrait; use Exception; use think\Collection; use think\Db; @@ -23,6 +24,7 @@ use think\Model; */ class CouponRepository extends Repository { + use CouponMainTrait; /** * 优惠券持有信息列表 * @@ -98,4 +100,18 @@ class CouponRepository extends Repository return CouponMain::findList($where, $fields, $page, $size, $call, $sortOrder); } + /** + * 写入一个领取优惠券 + * @param array $data + * @return Coupon|Model + */ + public function receiveCoupon(array $data) + { + return Coupon::create($data); + } + + + + + } \ No newline at end of file diff --git a/app/repository/DictionaryRepository.php b/app/repository/DictionaryRepository.php index a6eae2f..0660ea0 100644 --- a/app/repository/DictionaryRepository.php +++ b/app/repository/DictionaryRepository.php @@ -6,6 +6,7 @@ use app\model\Area; use app\model\BusinessCircle; use app\model\Category; use app\model\Model; +use app\model\UsingRule; use app\service\Repository; use think\Collection; @@ -74,6 +75,11 @@ class DictionaryRepository extends Repository /** * 获取商家分类数据 + * @param array $where + * @param array $fields + * @param callable|null $call + * @param array $order + * @return mixed|Collection */ public function getBusinessTypeList(array $where=[], array $fields = [], callable $call=null, array $order = []) { @@ -131,6 +137,9 @@ class DictionaryRepository extends Repository /** * 解析地址编码 * [province, city, county] + * @param array $list + * @param array $areaList + * @return array */ public function parseAreaText(array $list, array $areaList = []): array { @@ -149,4 +158,23 @@ class DictionaryRepository extends Repository return $list; } + /** + * 获取一个优惠券的使用规则 + * @param int $couponMainId + * @return string + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getUsingRuleByCouponMainId(int $couponMainId) + { + $usingRule =UsingRule::where("coupon_id",$couponMainId)->find(); + if(empty($usingRule)){ + return ''; + } + return "
该优惠券可以在" . encodeCouponCycle($usingRule->cycle) . "进行使用
+
该优惠券可以在每天的" . $usingRule->day_start_time ."到" .$usingRule->day_end_time ."进行使用
+
该优惠券每天每人可以领取". $usingRule->person_day_total ."张
+
该优惠券每人总共可以领取". $usingRule->person_total ."张
"; + } } \ No newline at end of file diff --git a/app/traits/CouponMainTrait.php b/app/traits/CouponMainTrait.php new file mode 100644 index 0000000..b79d304 --- /dev/null +++ b/app/traits/CouponMainTrait.php @@ -0,0 +1,40 @@ +json(4001, "优惠券不存在"); + } + if ($couponMain->status != CouponMain::status_on) { + return $this->json(4002, "优惠券已停用"); + } + if ($couponMain->on_shelf != CouponMain::on_shelf_on) { + return $this->json(4003, "优惠券已下架"); + } + $time = time(); + if (strtotime($couponMain->start_time) > $time) { + return $this->json(4004, "优惠券还未发行"); + } + + if (strtotime($couponMain->end_time) < $time) { + return $this->json(4004, "优惠券已结束使用"); + } + + if ($couponMain->using_count <= 0) { + return $this->json(4004, "优惠券已经被领完了"); + } + return true; + } +} \ No newline at end of file diff --git a/app/traits/CouponTrait.php b/app/traits/CouponTrait.php index 93cb06d..432beef 100644 --- a/app/traits/CouponTrait.php +++ b/app/traits/CouponTrait.php @@ -2,6 +2,9 @@ namespace app\traits; +use app\exception\RepositoryException; +use app\model\CouponMain; +use app\model\UsingRule; use think\Model; use app\model\Coupon; @@ -21,8 +24,6 @@ trait CouponTrait /**消费者已使用优惠券总数 * @param string $userCode - * - * * @return int */ public function consumerUsedTotalCoupon($userCode) @@ -30,10 +31,9 @@ trait CouponTrait return Coupon::where("consumer_code", $userCode)->where("is_verificated", Coupon::is_verificated_on)->count("id"); } - /**消费者已使用优惠券总数 + /** + * 消费者已使用优惠券总数 * @param string $userCode - * - * * @return int */ public function consumerNotUsedTotalCoupon($userCode) @@ -41,10 +41,9 @@ trait CouponTrait return Coupon::where("consumer_code", $userCode)->where("is_verificated", Coupon::is_verificated_off)->count("id"); } - /**消费者已使用优惠券总数 + /** + * 消费者已使用优惠券总数 * @param string $userCode - * - * * @return array * @throws \Exception */ @@ -55,5 +54,112 @@ trait CouponTrait }, ["id" => "desc"]); } + /** + * 查看某个优惠券的是否可以领取 0 可以领取 1 已领取不能再领取 + * @param $accountCode + * @param CouponMain $couponMain + * @return int + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getCouponReceiveStatus($accountCode,CouponMain $couponMain ) + { + //没有领取记录就可以领取 + $ReceiveCount = Coupon::where("coupon_id",$couponMain->id) + ->where("consumer_code",$accountCode) + ->count(); + if($ReceiveCount <= 0){ + return CouponMain::COMMON_OFF; + } + //确定使用规则 + $usingRule =UsingRule::where("coupon_id",$couponMain->id)->find(); + if(empty($usingRule)){ + return CouponMain::COMMON_OFF; + } + + //单人日限量 + $todayReceivesCount = Coupon::where("coupon_id",$couponMain->id) + ->where("consumer_code",$accountCode) + ->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")]) + ->count(); + + if($todayReceivesCount >= $usingRule->person_day_total ){ + + return CouponMain::COMMON_ON; + } + + + //单人总限量 + if($ReceiveCount >= $usingRule->person_total ){ + return CouponMain::COMMON_ON; + } + + return CouponMain::COMMON_OFF; + } + + + /** + * 查看某个优惠券的是否可以领取 0 可以领取 1 已领取不能再领取 + * @param $accountCode + * @param CouponMain $couponMain + * @return void + * @throws RepositoryException + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getCouponReceiveStatusText($accountCode,CouponMain $couponMain ) + { + //没有领取记录就可以领取 + $ReceiveCount = Coupon::where("coupon_id",$couponMain->id) + ->where("consumer_code",$accountCode)->count(); + + + //确定使用规则 + $usingRule =UsingRule::where("coupon_id",$couponMain->id)->find(); + if(empty($usingRule)){ + throw new RepositoryException("使用规则错误,不能领取"); + } + + + //一天的总限量 + $dayTotalReceivesCount = Coupon::where("coupon_id",$couponMain->id) + ->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")]) + ->count(); + if($dayTotalReceivesCount >= $usingRule->day_total){ + throw new RepositoryException("单日领取总限量达到上限"); + } + + + //单人日限量 + $todayReceivesCount = Coupon::where("coupon_id",$couponMain->id) + ->where("consumer_code",$accountCode) + ->whereTime("received_time","between",[date("Y-m-d 00:00:00"),date("Y-m-d 23:59:59")]) + ->count(); + if($todayReceivesCount >= $usingRule->person_day_total ){ + throw new RepositoryException("单人日限量达到上限"); + } + + //单人总限量 + if($ReceiveCount >= $usingRule->person_total ){ + throw new RepositoryException("单人总限量达到上限"); + } + + + + + + $time = time(); + //一天的开始时间 + if(strtotime(date("Y-m-d " . $usingRule->day_start_time)) > $time){ + throw new RepositoryException("请在当天{$usingRule->day_start_time}后来领取"); + } + //一天的结束时间 + if(strtotime(date("Y-m-d ".$usingRule->day_end_time)) < $time){ + throw new RepositoryException("请在当天{$usingRule->day_start_time}前领取"); + } + + } } \ No newline at end of file diff --git a/app/traits/account/BusinessFlowTrait.php b/app/traits/account/BusinessFlowTrait.php index ecde742..7739152 100644 --- a/app/traits/account/BusinessFlowTrait.php +++ b/app/traits/account/BusinessFlowTrait.php @@ -29,4 +29,49 @@ trait BusinessFlowTrait ->page($page,$size) ->select(); } -} \ No newline at end of file + + /** + * 获取关注的商家的code + * @param $accountCode + * @return array + */ + public function getBusinessFlowCodeArray($accountCode) + { + return BusinessFlow::where("user_code",$accountCode) + ->column("business_code"); + } + + /** + * 获取关注的商家的code + * @param $accountCode + * @param $businessCode + * @return BusinessFlow|array|\think\Model|null + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function hasBusinessFlow($accountCode,$businessCode) + { + return BusinessFlow::where("user_code",$accountCode) + ->where("business_code",$businessCode) + ->find(); + } + + /** + * 关注一个商家 + * @param $accountCode + * @param $businessCode + * @param $businessName + * @return BusinessFlow|\think\Model + */ + public function createBusinessFlow($accountCode,$businessCode,$businessName) + { + return BusinessFlow::create([ + "user_code"=>$accountCode, + "business_code"=>$businessCode, + "business_name"=>$businessName, + "create_time"=>date("Y-m-d H:i:s") + ]); + } + +} diff --git a/route/api.php b/route/api.php index a35db7e..606bd99 100644 --- a/route/api.php +++ b/route/api.php @@ -10,11 +10,12 @@ // +---------------------------------------------------------------------- use think\facade\Route; -Route::rule('account/loginByCode', "\\app\\controller\\api\\user@login");//用户登录 -Route::rule('consumer/home', "\\app\\controller\\api\\Consumer@home");//首页列表(优惠券列表) -Route::rule('consumer/bannerList', "\\app\\controller\\api\\Consumer@bannerList");//首页列表(优惠券列表) -Route::rule('dic/getDisList', "\\app\\controller\\api\\dictionary@getDisList");//距离选项列表 -Route::rule('dic/getBusinessTypeListByPid', "\\app\\controller\\api\\dictionary@getBusinessTypeList");//首页获取商家类型 -Route::rule('dic/getCouponTypeList', "\\app\\controller\\api\\dictionary@getCouponTypeList");//首页获取优惠券类型 -Route::rule('dic/getBusinessTypeList', "\\app\\controller\\api\\business@getBusinessTypeList");//首页获取商家类型 -Route::rule('dic/getBusinessCircle', "\\app\\controller\\api\\business@getBusinessCircle");//首页获取商家商圈 +//Route::rule('account/loginByCode', "\\app\\controller\\api\\user@login");//用户登录 +//Route::rule('consumer/home', "\\app\\controller\\api\\consumer@home");//首页列表(优惠券列表) +//Route::rule('consumer/bannerList', "\\app\\controller\\api\\consumer@bannerList");//首页列表(优惠券列表) +//Route::rule('dic/getDisList', "\\app\\controller\\api\\dictionary@getDisList");//距离选项列表 +//Route::rule('dic/getBusinessTypeListByPid', "\\app\\controller\\api\\dictionary@getBusinessTypeList");//首页获取商家类型 +//Route::rule('dic/getCouponTypeList', "\\app\\controller\\api\\dictionary@getCouponTypeList");//首页获取优惠券类型 +//Route::rule('dic/getBusinessTypeList', "\\app\\controller\\api\\business@getBusinessTypeList");//首页获取商家类型 +//Route::rule('dic/getBusinessCircle', "\\app\\controller\\api\\business@getBusinessCircle");//首页获取商家商圈 +//Route::rule('consumer/flowBusiness', "\\app\\controller\\api\\consumer@flowBusiness");//首页获取商家商圈 diff --git a/view/manager/coupon/add.html b/view/manager/coupon/add.html index f854ff8..4f15668 100644 --- a/view/manager/coupon/add.html +++ b/view/manager/coupon/add.html @@ -121,13 +121,13 @@
- +
- +
@@ -176,8 +176,8 @@
-
- + +
diff --git a/view/manager/coupon/edit.html b/view/manager/coupon/edit.html index ec91d04..c29d786 100644 --- a/view/manager/coupon/edit.html +++ b/view/manager/coupon/edit.html @@ -178,8 +178,8 @@
-
- + +
@@ -234,4 +234,21 @@ - \ No newline at end of file + + + \ No newline at end of file