Browse Source

次卡购买

master
chenx 1 year ago
parent
commit
2e2f9b655d

+ 97
- 25
app/controller/api/project/Oncecard.php View File

@@ -9,6 +9,7 @@ use app\model\store\project\MemberOnceCardModel;
use app\model\store\project\OnceCardModel;
use app\model\user\User;
use app\Request;
use app\services\activity\coupon\StoreCouponUserServices;
use think\facade\Db;

class Oncecard extends AuthController
@@ -123,6 +124,102 @@ class Oncecard extends AuthController
return $this->success(['detail' => $detail]);
}

//计算价格
public function computed(Request $request)
{
$uid = $request->uid();
$member_once_card_id = $this->request->param('member_once_card_id/d');
$check = MemberOnceCardModel::where('member_once_card_id', $member_once_card_id)->where('member_id', $uid)->field('once_card_id')->find();
if (empty($check)) {
return $this->fail('记录不存在');
}
$once_card = OnceCardModel::find($check['once_card_id']);
if (empty($once_card)) return $this->fail('次卡不存在');
if ($once_card->is_delete != 0) return $this->fail('次卡不存在');
if ($once_card->status != 1) return $this->fail('次卡已下架');
//秒杀活动时间内判断数量
if ($flash_status = $this->checkFlashStatus($once_card)) {
if ($once_card->flash_num < 1) return $this->fail('秒杀数量不足够');
}

//判断总价
$total_price = $price = $flash_status ? $once_card->flash_price : $once_card->price;

$integral = 0;
$balance = 0;

//判断优惠卷
$coupon_id = $this->request->param('coupon_id/d', 0);
$couponBalance = 0;
if (!empty($coupon_id)) {
/** @var StoreCouponUserServices $couponServices */
$couponServices = app()->make(StoreCouponUserServices::class);
$couponInfo = $couponServices->getOne([['id', '=', $coupon_id], ['uid', '=', $uid], ['is_fail', '=', 0], ['status', '=', 0], ['start_time', '<=', $_SERVER['REQUEST_TIME']], ['end_time', '>=', $_SERVER['REQUEST_TIME']]], '*', ['issue']);
if (!$couponInfo) {
return $this->fail('优惠券不存在');
}
$type = $couponInfo['applicable_type'] ?? 0;
if ($couponInfo['use_min_price'] > $total_price || $type != 0) {//只能是通用券
return $this->fail('不满足优惠劵的使用条件!');
}
//满减券
if ($couponInfo['coupon_type'] == 1) {
$couponPrice = $couponInfo['coupon_price'];
} else {
if ($couponInfo['coupon_price'] <= 0) {//0折
$couponPrice = $total_price;
} else if ($couponInfo['coupon_price'] >= 100) {
$couponPrice = 0;
} else {
$truePrice = (float)bcmul((string)$total_price, bcdiv((string)$couponInfo['coupon_price'], '100', 2), 2);
$couponPrice = (float)bcsub((string)$total_price, (string)$truePrice, 2);
}
}
if ($couponPrice < $total_price) {
$need_pay = (float)bcsub((string)$total_price, (string)$couponPrice, 2);
} else {
$couponPrice = $total_price;
$need_pay = 0;
}
$couponBalance = $couponPrice;
} else {
//获取需要支付的金额
$need_pay = round((($total_price) * 100 - $couponBalance * 100 - $balance * 100) / 100, 2);
}
return ['need_pay' => $need_pay, 'couponBalance' => $couponBalance];
}

protected function checkFlashStatus($once_card)
{
return ($once_card->is_flash_sale == 1 && $once_card->is_flash_sale_expire == 0);
}

//下单
public function create()
{
$once_card_id = $this->request->param('once_card_id/d', 0);
$coupon_id = $this->request->param('coupon_id/d', 0);
$params = [
'member_id' => $this->request->uid(),
'coupon_id' => $coupon_id,
'once_card_id' => $once_card_id,
'ip' => $this->request->ip(),
'mark' => $this->request->param('mark', ''),
'payType' => $this->request->param('payType', ''),
'is_coin' => $this->request->param('is_coin/d', 0),
];
Db::startTrans();
try {
$order_logic = OrderLogic::init();
$order_id = $order_logic['once_card']->createOrder($params);
Db::commit();
return $this->success(['order_id' => $order_id]);
} catch (\Exception $e) {
Db::rollback();
return $this->fail($e->getMessage());
}
}

/******************************** 下面接口暂未对接 ***************************************/

public function getMemberOncecardDetail()
@@ -163,31 +260,6 @@ class Oncecard extends AuthController
]);
}

public function createOrder()
{
$once_card_id = $this->request->param('once_card_id/d', 0);
$total_price = $this->request->param('total_price/f', 0);
$use_integral = $this->request->param('use_integral/d', 0);
$coupon_id = $this->request->param('coupon_id/d', 0);
$params = [
'member_id' => $this->request->uid(),
'total_price' => $total_price,
'use_integral' => $use_integral,
'coupon_id' => $coupon_id,
'once_card_id' => $once_card_id,
];
Db::startTrans();
try {
$order_logic = OrderLogic::init();
$order_id = $order_logic['once_card']->createOrder($params);
Db::commit();
return $this->success(['order_id' => $order_id]);
} catch (\Exception $e) {
Db::rollback();
return $this->fail($e->getMessage());
}
}

public function cancelOrder()
{
$once_card_order_id = $this->request->param('once_card_order_id/d', 0);

+ 5
- 0
app/controller/api/v1/store/StoreCouponsController.php View File

@@ -83,4 +83,9 @@ class StoreCouponsController
{
return app('json')->successful($service->beUsableCouponList((int)$request->uid(), $cartId, !!$new));
}

public function getOnceCardCoupon(Request $request, StoreCouponIssueServices $service)
{
return app('json')->successful($service->beUsableCouponList2((int)$request->uid()));
}
}

+ 7
- 2
app/controller/api/v1/store/StoreProductController.php View File

@@ -2,6 +2,7 @@

namespace app\controller\api\v1\store;

use app\model\user\User;
use app\Request;
use app\services\other\QrcodeServices;
use app\services\product\category\StoreCategoryServices;
@@ -79,7 +80,9 @@ class StoreProductController
$res = json_decode($res, true);
$test = $res['agent_level'] ?? 0;
$where['test'] = $test;
$list = $this->services->getGoodsList($where, (int)$request->uid());
$User = new User();
$a = $User->where('spread_uid', $request->uid())->count();
$list = $this->services->getGoodsList($where, (int)$request->uid(), 0, $a);
return app('json')->successful(get_thumb_water($list, $type, $field));
}

@@ -194,7 +197,9 @@ class StoreProductController
$res = $request->user();
$res = json_decode($res, true);
$test = $res['agent_level'] ?? 0;
$data = $this->services->productDetail($request, (int)$id, (int)$type, (int)$promotions_type, $test);
$User = new User();
$a = $User->where('spread_uid', $request->uid())->count();
$data = $this->services->productDetail($request, (int)$id, (int)$type, (int)$promotions_type, $test, $a);
return app('json')->successful($data);
}


