From aeb45f7d21630515a279396930e9990439c2f2e0 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Tue, 25 Aug 2020 17:29:10 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=8B=E5=8D=95=E6=88=90=E5=8A=9F=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=B9=E4=BB=B7=E5=95=86=E5=93=81=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/PurchaseLimitController.php | 6 ++++++ app/Service/CouponService.php | 18 +++++++++++++----- app/Service/CouponServiceInterface.php | 2 +- app/Service/OrderService.php | 15 +++++++++++---- app/Service/PurchaseLimitService.php | 16 ++++++++++++---- app/Service/PurchaseLimitServiceInterface.php | 2 +- app/Service/ShopCarService.php | 2 +- config/routes.php | 2 +- 8 files changed, 46 insertions(+), 17 deletions(-) diff --git a/app/Controller/PurchaseLimitController.php b/app/Controller/PurchaseLimitController.php index 37870db..0dd222c 100644 --- a/app/Controller/PurchaseLimitController.php +++ b/app/Controller/PurchaseLimitController.php @@ -22,6 +22,12 @@ class PurchaseLimitController extends BaseController return $this->success($res); } + public function ssdbPurchaseRecord() + { + $res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214); + return $this->success($res); + } + public function test() { $res = $this->purchaseLimitService->test($this->request->all()); diff --git a/app/Service/CouponService.php b/app/Service/CouponService.php index c5cb7bd..e0469f1 100644 --- a/app/Service/CouponService.php +++ b/app/Service/CouponService.php @@ -226,13 +226,18 @@ class CouponService implements CouponServiceInterface * @param $order_id * @return bool */ - public function refundOrderCoupons($order_id,$user_id){ + public function refundOrderCoupons($order_id){ $coupon = CouponUserUse::where([ - ['order_main_id','=',$order_id], - ['status','=',CouponUserUse::COUPON_USE_STATE_USED], - ]) + ['order_main_id','=',$order_id], + ['status','=',CouponUserUse::COUPON_USE_STATE_USED], + ]) ->select('id','user_receive_id','number') ->first(); + + if (empty($coupon)) { + return ''; + } + // 返回用户优惠券数量并更新状态 $res = Db::update("UPDATE ims_system_coupon_user_receive SET number_remain=number_remain+{$coupon->number}, status=IF(number=number_remain,0,1), update_time=".time()."" ." WHERE id={$coupon->user_receive_id} AND number>=(number_remain+{$coupon->number})"); @@ -249,9 +254,12 @@ class CouponService implements CouponServiceInterface ]); //删除当日 redis 使用记录缓存 + $order_main = OrderMain::where('id',$order_id) + ->select('global_order_id','user_id') + ->first(); $redis = ApplicationContext::getContainer()->get(Redis::class); $remRes = $redis->sRem( - 'coupon_'.date('Ymd').'_used_'.$user_id, + 'coupon_'.date('Ymd').'_used_'.$order_main->user_id, $coupon->system_coupon_id ); return $res; diff --git a/app/Service/CouponServiceInterface.php b/app/Service/CouponServiceInterface.php index e4155d7..5220320 100644 --- a/app/Service/CouponServiceInterface.php +++ b/app/Service/CouponServiceInterface.php @@ -27,6 +27,6 @@ interface CouponServiceInterface */ public function getOrderCanUseCoupons($orderAmount, $marketId, $userId, $fields=[], $type=1, $storeTypeIds=[0]); - public function refundOrderCoupons($order_id,$user_id); + public function refundOrderCoupons($order_id); public function clearTodayCouponUsed($userId, $couponId); } diff --git a/app/Service/OrderService.php b/app/Service/OrderService.php index 8d76e7c..afd19fc 100644 --- a/app/Service/OrderService.php +++ b/app/Service/OrderService.php @@ -34,6 +34,12 @@ class OrderService implements OrderServiceInterface */ protected $couponService; + /** + * @Inject + * @var PurchaseLimitServiceInterface + */ + protected $purchaseLimitService; + /** * @inheritDoc */ @@ -271,6 +277,9 @@ class OrderService implements OrderServiceInterface return '订单商品异常'; } + //判断是否有购买特价商品 + $this->purchaseLimitService->ssdbPurchaseRecord($orderGoods,$data['user_id'],$dataMain['global_order_id']); + // 修改总订单金额,金额是计算来的 // TODO 这部分其实可以结合处理优化一下,循环前后关联处理太多 $updateOrderMain = OrderMain::query()->where(['id' => $orderMainId])->update(['money' => $orderAmountTotal, 'total_money' => $dataMain['money']]); @@ -705,12 +714,10 @@ class OrderService implements OrderServiceInterface * @inheritDoc */ public function onlineCancel($order_id){ - $order_main = OrderMain::where('id',$order_id) - ->select('global_order_id','user_id') - ->first(); OrderMain::where('id',$order_id) ->update(['state' => OrderMain::ORDER_STATE_CANCEL]); - $res = $this->couponService->refundOrderCoupons($order_id,$order_main->user_id); + //撤销redis 用券记录 + $res = $this->couponService->refundOrderCoupons($order_id); return $res; } /** diff --git a/app/Service/PurchaseLimitService.php b/app/Service/PurchaseLimitService.php index 7434bb0..2b84faa 100644 --- a/app/Service/PurchaseLimitService.php +++ b/app/Service/PurchaseLimitService.php @@ -29,11 +29,19 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface return $res; } - public function ssdbPurchaseRecord($params) + public function ssdbPurchaseRecord($data,$user_id,$global_order_id) { - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'], $params['order_id']); - $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id'],60); + foreach ($data as $k => $v){ + if($v['money'] == 0.01){ + //添加特价商品购买记录到ssdb + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $ssdb->exec('set', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'], $global_order_id); + $end_timestamp = strtotime(date('Y-m-d').'23:59:59'); + $end_time = $end_timestamp - time(); + $ssdb->exec('expire', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$user_id.'_'.$v['good_id'],$end_time); + } + } + return true; } public function test($params) diff --git a/app/Service/PurchaseLimitServiceInterface.php b/app/Service/PurchaseLimitServiceInterface.php index c2626c4..8811fc6 100644 --- a/app/Service/PurchaseLimitServiceInterface.php +++ b/app/Service/PurchaseLimitServiceInterface.php @@ -8,7 +8,7 @@ interface PurchaseLimitServiceInterface { public function getStoreIdByMarketId($params); - public function ssdbPurchaseRecord($params); + public function ssdbPurchaseRecord($params,$user_id,$global_order_id); public function test($params); } \ No newline at end of file diff --git a/app/Service/ShopCarService.php b/app/Service/ShopCarService.php index 7b20bc8..a739846 100644 --- a/app/Service/ShopCarService.php +++ b/app/Service/ShopCarService.php @@ -19,7 +19,7 @@ class ShopCarService implements ShopCarServiceInterface { //获取ssdb购买记录 $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $record_exists = $ssdb->exec('hexists',SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'], $params['good_id']); + $record_exists = $ssdb->exec('get',PURCHASE_RECORD. date('Ymd') .'_'.$params['user_id'].'_'.$params['good_id']); if($record_exists) { $error = [ diff --git a/config/routes.php b/config/routes.php index a0f385c..637d5ac 100644 --- a/config/routes.php +++ b/config/routes.php @@ -56,7 +56,7 @@ Router::addGroup('/v1/',function (){ //小程序支付相关 Router::post('wxminipay/online', 'App\Controller\PaymentController@wxminiPayOnline'); Router::post('wxminipay/offline', 'App\Controller\PaymentController@wxminiPayOffline'); - + //加入购物车 Router::post('ShopCar/addShopCar', 'App\Controller\ShopCarController@addShopCar'); Router::post('ShopCar/updateShopCar', 'App\Controller\ShopCarController@updateShopCar'); From 3ea7418a8a2fad97d9880e230b6c0022c7b66096 Mon Sep 17 00:00:00 2001 From: weigang Date: Tue, 25 Aug 2020 19:19:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?openid=E4=B8=BA=E7=A9=BA=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=8F=91=E9=80=81tempmsg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/MiniprogramService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Service/MiniprogramService.php b/app/Service/MiniprogramService.php index 2816f69..c74c0ac 100644 --- a/app/Service/MiniprogramService.php +++ b/app/Service/MiniprogramService.php @@ -155,6 +155,10 @@ class MiniprogramService implements MiniprogramServiceInterface */ public function sendTempMsg($openid, $template_id, $data, $redirect_url = '', $applet_config = ['appid' => '', 'pagepath' => '']) { + if (empty($openid) || empty($template_id) || empty($data)) { + return ; + } + // 先拼个基础的 $template = [ 'touser' => $openid,