From 7cf6e9efdabb38eedbfc0118152311bed041b3e6 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Thu, 27 Jan 2022 11:16:02 +0800 Subject: [PATCH] setter --- app/controller/api/Coupon.php | 76 +++++++++++++++++-------- app/controller/api/Dictionary.php | 15 ++++- app/repository/DictionaryRepository.php | 4 +- 3 files changed, 69 insertions(+), 26 deletions(-) diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 7a175e1..24e652f 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -67,31 +67,61 @@ class Coupon extends Base '(end_time > NOW()) as sort_weight']; $whereMap[] = ['consumer_code', '=', $accountCode]; - switch ($type) { - case 'all': - // 全部持有优惠券 - $sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc']; - break; - case 'notUsed': - // 未使用(包含已过期) - $whereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; - $sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc']; - break; - case 'normal': - // 未使用且未过期 - $whereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; - $whereMap[] = ['end_time', '< TIME', date('Y-m-d H:i:s')]; - break; - case 'used': - // 已使用 - $whereMap[] = ['is_verificated', '=', self::BOOL_TRUE]; - $sortOrder = ['verificate_time' => 'desc']; - break; - } +// switch ($type) { +// case 'all': +// // 全部持有优惠券 +// $sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc']; +// break; +// case 'notUsed': +// // 未使用(包含已过期) +// $whereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; +// $sortOrder = ['sort_weight' => 'desc', 'end_time' => 'asc']; +// break; +// case 'normal': +// // 未使用且未过期 +// $whereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; +// $whereMap[] = ['end_time', '> TIME', date('Y-m-d H:i:s')]; +// break; +// case 'used': +// // 已使用 +// $whereMap[] = ['is_verificated', '=', self::BOOL_TRUE]; +// $sortOrder = ['verificate_time' => 'desc']; +// break; +// } $res = CouponRepository::getInstance()->findList($whereMap, $fields, $page, $size,function ($q){ - return $q->with(["couponMain","scoreModel","business"]); + return $q->with(["couponMain","scoreModel","business"]) + ->where(function ($q){ + $notUsedWhereMap = [];//未过期 未使用 + $notUsedWhereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; + $notUsedWhereMap[] = ['end_time', '> TIME', date('Y-m-d H:i:s')]; + + $usedWhereMap = [];//已使用 7天内 + $usedWhereMap[] = ['is_verificated', '=', self::BOOL_TRUE]; + $usedWhereMap[] = ['verificate_time', '> TIME', date('Y-m-d H:i:s',time() - (7 * 86400)) ]; + + $beOverdueWhereMap = [];//未使用 已过期7天内 + $beOverdueWhereMap[] = ['is_verificated', '=', self::BOOL_FALSE]; + $beOverdueWhereMap[] = ['end_time', '> TIME', date('Y-m-d H:i:s',time() - (7 * 86400))];; + + + $q->whereOr(function ($q)use($notUsedWhereMap){ + $q->where($notUsedWhereMap); + })//未使用未过期 + + ->whereOr(function ($q)use($usedWhereMap){ + $q->where($usedWhereMap); + })//已使用 7天内 + + + ->whereOr(function ($q)use($usedWhereMap){ + $q->where($usedWhereMap); + });//已过期 + }) + //->fetchSql(true) + ; }, $sortOrder); + $time = time(); $res['list'] ->each(function ($item) use($time){ //重置优惠券名称 @@ -505,7 +535,7 @@ class Coupon extends Base //付款成功才提交!!!!!伪装成功 if(true||isset($result['payment_no']) ){ Db::commit(); - return $this->json(0,"优惠券签到使用成功,您获得{$consumerMoney}元红包,已存入您的零钱"); + return $this->json(0,"优惠券签到使用成功,您获得{$consumerMoney}元红包,已存入您的零钱",["redPacket"=>$consumerMoney]); } //Log::info("企业发起付款失败:" . json_encode($result,JSON_UNESCAPED_UNICODE)); } diff --git a/app/controller/api/Dictionary.php b/app/controller/api/Dictionary.php index 1a1e5f5..d6da49f 100644 --- a/app/controller/api/Dictionary.php +++ b/app/controller/api/Dictionary.php @@ -48,7 +48,20 @@ class Dictionary extends Base */ public function getBusinessCircle(): Json { - $items = DictionaryRepository::getInstance()->getAllBusinessCircleList(); + $lng = $this->request->param('lng/f', 0); // 经度 104.752890 + $lat = $this->request->param('lat/f', 0); // 纬度 31.465040 + $field = ["*"]; + $order = []; + + if ($lng && $lat) { + $field[] = "abs( (IFNULL(lat,0) - {$lng}) * (IFNULL(lng,0) - {$lat}) ) as square"; + $order["square"] = "asc"; + } + + $order["sort"] = "desc"; + $order["id"] = "desc"; + + $items = DictionaryRepository::getInstance()->getAllBusinessCircleList($field,$order); $items->each(function ($item) { $areaText = ''; if (!empty($item['province_text'])) { diff --git a/app/repository/DictionaryRepository.php b/app/repository/DictionaryRepository.php index 7e9cb1a..58bc4d7 100644 --- a/app/repository/DictionaryRepository.php +++ b/app/repository/DictionaryRepository.php @@ -44,11 +44,11 @@ class DictionaryRepository extends Repository /** * 获取所有的商圈数据 */ - public function getAllBusinessCircleList(array $fields=[]) + public function getAllBusinessCircleList(array $fields=[],$order = ['sort'=>'desc', 'id'=>'desc']) { try { return BusinessCircle::field($fields) - ->order(['sort'=>'desc', 'id'=>'asc']) + ->order($order) ->select(); } catch (\Exception $e) { return new Collection();