+ 18
- 0
app/controller/store/project/logic/order/OrderLogic.php View File

@@ -0,0 +1,18 @@
<?php

namespace app\controller\store\project\logic\order;

class OrderLogic
{

private static $app;

public static function init()
{
self::$app = [
'once_card' => new OrderOnceCardLogic(),
];
return self::$app;
}

}

+ 845
- 0
app/controller/store/project/logic/order/OrderOnceCardLogic.php View File

@@ -0,0 +1,845 @@
<?php

namespace app\controller\store\project\logic\order;

use app\model\coin\CoinLog;
use app\model\store\project\MemberOnceCardItemModel;
use app\model\store\project\MemberOnceCardModel;
use app\model\store\project\MemberProjectModel;
use app\model\store\project\OnceCardItemModel;
use app\model\store\project\OnceCardModel;
use app\model\store\project\order\OnceCardOrderItemModel;
use app\model\store\project\order\OnceCardOrderModel;
use app\model\store\project\ProjectModel;
use app\services\activity\coupon\StoreCouponUserServices;
use app\services\pay\OrderPayServices;
use app\services\pay\YuePayServices;
use app\services\pay\PayServices;
use app\services\store\logic\ApplyServiceLogic;
use think\facade\Cache;

class OrderOnceCardLogic
{

use OrderTrait;

protected $once_card;
protected $order;

// public function wxPay($params)
// {
// $this->checkOrderPayStatus($params);
// $this->completePayAct('weixin', $params['payinfo']);
// $MemberWalletLogic = new MemberWalletLogic($this->order->shop_id, $this->order->member_id);
// $MemberWalletLogic->addIntegralByPayment($this->order->need_pay); //更新支付返的积分
// //计算业绩
// $PartnerLogic = new PartnerLogic($this->order->shop_id);
// $PartnerLogic->commission($this->order->member_id, $this->order->need_pay);
// //写入GMV
// $shop_gmv_logs = new ShopGmvLogsModel();
// $shop_gmv_logs->shop_id = $this->order->shop_id;
// $shop_gmv_logs->balance = $this->order->need_pay;
// $shop_gmv_logs->save();
// }
//
// public function moneyPay($params)
// {
// //判断订单支付的状态与数据初始化
// $this->checkOrderPayStatus($params);
//
// //下面是独属于余额支付
// $MemberWalletLogic = new MemberWalletLogic($this->shopId, $this->member->uid);
// $res = $MemberWalletLogic->useBalance($this->order->need_pay, $this->order->total_price, 15); //商城购物使用
// if ($res == false) $this->error($MemberWalletLogic->getError());
//
// //完成支付后的操作
// $this->completePayAct('money');
// }

public function createOrder($params)
{
//判断用户
empty($params['member_id']) && $this->error('请先登录后再操作');
$this->checkMember($params['member_id'], false);

$once_card_id = (int)$params['once_card_id'];
if ($once_card_id == 0) $this->error('次卡不存在');
//判断次卡
$this->checkOnceCard($once_card_id, true);
if ($this->once_card->is_delete != 0) $this->error('次卡不存在');
if ($this->once_card->status != 1) $this->error('次卡已下架');

//秒杀活动时间内判断数量
if ($flash_status = $this->checkFlashStatus()) {
if ($this->once_card->flash_num < 1) $this->error('秒杀数量不足够');
}

//判断总价
$total_price = $price = $flash_status ? $this->once_card->flash_price : $this->once_card->price;

$integral = 0;
$balance = 0;

//判断优惠卷
$coupon_id = $params['coupon_id'];
$couponBalance = 0;
if (!empty($coupon_id)) {
/** @var StoreCouponUserServices $couponServices */
$couponServices = app()->make(StoreCouponUserServices::class);
$couponInfo = $couponServices->getOne([['id', '=', $coupon_id], ['uid', '=', $params['member_id']], ['is_fail', '=', 0], ['status', '=', 0], ['start_time', '<=', $_SERVER['REQUEST_TIME']], ['end_time', '>=', $_SERVER['REQUEST_TIME']]], '*', ['issue']);
if (!$couponInfo) {
$this->error('优惠券不存在');
}
$type = $couponInfo['applicable_type'] ?? 0;
if ($couponInfo['use_min_price'] > $total_price || $type != 0) {//只能是通用券
$this->error('不满足优惠劵的使用条件!');
}
//满减券
if ($couponInfo['coupon_type'] == 1) {
$couponPrice = $couponInfo['coupon_price'];
} else {
if ($couponInfo['coupon_price'] <= 0) {//0折
$couponPrice = $total_price;
} else if ($couponInfo['coupon_price'] >= 100) {
$couponPrice = 0;
} else {
$truePrice = (float)bcmul((string)$total_price, bcdiv((string)$couponInfo['coupon_price'], '100', 2), 2);
$couponPrice = (float)bcsub((string)$total_price, (string)$truePrice, 2);
}
}
if ($couponPrice < $total_price) {
$need_pay = (float)bcsub((string)$total_price, (string)$couponPrice, 2);
} else {
$couponPrice = $total_price;
$need_pay = 0;
}
$couponBalance = $couponPrice;
} else {
//获取需要支付的金额
$need_pay = round((($total_price) * 100 - $couponBalance * 100 - $balance * 100) / 100, 2);
}

if ($params['payType'] == 'weixin' && $params['is_coin'] == 1) {
//判断币
$Coin = new \app\model\coin\Coin();
$coin = $Coin->where('uid', $params['member_id'])->value('coin');
if (!empty($coin)) {
if ($this->once_card->coin > $coin) {
$this->error('币不足');
}
} else {
$this->error('币不足');
}
if ($need_pay - $this->once_card->coin < 0) {
$need_pay = 0;
} else {
$need_pay = $need_pay - $this->once_card->coin;
}
}

//处理次卡
$order_model = new OnceCardOrderModel();
$OnceCardOrder_data = [
'member_id' => $this->member->uid,
'once_card_id' => $this->once_card->once_card_id,
'name' => $this->once_card->name,
'valid_time' => $this->once_card->valid_time,
'valid_unit' => $this->once_card->valid_unit,
'is_flash_sale' => $flash_status ? 1 : 0,
'cover_img' => $this->once_card->cover_img,
'total_price' => $total_price,
'member_coupon_id' => $params['coupon_id'],
'coupon_money' => $couponBalance,
'use_integral' => $integral,
'integral_balance' => $balance,
'need_pay' => $need_pay,
'pay_type' => $params['payType'],
'add_time' => $_SERVER['REQUEST_TIME'],
'add_ip' => $params['ip'],
'order_id' => $this->getNewOrderId(),
'coin' => $this->once_card->coin,
'mark' => $params['mark'],
'unique' => md5($this->getNewOrderId() . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8)),
'verify_code' => $this->getStoreCode($order_model),
'channel_type' => 'routine'
];
if ($need_pay == '0' || $need_pay == '0.00') {
$OnceCardOrder_data['is_paid'] = 1;
$OnceCardOrder_data['pay_time'] = $_SERVER['REQUEST_TIME'];
$OnceCardOrder_data['pay_info'] = '抵扣币或优惠券后,金额为0';
$OnceCardOrder_data['pay_price'] = 0.00;
$OnceCardOrder_data['trade_no'] = '';
}

$order_model->save($OnceCardOrder_data);

//如果不是秒杀这时候要去添加销量
if ($flash_status) {
$this->once_card->flash_num = $this->once_card->flash_num - 1;
$this->once_card->fictitious_take_count = $this->once_card->fictitious_take_count + 1;
$this->once_card->take_count = $this->once_card->take_count + 1;
$this->once_card->save();
} else {
$this->once_card->fictitious_take_count = $this->once_card->fictitious_take_count + 1;
$this->once_card->take_count = $this->once_card->take_count + 1;
$this->once_card->save();
}

//处理次卡项目
$items = OnceCardItemModel::where([
['once_card_id', '=', $this->once_card->once_card_id],
['is_delete', '=', 0]
])->select()->toArray();
if (empty($items)) $this->error('次卡错误');

$item_data = [];
foreach ($items as $k => $item) {
if (null === $project = ProjectModel::find($item['project_id'])) $this->error('项目不存在');
$item_data[] = [
'member_id' => $this->member->uid,
'once_card_order_id' => $order_model->once_card_order_id,
'once_card_item_id' => $item['once_card_item_id'],
'project_id' => $item['project_id'],
'full_name' => $project->full_name,
'abbreviation' => $project->abbreviation,
'market_price' => $project->market_price,
'cover_img' => $project->cover_img,
'total_num' => $item['num'],
'add_ip' => $params['ip'],
'add_time' => $_SERVER['REQUEST_TIME'],
];
}

$order_item_model = new OnceCardOrderItemModel();
$order_item_model->saveAll($item_data);

if ($params['is_coin'] == 1) {
//扣除币
//增加币记录
$CoinLog = new CoinLog();
$CoinLog->operate($params['member_id'], $this->once_card->coin, 8, $order_model->once_card_order_id, 0);
}

//券记录
if (!empty($coupon_id)) {
$res1 = $couponServices->useCoupon($coupon_id);
if (!$res1) {
$this->error('使用优惠劵失败!');
}
}

if ($need_pay == '0' || $need_pay == '0.00') {
//支付金额为0,成功后,办理卡
$this->completePayAct($order_model->once_card_order_id, $params['ip']);
return $order_model->once_card_order_id;
}

$orderId = $order_model->once_card_order_id;
$order_model = new OnceCardOrderModel();
$order = $order_model->where('once_card_order_id', $orderId)->find();
$payType = $params['payType'];
$uid = $params['member_id'];
if ($orderId) {
$orderInfo = $order->toArray();
$info = compact('orderId');
switch ($payType) {
case PayServices::WEIXIN_PAY:
/** @var OrderPayServices $payServices */
$payServices = app()->make(OrderPayServices::class);
$from = 'weixin';
$info['jsConfig'] = $payServices->OnceCardOrderPay($orderInfo, $from);
return $info;
break;
case PayServices::YUE_PAY:
/** @var YuePayServices $yueServices */
$yueServices = app()->make(YuePayServices::class);
$pay = $yueServices->OnceCardYueOrderPay($orderInfo, $uid);
if ($pay['status'] === true) {
//支付成功后,办理卡
$this->completePayAct($order_model->once_card_order_id, $params['ip']);
return $order_model->once_card_order_id;
} else {
$this->error('余额支付失败');
}
break;
default:
$this->error('payType参数错误');
break;
}
} else {
$this->error('订单生成失败!');
}
}

