|
| xqd
@@ -23,7 +23,8 @@ use function foo\func;
|
|
|
use Illuminate\Http\Request;
|
|
|
use App\Services\Base\Attachment;
|
|
|
use App\Services\Base\ErrorCode;
|
|
|
-use Validator, Response, Auth, Cache;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
+use Validator, Response, Auth;
|
|
|
|
|
|
class HomeController extends Controller
|
|
|
{
|
|
| xqd
@@ -777,7 +778,6 @@ class HomeController extends Controller
|
|
|
]
|
|
|
);
|
|
|
|
|
|
-
|
|
|
if ($validator->fails()) {
|
|
|
return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
|
|
|
}
|
|
| xqd
@@ -808,6 +808,8 @@ class HomeController extends Controller
|
|
|
|
|
|
if (request('couponid')) {
|
|
|
$coupon = CouponInfoModel::find(request('couponid'));
|
|
|
+ Cache::store('database')->put($order->out_trade_no, request('couponid'), 10);
|
|
|
+
|
|
|
if ($coupon->type == 1) {
|
|
|
$money = $money * ($coupon->discount / 10);
|
|
|
} else {
|
|
| xqd
@@ -816,9 +818,38 @@ class HomeController extends Controller
|
|
|
|
|
|
}
|
|
|
if (request('cardid')) {
|
|
|
- $discount = CardInfoModel::find(request('cardid'))->price;
|
|
|
- $money = $money - $discount;
|
|
|
+ $money = 0;
|
|
|
}
|
|
|
+
|
|
|
+ if($money == 0){
|
|
|
+ $order->status = 1;
|
|
|
+ $order->save();
|
|
|
+
|
|
|
+ if(request('cardid')){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['order_no'] = $order->out_trade_no;
|
|
|
+ $data['order_id'] = $order->id;
|
|
|
+ $data['order_price'] = $order->price;
|
|
|
+ $data['paid_price'] = 0;
|
|
|
+ $data['type'] = $order->paytype;
|
|
|
+
|
|
|
+ PaidInfoModel::create($data);
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'code' => 200,
|
|
|
+ 'msg' => '支付成功'
|
|
|
+ ];
|
|
|
+
|
|
|
+ $card = CardInfoModel::find(request('cardid'));
|
|
|
+ $card->status =2;
|
|
|
+ $card->save();
|
|
|
+
|
|
|
+ return $this->api(compact('data'));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
$app = Factory::payment($this->options());
|
|
|
|
|
|
$result = $app->order->unify([
|
|
| xqd
@@ -867,6 +898,14 @@ class HomeController extends Controller
|
|
|
|
|
|
PaidInfoModel::create($data);
|
|
|
|
|
|
+ $couponid = Cache::store('database')->get($order->out_trade_no);
|
|
|
+ if($couponid) {
|
|
|
+ $user_id = $order->user_id;
|
|
|
+ $coupon = UserCouponRelationModel::where('coupon_id',$couponid)->where('user_id',$user_id)->first();
|
|
|
+ $coupon->status =1;
|
|
|
+ $coupon->save();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
} else {
|
|
|
return $successful('通信失败,请稍后再通知我');
|
|
| xqd
@@ -1131,7 +1170,7 @@ class HomeController extends Controller
|
|
|
if (!$coupon) {
|
|
|
$data = [
|
|
|
'code' => 10002,
|
|
|
- 'msg' => '改优惠券已被领取完毕!'
|
|
|
+ 'msg' => '该优惠券已被领取完毕!'
|
|
|
];
|
|
|
return $this->api($data);
|
|
|
}
|
|
| xqd
@@ -1148,7 +1187,7 @@ class HomeController extends Controller
|
|
|
} else {
|
|
|
$data = [
|
|
|
'code' => 10002,
|
|
|
- 'msg' => '改优惠券已被领取完毕!'
|
|
|
+ 'msg' => '该优惠券已被领取完毕!'
|
|
|
];
|
|
|
|
|
|
return $this->api($data);
|
|
| xqd
@@ -1294,8 +1333,6 @@ class HomeController extends Controller
|
|
|
* {
|
|
|
* "id": 7,
|
|
|
* "card_no": "15319090241",
|
|
|
- * "price": 50,
|
|
|
- * "min_price": 100,
|
|
|
* "status": 1,
|
|
|
* "user_id": 1,
|
|
|
* "remark": "",
|
|
| xqd
@@ -1376,16 +1413,12 @@ class HomeController extends Controller
|
|
|
$usablecoupons = array_values($usablecoupons);
|
|
|
|
|
|
|
|
|
- $current_product = ProductInfoModel::find(request('product_id'));
|
|
|
- $usableCards = CardInfoModel::where('user_id', $user->id)->where('status', 1)->where('end_time', '>=', now())->where('product_id', 'like', '%' . request('product_id') . '%')->where('min_price','<=',$current_product->origin_price)->get();
|
|
|
+ $usableCards = CardInfoModel::where('user_id', $user->id)->where('status', 1)->where('end_time', '>=', now())->where('product_id', 'like', '%' . request('product_id') . '%')->get();
|
|
|
foreach ($usableCards as $card) {
|
|
|
$card->product = $card->product();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return $this->api(compact('usablecoupons', 'usableCards'));
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|