@@ -191,7 +191,10 @@ class StoreProductController | |||
[$promotions_type] = $request->getMore([ | |||
[['promotions_type', 'd'], 0] | |||
], true); | |||
$data = $this->services->productDetail($request, (int)$id, (int)$type, (int)$promotions_type); | |||
$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); | |||
return app('json')->successful($data); | |||
} | |||
@@ -375,7 +375,7 @@ class Oncecard extends AuthController | |||
$once_card_id = (int)$params['once_card_id']; | |||
if ($once_card_id == 0) return ($this->fail('次卡不存在')); | |||
//判断抢购 | |||
//判断次卡 | |||
if (null === $once_card = OnceCardModel::lock(true)->find($once_card_id)) return ($this->fail('次卡不存在')); | |||
if ($once_card->is_delete != 0) return ($this->fail('次卡不存在')); |
@@ -178,7 +178,7 @@ class StoreProductDao extends BaseDao | |||
* @throws \think\db\exception\DbException | |||
* @throws \think\db\exception\ModelNotFoundException | |||
*/ | |||
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'], string $order = '', array $with = ['couponId', 'description']) | |||
public function getSearchList(array $where, int $page = 0, int $limit = 0, array $field = ['*'], string $order = '', array $with = ['couponId', 'description', 'cateName']) | |||
{ | |||
if (isset($where['star'])) $with[] = 'star'; | |||
return $this->search($where)->with($with)->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) { |
@@ -36,14 +36,14 @@ class ProductRelated extends BaseModel | |||
return $this->hasOne(StoreProduct::class, 'id', 'product_id')->bind(['image' => 'image', 'store_name' => 'store_name']); | |||
} | |||
public function giveMoney($product_id) | |||
public function giveMoney($product_id, $uid) | |||
{ | |||
try { | |||
$product = new StoreProduct(); | |||
$ProductRelated = new ProductRelated(); | |||
$benefit_money = $product->where('id', $product_id)->value('benefit_money'); | |||
if (!empty($benefit_money)) { | |||
$result = $ProductRelated->where('product_id', $product_id)->where('is_delete', 0)->field('uid')->with(['getUserOneData'])->select()->toArray(); | |||
$result = $ProductRelated->where('product_id', $product_id)->where('is_delete', 0)->where("uid != " . $uid)->field('uid')->with(['getUserOneData'])->select()->toArray(); | |||
if ($result) { | |||
$time = $_SERVER['REQUEST_TIME']; | |||
$User = new User(); |
@@ -88,7 +88,7 @@ class StoreOrderSuccessServices extends BaseServices | |||
foreach ($cartIds as $k => $v) { | |||
$product_id = $order_cart_info->where('cart_id', $v)->value('product_id'); | |||
if ($product_id) { | |||
$ProductRelated->giveMoney($product_id); | |||
$ProductRelated->giveMoney($product_id, $orderInfo['uid']); | |||
} | |||
} | |||
} |
@@ -72,6 +72,33 @@ class OrderPayServices | |||
} | |||
/** | |||
* 次卡订单发起支付 | |||
* @param array $orderInfo | |||
* @return array|string | |||
*/ | |||
public function OnceCardOrderPay(array $orderInfo, string $payType) | |||
{ | |||
$openid = ''; | |||
if (!in_array($payType, ['weixinh5', 'pc', 'store']) && !request()->isApp()) { | |||
if ($payType === 'weixin') { | |||
$userType = 'wechat'; | |||
} else { | |||
$userType = $payType; | |||
} | |||
/** @var WechatUserServices $services */ | |||
$services = app()->make(WechatUserServices::class); | |||
$openid = $services->uidToOpenid($orderInfo['member_id'], 'routine'); | |||
if (!$openid) { | |||
throw new ValidateException('获取用户openid失败,无法支付'); | |||
} | |||
} | |||
$body = $orderInfo['name']; | |||
$successAction = 'once_card'; | |||
return $this->payServices->pay($payType, $openid, $orderInfo['order_id'], $orderInfo['need_pay'], $successAction, $body); | |||
} | |||
/** | |||
* 支付宝支付 | |||
* @param array $orderInfo | |||
* @param string $quitUrl |
@@ -20,6 +20,36 @@ class YuePayServices extends BaseServices | |||
{ | |||
/** | |||
* 次卡订单余额支付 | |||
* @param array $orderInfo | |||
* @param $uid | |||
* @return bool[]|string[] | |||
*/ | |||
public function OnceCardYueOrderPay(array $orderInfo, $uid) | |||
{ | |||
/** @var UserServices $services */ | |||
$services = app()->make(UserServices::class); | |||
$userInfo = $services->getUserInfo($uid); | |||
if ($userInfo['now_money'] < $orderInfo['need_pay']) { | |||
throw new ValidateException('余额不足'); | |||
} | |||
$this->transaction(function () use ($services, $orderInfo, $userInfo) { | |||
$res = false !== $services->bcDec($userInfo['uid'], 'now_money', $orderInfo['need_pay'], 'uid'); | |||
//写入余额记录 | |||
$now_money = bcsub((string)$userInfo['now_money'], (string)$orderInfo['need_pay'], 2); | |||
$number = $orderInfo['need_pay']; | |||
/** @var UserMoneyServices $userMoneyServices */ | |||
$userMoneyServices = app()->make(UserMoneyServices::class); | |||
$res = $res && $userMoneyServices->income('pay_once_card', $userInfo['uid'], $number, $now_money, $orderInfo['once_card_order_id']); | |||
if (!$res) { | |||
throw new ValidateException('余额支付失败!'); | |||
} | |||
}); | |||
return ['status' => true]; | |||
} | |||
/** | |||
* 订单余额支付 | |||
* @param array $orderInfo | |||
* @param $uid |
@@ -1239,6 +1239,22 @@ class StoreProductServices extends BaseServices | |||
} else { | |||
$item['star'] = '3.0'; | |||
} | |||
//判断商品购买条件 | |||
if (($where['test'] + 1) == $item['userlevel']) { | |||
$item['type'] = true; | |||
} else { | |||
$item['type'] = false; | |||
} | |||
$item['is_jingpin'] = 0; | |||
if (isset($item['cateName'])) { | |||
foreach ($item['cateName'] as $kk => $vv) { | |||
if ($vv['cate_name'] == '精品区' || $vv['cate_name'] == '精品') { | |||
$item['is_jingpin'] = 1; | |||
break; | |||
} | |||
} | |||
} | |||
} | |||
$list = $this->getActivityList($list); | |||
$list = $this->getProduceOtherList($list, $uid, isset($where['type']) && !!$where['type']); | |||
@@ -1520,11 +1536,11 @@ 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) | |||
public function productDetail(Request $request, int $id, int $type, int $promotions_type = 0, $test = 0) | |||
{ | |||
$uid = (int)$request->uid(); | |||
$data['uid'] = $uid; | |||
$storeInfo = $this->dao->getOne(['id' => $id, 'is_show' => 1, 'is_del' => 0], '*', ['description', 'brand']); | |||
$storeInfo = $this->dao->getOne(['id' => $id, 'is_show' => 1, 'is_del' => 0], '*', ['description', 'brand', 'cateName']); | |||
if (!$storeInfo) { | |||
throw new ValidateException('商品不存在'); | |||
} else { | |||
@@ -1665,6 +1681,19 @@ 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']) { | |||
$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'] == '精品') { | |||
$data['storeInfo']['is_jingpin'] = 1; | |||
break; | |||
} | |||
} | |||
return $data; | |||
} | |||