/**
* 核销订单生成核销码
* @return false|string
*/
public function getStoreCode($order_model)
{
mt_srand();
list($msec, $sec) = explode(' ', microtime());
$num = $_SERVER['REQUEST_TIME'] + mt_rand(10, 999999) . '' . substr($msec, 2, 3);//生成随机数
if (strlen($num) < 12)
$num = str_pad((string)$num, 12, 0, STR_PAD_RIGHT);
else
$num = substr($num, 0, 12);
if ($order_model->where(['verify_code' => $num])->value('once_card_order_id')) {
return $this->getStoreCode($order_model);
}
return $num;
}

public function getNewOrderId(string $prefix = 'wx')
{
$snowflake = new \Godruoyi\Snowflake\Snowflake();
$is_callable = function ($currentTime) {
// if (is_win()) {
$redis = Cache::store('redis');
$swooleSequenceResolver = new \Godruoyi\Snowflake\RedisSequenceResolver($redis->handler());
return $swooleSequenceResolver->sequence($currentTime);
// } else {
// $swooleSequenceResolver = new \Godruoyi\Snowflake\SwooleSequenceResolver();
// return $swooleSequenceResolver->sequence($currentTime);
// }
};
//32位
if (PHP_INT_SIZE == 4) {
$id = abs($snowflake->setSequenceResolver($is_callable)->id());
} else {
$id = $snowflake->setStartTimeStamp(strtotime('2020-06-05') * 1000)->setSequenceResolver($is_callable)->id();
}
return $prefix . $id;
}

