Browse Source

Merge branch 'purchase_limit' of ssh://120.24.33.109:11022/hyzjshwo/lanzu_api_hyperf into purchase_limit

# Conflicts:
#	app/Service/OrderService.php
master
liangyuyan 6 years ago
parent
commit
7cd329b4fd
  1. 12
      app/Controller/PurchaseLimitController.php
  2. 18
      app/Service/CouponService.php
  3. 2
      app/Service/CouponServiceInterface.php
  4. 4
      app/Service/MiniprogramService.php
  5. 17
      app/Service/OrderService.php
  6. 43
      app/Service/PurchaseLimitService.php
  7. 4
      app/Service/PurchaseLimitServiceInterface.php
  8. 2
      app/Service/ShopCarService.php
  9. 3
      config/routes.php

12
app/Controller/PurchaseLimitController.php

@ -22,6 +22,18 @@ class PurchaseLimitController extends BaseController
return $this->success($res);
}
public function ssdbPurchaseRecord()
{
$res = $this->purchaseLimitService->ssdbPurchaseRecord($this->request->all(),214,156813021196050432);
return $this->success($res);
}
public function delSsdbPurchaseRecord()
{
$res = $this->purchaseLimitService->delSsdbPurchaseRecord($this->request->input('order_id'));
return $this->success($res);
}
public function test()
{
$res = $this->purchaseLimitService->test($this->request->all());

18
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;

2
app/Service/CouponServiceInterface.php

@ -27,7 +27,7 @@ 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);
public function orderRefundCoupon($global_order_id);
}

4
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,

17
app/Service/OrderService.php

@ -50,6 +50,12 @@ class OrderService implements OrderServiceInterface
*/
protected $userService;
/**
* @Inject
* @var PurchaseLimitServiceInterface
*/
protected $purchaseLimitService;
/**
* @inheritDoc
*/
@ -287,6 +293,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']]);
@ -721,12 +730,12 @@ 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);
//撤销特价商品购买记录
$res = $this->purchaseLimitService->delSsdbPurchaseRecord($order_id);
return $res;
}
/**

43
app/Service/PurchaseLimitService.php

@ -2,6 +2,8 @@
namespace App\Service;
use App\Model\Order;
use App\Model\OrderGoods;
use Hyperf\Di\Annotation\Inject;
use Hyperf\DbConnection\Db;
use App\Model\Goods;
@ -29,11 +31,46 @@ class PurchaseLimitService implements PurchaseLimitServiceInterface
return $res;
}
public function ssdbPurchaseRecord($params)
public function ssdbPurchaseRecord($data,$user_id,$global_order_id)
{
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 delSsdbPurchaseRecord($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);
$order = Order::query()
->where('order_main_id',$order_id)
->select('id','user_id')
->get()
->toArray();
foreach ($order as $k1 => $v1){
$goods = OrderGoods::query()
->where([
['order_id','=',$v1['id']],
['money','=',0.01],
])
->select('good_id')
->get()
->toArray();
foreach ($goods as $k2 => $v2) {
$ssdb->exec('del', SsdbKeysPrefix::PURCHASE_RECORD. date('Ymd') .'_'.$v1['user_id'].'_'.$v2['good_id'], $global_order_id);
var_dump($v1['user_id']);
var_dump($v1['good_id']);
}
}
return true;
}
public function test($params)

4
app/Service/PurchaseLimitServiceInterface.php

@ -8,7 +8,9 @@ interface PurchaseLimitServiceInterface
{
public function getStoreIdByMarketId($params);
public function ssdbPurchaseRecord($params);
public function ssdbPurchaseRecord($params,$user_id,$global_order_id);
public function delSsdbPurchaseRecord($order_id);
public function test($params);
}

2
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 = [

3
config/routes.php

@ -56,11 +56,12 @@ 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');
Router::post('PurchaseLimit/test', 'App\Controller\PurchaseLimitController@test');
Router::post('PurchaseLimit/delSsdbPurchaseRecord', 'App\Controller\PurchaseLimitController@delSsdbPurchaseRecord');
Router::post('PurchaseLimit/getStoreIdByMarketId', 'App\Controller\PurchaseLimitController@getStoreIdByMarketId');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);

Loading…
Cancel
Save