public function completePayAct($once_card_order_id, $ip, $notify = [])
{
if (!empty($notify)) {
//判断传来的订单
$this->checkOrder($once_card_order_id, true, $notify['out_trade_no']);
// $once_card_order_id = $this->order->once_card_order_id;
} else {
//判断传来的订单
$this->checkOrder($once_card_order_id, true);
}
if (!empty($notify)) {
//支付回调成功
$this->order->is_paid = 1;
$this->order->pay_time = $_SERVER['REQUEST_TIME'];
$this->order->trade_no = $notify['transaction_id'];
// $this->order->pay_price = $notify[''];//???
$this->order->pay_info = json_encode($notify);
$this->order->save();
}
//计算有有效时间
if ($this->order->valid_unit == 'day') $valid_unit = 86400;
if ($this->order->valid_unit == 'month') $valid_unit = 86400 * 30;
if ($this->order->valid_unit == 'year') $valid_unit = 86400 * 365;
$valid_end_time = date('Y-m-d', $_SERVER['REQUEST_TIME'] + ($valid_unit * $this->order->valid_time));

//处理我的次卡
$member_once_data_data = [
'member_id' => $this->member->uid,
'once_card_order_id' => $this->order->once_card_order_id,
'once_card_id' => $this->once_card->once_card_id,
'name' => $this->order->name,
'cover_img' => $this->order->cover_img,
'valid_end_time' => $valid_end_time,
'total_price' => $this->order->total_price,
'member_coupon_id' => $this->order->member_coupon_id,
'coupon_money' => $this->order->coupon_money,
'use_integral' => $this->order->use_integral,
'integral_balance' => $this->order->integral_balance,
'youhui_balance' => $this->order->youhui_balance,
'need_pay' => $this->order->need_pay,
'pay_type' => $this->order->pay_type,
'pay_time' => $this->order->pay_time,
'pay_info' => $this->order->pay_info,
'add_time' => $_SERVER['REQUEST_TIME'],
'add_ip' => $ip,
'is_paid' => 1,
];
$member_once_card_model = new MemberOnceCardModel();
$member_once_card_model->save($member_once_data_data);

//处理我的次卡项目
$items = OnceCardOrderItemModel::where([
['once_card_order_id', '=', $this->order->once_card_order_id],
])->select()->toArray();
if (empty($items)) $this->error('订单出错啦');

foreach ($items as $k => $item) {
//处理次卡项目
$item_data = [
'member_id' => $this->member->uid,
'member_once_card_id' => $member_once_card_model->member_once_card_id,
'project_id' => $item['project_id'],
'full_name' => $item['full_name'],
'abbreviation' => $item['abbreviation'],
'market_price' => $item['market_price'],
'cover_img' => $item['cover_img'],
'total_num' => $item['total_num'],
'remain_num' => $item['total_num'],
'add_time' => $_SERVER['REQUEST_TIME'],
'add_ip' => $ip,
];
$member_item_model = new MemberOnceCardItemModel();
$member_item_model->save($item_data);

//添加项目销量
if (null === $project = ProjectModel::find($item['project_id'])) $this->error('项目不存在');
$project->take_count = $project->take_count + $item['total_num'];
$project->save();

//处理我的项目
$member_project_data = [
'member_id' => $this->member->uid,
'source' => 'once_card',
'project_id' => $project->project_id,
'member_once_card_item_id' => $member_item_model->member_once_card_item_id,
'total_num' => $item['total_num'],
'remain_num' => $item['total_num'],
'valid_end_time' => $valid_end_time,
'add_time' => $_SERVER['REQUEST_TIME'],
'add_ip' => $ip,
];
$member_project_model = new MemberProjectModel();
$member_project_model->save($member_project_data);
}

//添加办卡记录
$res = ApplyServiceLogic::apply($this->member->uid, 'once_card', $this->order->name, $member_once_card_model->member_once_card_id, $this->order->need_pay, $this->order->total_price, 0, 0);
if (!$res) $this->error('支付失败');
}

public function cancelOrder($params)
{
//判断用户
empty($params['member_id']) && $this->error('请先登录后再操作');
$this->checkMember($params['member_id'], false);

//判断传来的订单
$once_card_order_id = (int)$params['once_card_order_id'];
$this->checkOrder($once_card_order_id, true);
if ($this->order->member_id != $this->member->uid) $this->error('订单不存在');
if ($this->order->is_paid != 0) $this->error('订单不存在');
if ($this->order->is_delete == 1) $this->error('订单不在未支付状态');

//判断次卡
$this->checkOnceCard($this->order->once_card_id, true);

//处理订单
$this->order->is_delete = 1;
$this->order->save();

//如果是秒杀取消就释放库存
if ($this->order->is_flash_sale == 1) {
$this->once_card->flash_num = $this->once_card->flash_num + 1;
$this->once_card->fictitious_take_count = $this->once_card->fictitious_take_count - 1 > 0 ? $this->once_card->fictitious_take_count - 1 : 0;
$this->once_card->take_count = $this->once_card->take_count - 1;
$this->once_card->save();
}
}

public function checkOnceCard($once_card_id, $lock)
{
if (null === $this->once_card = OnceCardModel::lock($lock)->find($once_card_id)) $this->error('次卡不存在');
}

public function checkOrder($once_card_order_id, $lock, $out_trade_no = '')
{
if (empty($out_trade_no)) {
if (null === $this->order = OnceCardOrderModel::lock($lock)->find($once_card_order_id)) $this->error('订单不存在');
} else {
if (null === $this->order = OnceCardOrderModel::where('order_id', $out_trade_no)::lock($lock)->find()) $this->error('订单不存在');
}
}

public function checkFlashStatus()
{
return ($this->once_card->is_flash_sale == 1 && $this->once_card->is_flash_sale_expire == 0);
}

// public function apply($params)
// {
// //判断其合法性
// $operate_type = (int)$params['operate_type'];
// $operate_id = (int)$params['operate_id'];
// if (!in_array($operate_type, [1, 2])) $this->error('参数错误');
//
// //判断用户
// $this->checkMember($params['member_id'], false);
//
// $once_card_id = (int)$params['once_card_id'];
// if ($once_card_id == 0) $this->error('次卡不存在');
// //判断抢购
// $this->checkOnceCard($once_card_id, true);
// if ($this->once_card->is_delete != 0) $this->error('次卡不存在');
// if ($this->once_card->status != 1) $this->error('次卡已下架');
//
// //秒杀活动时间内判断数量
// if ($flash_status = $this->checkFlashStatus()) {
// if ($this->once_card->flash_num < 1) $this->error('秒杀数量不足够');
// }
//
// //判断总价
// $total_price = $price = $flash_status ? $this->once_card->flash_price : $this->once_card->price;
// if (empty($params['total_price'])) $this->error('参数错误#1');
// if ((float)$params['total_price'] != $total_price) $this->error('参数错误#2');
//
// //得到实际支付的金额
// $need_pay = (float)$params['need_pay'];
//
// //获取优惠金额
// $youhui_balance = round((($total_price) * 100 - $need_pay * 100) / 100, 2);
// $youhui_balance = $youhui_balance > 0 ? $youhui_balance : 0;
//
//
// //计算有有效时间
// if ($this->once_card->valid_unit == 'day') $valid_unit = 86400;
// if ($this->once_card->valid_unit == 'month') $valid_unit = 86400 * 30;
// if ($this->once_card->valid_unit == 'year') $valid_unit = 86400 * 365;
// $valid_end_time = date('Y-m-d', time() + ($valid_unit * $this->once_card->valid_time));
//
// //处理次卡
// $member_once_card_model = new MemberOnceCardModel();
// $member_once_card_model->save([
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'once_card_id' => $this->once_card->once_card_id,
// 'name' => $this->once_card->name,
// 'cover_img' => $this->once_card->cover_img,
// 'valid_end_time' => $valid_end_time,
// 'total_price' => $total_price,
// 'need_pay' => $need_pay,
// 'youhui_balance' => $youhui_balance,
// 'pay_type' => 'offline',
// 'pay_time' => time(),
// ]);
//
// if ($flash_status) {
// $this->once_card->flash_num = $this->once_card->flash_num - 1;
// $this->once_card->fictitious_take_count = $this->once_card->fictitious_take_count + 1;
// $this->once_card->take_count = $this->once_card->take_count + 1;
// $this->once_card->save();
// }
//
// //处理次卡项目
// $items = OnceCardItemModel::where([
// ['shop_id', '=', $this->shopId],
// ['once_card_id', '=', $this->once_card->once_card_id],
// ['is_delete', '=', 0]
// ])->select()->toArray();
// if (empty($items)) $this->error('次卡错误');
//
//
// foreach ($items as $k => $item) {
// //添加项目销量
// if (null === $project = ProjectModel::find($item['project_id'])) $this->error('项目不存在');
// if ($project->shop_id != $this->shopId) $this->error('项目不存在');
// $project->take_count = $project->take_count + $item['num'];
// $project->save();
//
// $item_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'member_once_card_id' => $member_once_card_model->member_once_card_id,
// 'project_id' => $item['project_id'],
// 'full_name' => $project->full_name,
// 'abbreviation' => $project->abbreviation,
// 'market_price' => $project->market_price,
// 'cover_img' => $project->cover_img,
// 'total_num' => $item['num'],
// 'remain_num' => $item['num'],
// ];
// $member_item_model = new MemberOnceCardItemModel();
// $member_item_model->save($item_data);
//
// //处理我的项目
// $member_project_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'source' => 'once_card',
// 'project_id' => $project->project_id,
// 'member_once_card_item_id' => $member_item_model->member_once_card_item_id,
// 'total_num' => $item['num'],
// 'remain_num' => $item['num'],
// 'valid_end_time' => $valid_end_time,
// ];
// $member_project_model = new MemberProjectModel();
// $member_project_model->save($member_project_data);
// }
//
// //添加办卡记录
// $res = ApplyServiceLogic::apply($this->shopId, $this->member->uid, 'once_card', $this->once_card->name, $member_once_card_model->member_once_card_id, $need_pay, $total_price, $operate_type, $operate_id);
// if (!$res) $this->error('办理失败');
//
// }
//
// public function sendOnceCard($params)
// {
// //判断用户
// $this->checkMember($params['member_id'], false);
//
// $once_card_id = (int)$params['once_card_id'];
// if ($once_card_id == 0) $this->error('次卡不存在');
// //判断抢购
// $this->checkOnceCard($once_card_id, true);
// if ($this->once_card->is_delete != 0) $this->error('次卡不存在');
// if ($this->once_card->status != 1) $this->error('次卡已下架');
//
// //秒杀活动时间内判断数量
// $flash_status = $this->checkFlashStatus();
//
// //判断总价
// $total_price = $price = $flash_status ? $this->once_card->flash_price : $this->once_card->price;
//
// //得到实际支付的金额
// $need_pay = 0;
//
// //获取优惠金额
// $youhui_balance = round((($total_price) * 100 - $need_pay * 100) / 100, 2);
// $youhui_balance = $youhui_balance > 0 ? $youhui_balance : 0;
//
//
// //计算有有效时间
// if ($this->once_card->valid_unit == 'day') $valid_unit = 86400;
// if ($this->once_card->valid_unit == 'month') $valid_unit = 86400 * 30;
// if ($this->once_card->valid_unit == 'year') $valid_unit = 86400 * 365;
// $valid_end_time = date('Y-m-d', time() + ($valid_unit * $this->once_card->valid_time));
//
// //处理次卡
// $member_once_card_model = new MemberOnceCardModel();
// $member_once_card_model->save([
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'once_card_id' => $this->once_card->once_card_id,
// 'name' => $this->once_card->name,
// 'cover_img' => $this->once_card->cover_img,
// 'valid_end_time' => $valid_end_time,
// 'total_price' => $total_price,
// 'need_pay' => $need_pay,
// 'youhui_balance' => $youhui_balance,
// 'pay_type' => 'offline',
// 'pay_time' => time(),
// ]);
//
// //处理次卡项目
// $items = OnceCardItemModel::where([
// ['shop_id', '=', $this->shopId],
// ['once_card_id', '=', $this->once_card->once_card_id],
// ['is_delete', '=', 0]
// ])->select()->toArray();
// if (empty($items)) $this->error('次卡错误');
//
//
// foreach ($items as $k => $item) {
// //添加项目销量
// if (null === $project = ProjectModel::find($item['project_id'])) $this->error('项目不存在');
// if ($project->shop_id != $this->shopId) $this->error('项目不存在');
//
// $item_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'member_once_card_id' => $member_once_card_model->member_once_card_id,
// 'project_id' => $item['project_id'],
// 'full_name' => $project->full_name,
// 'abbreviation' => $project->abbreviation,
// 'market_price' => $project->market_price,
// 'cover_img' => $project->cover_img,
// 'total_num' => $item['num'],
// 'remain_num' => $item['num'],
// ];
// $member_item_model = new MemberOnceCardItemModel();
// $member_item_model->save($item_data);
//
// //处理我的项目
// $member_project_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'source' => 'once_card',
// 'project_id' => $project->project_id,
// 'member_once_card_item_id' => $member_item_model->member_once_card_item_id,
// 'total_num' => $item['num'],
// 'remain_num' => $item['num'],
// 'valid_end_time' => $valid_end_time,
// ];
// $member_project_model = new MemberProjectModel();
// $member_project_model->save($member_project_data);
// }
//
// //添加办卡记录
// $res = ApplyServiceLogic::apply($this->shopId, $this->member->uid, 'once_card', $this->once_card->name, $member_once_card_model->member_once_card_id, $need_pay, $total_price, 0, 0);
// if (!$res) $this->error('办理失败');
// }
//
// protected function completePayAct($type, $payinfo = [])
// {
// $this->order->is_paid = 1;
// $this->order->is_delete = 1;
// $this->order->pay_time = time();
// $this->order->pay_type = $type;
// $this->order->pay_info = $payinfo;
// $this->order->save();
//
// //如果不是秒杀这时候要去添加销量
// if ($this->order->is_flash_sale == 0) {
// $this->once_card->fictitious_take_count = $this->once_card->fictitious_take_count + 1;
// $this->once_card->take_count = $this->once_card->take_count + 1;
// $this->once_card->save();
// }
//
// //计算有有效时间
// if ($this->order->valid_unit == 'day') $valid_unit = 86400;
// if ($this->order->valid_unit == 'month') $valid_unit = 86400 * 30;
// if ($this->order->valid_unit == 'year') $valid_unit = 86400 * 365;
// $valid_end_time = date('Y-m-d', time() + ($valid_unit * $this->order->valid_time));
//
//
// //处理我的次卡
// $member_once_data_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'once_card_order_id' => $this->order->once_card_order_id,
// 'once_card_id' => $this->once_card->once_card_id,
// 'name' => $this->order->name,
// 'cover_img' => $this->order->cover_img,
// 'valid_end_time' => $valid_end_time,
// 'market_price' => $this->order->market_price,
// 'total_price' => $this->order->total_price,
// 'member_coupon_id' => $this->order->member_coupon_id,
// 'coupon_money' => $this->order->coupon_money,
// 'use_integral' => $this->order->use_integral,
// 'integral_balance' => $this->order->integral_balance,
// 'youhui_balance' => $this->order->youhui_balance,
// 'need_pay' => $this->order->need_pay,
// 'pay_type' => $this->order->pay_type,
// 'pay_time' => $this->order->pay_time,
// 'pay_info' => $this->order->pay_info,
// ];
// $member_once_card_model = new MemberOnceCardModel();
// $member_once_card_model->save($member_once_data_data);
//
// //处理我的次卡项目
// $items = OnceCardOrderItemModel::where([
// ['shop_id', '=', $this->shopId],
// ['once_card_order_id', '=', $this->order->once_card_order_id],
// ])->select()->toArray();
// if (empty($items)) $this->error('订单出错啦');
//
// foreach ($items as $k => $item) {
// //处理次卡项目
// $item_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'member_once_card_id' => $member_once_card_model->member_once_card_id,
// 'project_id' => $item['project_id'],
// 'full_name' => $item['full_name'],
// 'abbreviation' => $item['abbreviation'],
// 'market_price' => $item['market_price'],
// 'cover_img' => $item['cover_img'],
// 'total_num' => $item['total_num'],
// 'remain_num' => $item['total_num'],
// ];
// $member_item_model = new MemberOnceCardItemModel();
// $member_item_model->save($item_data);
//
//
// //添加项目销量
// if (null === $project = ProjectModel::find($item['project_id'])) $this->error('项目不存在');
// if ($project->shop_id != $this->shopId) $this->error('项目不存在');
// $project->take_count = $project->take_count + $item['total_num'];
// $project->save();
//
// //处理我的项目
// $member_project_data = [
// 'shop_id' => $this->shopId,
// 'member_id' => $this->member->uid,
// 'source' => 'once_card',
// 'project_id' => $project->project_id,
// 'member_once_card_item_id' => $member_item_model->member_once_card_item_id,
// 'total_num' => $item['total_num'],
// 'remain_num' => $item['total_num'],
// 'valid_end_time' => $valid_end_time,
// ];
// $member_project_model = new MemberProjectModel();
// $member_project_model->save($member_project_data);
// }
//
// //添加办卡记录
// $res = ApplyServiceLogic::apply($this->shopId, $this->member->uid, 'once_card', $this->order->name, $member_once_card_model->member_once_card_id, $this->order->need_pay, $this->order->total_price, 0, 0);
// if (!$res) $this->error('支付失败');
//
//
// }
//
// protected function checkOrderPayStatus($params)
// {
// //判断用户
// empty($params['member_id']) && $this->error('请先登录后再操作');
// $this->checkMember($params['member_id'], false);
//
// //判断传来的订单
// $once_card_order_id = (int)$params['once_card_order_id'];
// $this->checkOrder($once_card_order_id, true);
// if ($this->order->member_id != $this->member->uid) $this->error('订单不存在');
// if ($this->order->is_paid != 0) $this->error('订单不存在');
// if ($this->order->is_delete == 1) $this->error('订单不在未支付状态');
// if ($this->order->add_time < (time() - 900)) $this->error('订单支付已经超时了,不能继续支付');
//
// //判断抢购
// $this->checkOnceCard($this->order->once_card_id, true);
//
//
// //处理数据
// if (!empty($this->order->member_coupon_id)) {
// if (null === $myCoupon = MemberCouponModel::find($this->order->member_coupon_id)) $this->error('优惠券不存在');
// if ($myCoupon->status == 1) $this->error('优惠券不存在');
//
// $myCoupon->status = 1;
// $myCoupon->save();
// LogsLogic::coupon($this->shopId, $this->member->uid, -1, 15, $this->order->member_coupon_id, '', 0);
// }
// $MemberWalletLogic = new MemberWalletLogic($this->shopId, $this->member->uid);
// if (!empty($order->use_integral)) { //使用积分
// $res = $MemberWalletLogic->useIntegral($order->use_integral, 12);
// if ($res == false) $this->error($MemberWalletLogic->getError());
// }
// $needPay = round(($this->order->total_price * 100 - $this->order->coupon_money * 100 - $this->order->integral_balance * 100) / 100, 2);
// if ($needPay <= 0 or $needPay != $this->order->need_pay) $this->error('支付金额不正确');
// }
//
// public function getIntegralBalance($total_price)
// {
// $SettingBalance = SettingBalanceModel::where([['shop_id', '=', $this->shopId]])->find();
// if (null === $SettingBalance) {
// $integral_deduction_balance_limit_rate = 0;
// } else {
// $integral_deduction_balance_limit_rate = $SettingBalance->integral_deduction_balance_limit_rate; //积分抵扣的比率 百分比
// }
// $integralSetting = SettingIntegralModel::where([['shop_id', '=', $this->shopId]])->find();
// if ($integralSetting === null) { //如果是空 代表不使用积分抵扣余额
// $integral_exchange_balance = 0;
// } else {
// $integral_exchange_balance = $integralSetting->integral_exchange_balance;//汇率
// }
//
// $pre_can_exchange_balance = round(($total_price * ($integral_deduction_balance_limit_rate * 100)) / 10000, 2);
// $pre_can_exchange_integral = $integral_exchange_balance == 0 ? 0 : round(($pre_can_exchange_balance * 10000) / ($integral_exchange_balance * 100), 0);
// $member_integral = $this->member->integral;
// if ($member_integral >= $pre_can_exchange_integral) {
// $return = [
// 'integral' => $pre_can_exchange_integral,
// 'balance' => $pre_can_exchange_balance
// ];
// } else {
// $return = [
// 'integral' => $member_integral,
// 'balance' => round(($member_integral * ($integral_exchange_balance * 100)) / 10000, 2),
// ];
// }
// return $return;
//
// }

}

+ 52
- 0
app/controller/store/project/logic/order/OrderTrait.php View File

@@ -0,0 +1,52 @@
<?php

namespace app\controller\store\project\logic\order;

use app\model\user\User;

trait OrderTrait
{

protected $member;

protected $shopId;
protected $today;
protected $orderId;
protected $order;

public function __construct()
{
$this->today = date('Y-m-d', time());
}

public function checkMember($memberId, $lock = true)
{
empty($memberId) && $this->error('用户未登录');
if (null === $this->member = User::where('uid', $memberId)->lock($lock)->find()) {
$this->error('用户未登录');
}
// $integral = MemberIntegralModel::where([
// ['shop_id', '=', $this->shopId],
// ['member_id', '=', $memberId],
// ['expire_time', '>', time()]
// ])->sum('remain_integral') ?? 0;
// $this->member->integral = $integral;
}

// public function checkOrder($orderId, $lock = true)
// {
// empty($orderId) && $this->error('请选择要支付的订单');
// if (null === $this->order = GoodsOrderModel::where('order_id', $orderId)->lock($lock)->find()) {
// $this->error('订单不存在');
// }
// if ($this->member->shop_id != $this->shopId) {
// $this->error('订单不存在');
// }
// }

public function error($message)
{
throw new \Exception($message);
}

}

+ 17
- 0
app/listener/pay/PayNotifyListener.php View File

@@ -4,9 +4,12 @@
namespace app\listener\pay;


use app\controller\store\project\logic\order\OrderLogic;
use app\services\pay\PayNotifyServices;
use app\services\wechat\WechatMessageServices;
use crmeb\services\CacheService;
use crmeb\utils\Hook;
use think\facade\Db;

/**
* 支付回调
@@ -25,6 +28,20 @@ class PayNotifyListener
[$notify] = $event;

if (isset($notify['attach']) && $notify['attach']) {
//判断是不是次卡订单
if ($notify['attach'] == 'once_card') {
Db::startTrans();
try {
$order_logic = OrderLogic::init();
$order_logic['once_card']->completePayAct('', '', $notify);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
//保存失败信息,且保存数据
CacheService::set('once_card_pay_notify_fail:' . $notify['out_trade_no'] . '_' . time(), json_encode($notify));
}
}
if (($count = strpos($notify['out_trade_no'], '_')) !== false) {
$notify['out_trade_no'] = substr($notify['out_trade_no'], $count + 1);
}

+ 13
- 0
app/model/store/project/order/OnceCardOrderItemModel.php View File

@@ -0,0 +1,13 @@
<?php

namespace app\model\store\project\order;

use crmeb\basic\BaseModel;

class OnceCardOrderItemModel extends BaseModel
{

protected $name = 'store_member_once_card_order_item';
protected $pk = 'once_card_order_item_id';

}

+ 19
- 0
app/model/store/project/order/OnceCardOrderModel.php View File

@@ -0,0 +1,19 @@
<?php

namespace app\model\store\project\order;

use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

class OnceCardOrderModel extends BaseModel
{

use ModelTrait;

protected $name = 'store_member_once_card_order';
protected $pk = 'once_card_order_id';
protected $type = [
'pay_info' => 'array',
];

}

+ 7
- 0
app/services/activity/coupon/StoreCouponIssueServices.php View File

@@ -581,6 +581,13 @@ class StoreCouponIssueServices extends BaseServices
return $coupServices->getUsableCouponList($uid, $cartGroup);
}

public function beUsableCouponList2(int $uid)
{
/** @var StoreCouponUserServices $coupServices */
$coupServices = app()->make(StoreCouponUserServices::class);
return $coupServices->getUsableCouponList2($uid);
}

/**获取单个优惠券类型
* @param array $where
* @return mixed

+ 91
- 7
app/services/activity/coupon/StoreCouponUserServices.php View File

@@ -143,14 +143,14 @@ class StoreCouponUserServices extends BaseServices
$cartInfo = $cartGroup['valid'];
$promotions = $cartGroup['promotions'] ?? [];
$promotionsList = [];
if($promotions){
if ($promotions) {
$promotionsList = array_combine(array_column($promotions, 'id'), $promotions);
}
$isOverlay = function($cart) use ($promotionsList) {
$isOverlay = function ($cart) use ($promotionsList) {
if (isset($cart['promotions_id']) && $cart['promotions_id']) {
foreach ($cart['promotions_id'] as $key => $promotions_id) {
$promotions = $promotionsList[$promotions_id] ?? [];
if ($promotions && $promotions['promotions_type'] != 4){
if ($promotions && $promotions['promotions_type'] != 4) {
$overlay = is_string($promotions['overlay']) ? explode(',', $promotions['overlay']) : $promotions['overlay'];
if (!in_array(5, $overlay)) {
return false;
@@ -167,7 +167,7 @@ class StoreCouponUserServices extends BaseServices
case 0:
case 3:
foreach ($cartInfo as $cart) {
if (!$isOverlay($cart)) continue;
if (!$isOverlay($cart)) continue;
$price = bcadd((string)$price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
$count++;
}
@@ -179,7 +179,7 @@ class StoreCouponUserServices extends BaseServices
if ($cateGorys) {
$cateIds = array_column($cateGorys, 'id');
foreach ($cartInfo as $cart) {
if (!$isOverlay($cart)) continue;
if (!$isOverlay($cart)) continue;
if (isset($cart['productInfo']['cate_id']) && array_intersect(explode(',', $cart['productInfo']['cate_id']), $cateIds)) {
$price = bcadd((string)$price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
$count++;
@@ -189,7 +189,7 @@ class StoreCouponUserServices extends BaseServices
break;
case 2:
foreach ($cartInfo as $cart) {
if (!$isOverlay($cart)) continue;
if (!$isOverlay($cart)) continue;
if (isset($cart['product_id']) && in_array($cart['product_id'], explode(',', $coupon['product_id']))) {
$price = bcadd((string)$price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
$count++;
@@ -213,6 +213,90 @@ class StoreCouponUserServices extends BaseServices
}

/**
* 下次卡单页面显示可用优惠券
* @param $uid
* @param $cartGroup
* @param $price
* @return array
*/
public function getUsableCouponList2(int $uid)
{
$userCoupons = $this->dao->getUserAllCoupon($uid);
$result = [];
if ($userCoupons) {
// $cartInfo = $cartGroup['valid'];
// $promotions = $cartGroup['promotions'] ?? [];
// $promotionsList = [];
// if($promotions){
// $promotionsList = array_combine(array_column($promotions, 'id'), $promotions);
// }
// $isOverlay = function($cart) use ($promotionsList) {
// if (isset($cart['promotions_id']) && $cart['promotions_id']) {
// foreach ($cart['promotions_id'] as $key => $promotions_id) {
// $promotions = $promotionsList[$promotions_id] ?? [];
// if ($promotions && $promotions['promotions_type'] != 4){
// $overlay = is_string($promotions['overlay']) ? explode(',', $promotions['overlay']) : $promotions['overlay'];
// if (!in_array(5, $overlay)) {
// return false;
// }
// }
// }
// }
// return true;
// };
foreach ($userCoupons as $coupon) {
$price = 0;
$count = 0;
// switch ($coupon['applicable_type']) {
// case 0:
// case 3:
// foreach ($cartInfo as $cart) {
// if (!$isOverlay($cart)) continue;
// $price = bcadd((string)$price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
// $count++;
// }
// break;
// case 1://品类券
// /** @var StoreCategoryServices $storeCategoryServices */
// $storeCategoryServices = app()->make(StoreCategoryServices::class);
// $cateGorys = $storeCategoryServices->getAllById((int)$coupon['category_id']);
// if ($cateGorys) {
// $cateIds = array_column($cateGorys, 'id');
// foreach ($cartInfo as $cart) {
// if (!$isOverlay($cart)) continue;
// if (isset($cart['productInfo']['cate_id']) && array_intersect(explode(',', $cart['productInfo']['cate_id']), $cateIds)) {
// $price = bcadd((string)$price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
// $count++;
// }
// }
// }
// break;
// case 2:
// foreach ($cartInfo as $cart) {
// if (!$isOverlay($cart)) continue;
// if (isset($cart['product_id']) && in_array($cart['product_id'], explode(',', $coupon['product_id']))) {
// $price = bcadd((string)$price, (string)bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
// $count++;
// }
// }
// break;
// }
if ($coupon['use_min_price'] <= $price) {
$coupon['start_time'] = $coupon['start_time'] ? date('Y/m/d', $coupon['start_time']) : date('Y/m/d', $coupon['add_time']);
$coupon['add_time'] = date('Y/m/d', $coupon['add_time']);
$coupon['end_time'] = date('Y/m/d', $coupon['end_time']);
$coupon['title'] = $coupon['coupon_title'];
$coupon['type'] = $coupon['applicable_type'];
$coupon['use_min_price'] = floatval($coupon['use_min_price']);
$coupon['coupon_price'] = floatval($coupon['coupon_price']);
$result[] = $coupon;
}
}
}
return $result;
}

/**
* 下单页面显示可用优惠券
* @param $uid
* @param $cartGroup
@@ -396,7 +480,7 @@ class StoreCouponUserServices extends BaseServices
} else {
$coupon['_type'] = 1;
$coupon['_msg'] = '立即使用';
$coupon['pc_type'] = 1;
$coupon['pc_type'] = 1;
$coupon['pc_msg'] = '可使用';
}
}

+ 6
- 4
app/services/order/StoreOrderSuccessServices.php View File

@@ -76,10 +76,12 @@ class StoreOrderSuccessServices extends BaseServices
// $user->where('uid',$orderInfo['uid'])->update(['agent_level'=>$agent_level]);
//

//扣除币
//增加币记录
$CoinLog = new CoinLog();
$CoinLog->operate($orderInfo['uid'], $orderInfo['coin'], 2, $orderInfo['id'], $orderInfo['cart_id']);
if (isset($orderInfo['cart_id'])) {
//扣除币
//增加币记录
$CoinLog = new CoinLog();
$CoinLog->operate($orderInfo['uid'], $orderInfo['coin'], 2, $orderInfo['id'], $orderInfo['cart_id']);
}

if (isset($orderInfo['cart_id']) && $orderInfo['cart_id']) {
$cartIds = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];

+ 6
- 6
app/services/product/product/StoreProductServices.php View File

@@ -1169,7 +1169,7 @@ class StoreProductServices extends BaseServices
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGoodsList(array $where, int $uid, int $promotions_type = 0)
public function getGoodsList(array $where, int $uid, int $promotions_type = 0, $a = 0)
{
$where['is_show'] = 1;
$where['is_del'] = 0;
@@ -1241,7 +1241,7 @@ class StoreProductServices extends BaseServices
}

//判断商品购买条件
if (($where['test'] + 1) == $item['userlevel']) {
if (($where['test'] + 1) == $item['userlevel'] && $a >= 3) {
$item['type'] = true;
} else {
$item['type'] = false;
@@ -1249,7 +1249,7 @@ class StoreProductServices extends BaseServices
$item['is_jingpin'] = 0;
if (isset($item['cateName'])) {
foreach ($item['cateName'] as $kk => $vv) {
if ($vv['cate_name'] == '精品区' || $vv['cate_name'] == '精品') {
if ($vv['cate_name'] == '会员一区' || $vv['cate_name'] == '会员二区' || $vv['cate_name'] == '会员三区' || $vv['cate_name'] == '会员四区' || $vv['cate_name'] == '会员五区' || $vv['cate_name'] == '会员六区' || $vv['cate_name'] == '会员七区' || $vv['cate_name'] == '会员八区' || $vv['cate_name'] == '会员九区') {
$item['is_jingpin'] = 1;
break;
}
@@ -1536,7 +1536,7 @@ class StoreProductServices extends BaseServices
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function productDetail(Request $request, int $id, int $type, int $promotions_type = 0, $test = 0)
public function productDetail(Request $request, int $id, int $type, int $promotions_type = 0, $test = 0, $a = 0)
{
$uid = (int)$request->uid();
$data['uid'] = $uid;
@@ -1682,14 +1682,14 @@ class StoreProductServices extends BaseServices
ProductLogJob::dispatch(['visit', ['uid' => $uid, 'id' => $id, 'product_id' => $id], 'product']);
$data['storeInfo']['price'] = two_num($data['storeInfo']['price'] + $data['storeInfo']['coin']);
//判断商品购买条件
if (($test + 1) == $data['storeInfo']['userlevel']) {
if (($test + 1) == $data['storeInfo']['userlevel'] && $a >= 3) {
$data['storeInfo']['type'] = true;
} else {
$data['storeInfo']['type'] = false;
}
$data['storeInfo']['is_jingpin'] = 0;
foreach ($data['storeInfo']['cateName'] as $kk => $vv) {
if ($vv['cate_name'] == '精品区' || $vv['cate_name'] == '精品') {
if ($vv['cate_name'] == '会员一区' || $vv['cate_name'] == '会员二区' || $vv['cate_name'] == '会员三区' || $vv['cate_name'] == '会员四区' || $vv['cate_name'] == '会员五区' || $vv['cate_name'] == '会员六区' || $vv['cate_name'] == '会员七区' || $vv['cate_name'] == '会员八区' || $vv['cate_name'] == '会员九区') {
$data['storeInfo']['is_jingpin'] = 1;
break;
}

+ 5
- 0
route/api.php View File

@@ -185,6 +185,7 @@ Route::group('api', function () {
Route::post('coupon/receive/batch', 'v1.store.StoreCouponsController/receive_batch')->name('couponReceiveBatch'); //批量领取优惠券
Route::get('coupons/user/:types', 'v1.store.StoreCouponsController/user')->name('couponsUser');//用户已领取优惠券
Route::get('coupons/order/:price', 'v1.store.StoreCouponsController/order')->name('couponsOrder');//优惠券 订单列表
Route::get('coupons/order2', 'v1.store.StoreCouponsController/getOnceCardCoupon');//优惠券 次卡订单列表
//购物车类
Route::get('cart/list', 'v1.store.StoreCartController/lst')->name('cartList'); //购物车列表
Route::post('cart/add', 'v1.store.StoreCartController/add')->name('cartAdd'); //购物车添加
@@ -638,6 +639,10 @@ Route::group('api', function () {
Route::post('wechat/create', 'coin.CoinController/create');
Route::post('wechat/recive', 'coin.CoinController/recive');
Route::post('wechat/cancel', 'coin.CoinController/cancel');

//次卡购买
Route::post('oncecard/computed', 'project.Oncecard/computed');
Route::post('oncecard/create', 'project.Oncecard/create');
})->middleware(StationOpenMiddleware::class)->middleware(AuthTokenMiddleware::class, true);



Loading…
Cancel
Save