wesley 6 роки тому
батько
коміт
ccbb075be6

+ 22 - 12
app/Http/Controllers/Api/V1/HomeController.php

xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd xqd
@@ -642,9 +642,9 @@ class HomeController extends Controller
             return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
         }
 
-        $order = OrderInfoModel::with(['paidinfo'])->select(['id', 'out_trade_no', 'username', 'phone', 'email', 'schedule_time', 'status', 'store_id', 'price', 'deposit', 'product_id','photo'])->find(request('order_id'));
+        $order = OrderInfoModel::with(['paidinfo'])->select(['id', 'out_trade_no', 'username', 'phone', 'email', 'schedule_time', 'status', 'store_id', 'price', 'deposit', 'product_id', 'photo'])->find(request('order_id'));
         $photo = $order->photo;
-        $order->photo = explode(',',$photo);
+        $order->photo = explode(',', $photo);
 
         $store = $order->store();
         $product = ProductInfoModel::find($order->product_id);
@@ -801,7 +801,7 @@ class HomeController extends Controller
         } else {
             $money = $order->deposit;
         }
-        session()->put($order->id.'paytype',request('paytype'));
+        session()->put($order->id . 'paytype', request('paytype'));
 
         if (request('couponid')) {
             $coupon = CouponInfoModel::find(request('couponid'));
@@ -819,7 +819,7 @@ class HomeController extends Controller
         $app = Factory::payment($this->options());
 
         $result = $app->order->unify([
-            'body' =>'小相馆 -'.$order->out_trade_no,
+            'body' => '小相馆 -' . $order->out_trade_no,
             'out_trade_no' => $order->out_trade_no,
             'total_fee' => $money * 100,
             'trade_type' => 'JSAPI',
@@ -852,7 +852,7 @@ class HomeController extends Controller
         return $app->handlePaidNotify(function ($notify, $successful) {
             \Log::info($notify);
             if ($notify['result_code'] == 'SUCCESS') {
-                $order = OrderInfoModel::where('out_trade_no',$notify['out_trade_no'])->first();
+                $order = OrderInfoModel::where('out_trade_no', $notify['out_trade_no'])->first();
                 $order->status = 1;
                 $order->save();
 
@@ -861,8 +861,8 @@ class HomeController extends Controller
                 $data['order_price'] = $order->price;
                 $data['paid_price'] = $notify['total_fee'] / 100;
                 $data['type'] = 0;
-                \Log::info($order->id.'paytype');
-                \Log::info(session()->get($order->id.'paytype'));
+                \Log::info($order->id . 'paytype');
+                \Log::info(session()->get($order->id . 'paytype'));
 
                 PaidInfoModel::create($data);
 
@@ -930,6 +930,7 @@ class HomeController extends Controller
         }
         $couponlist = CouponInfoModel::where('end_time', '>', Carbon::now('Asia/Shanghai'))->where('count', '>', 0)->get();
         foreach ($couponlist as $key => $item) {
+            $item->product = $item->product();
             $had = UserCouponRelationModel::where('coupon_id', $item->id)->where('user_id', $user->id)->count();
             if ($had) {
                 unset($couponlist[$key]);
@@ -966,6 +967,10 @@ class HomeController extends Controller
      *                          "discount": "7",            //折扣
      *                          "discount_price": null,      //优惠金额
      *                          "product_id": "1,2",         //可使用的产品id
+     *                          "product":[                  //可使用产品名字
+     *                              "证件照",
+     *                              "履历照"
+     *                          ]
      *                          "count": 10,
      *                          "end_time": "2018-07-31",     //有效期
      *                          "created_at": "2018-07-13 07:29:27",
@@ -987,6 +992,7 @@ class HomeController extends Controller
      *                  "end_time": "2019-07-31",
      *                  "qrcode": null,
      *                  "product_id": "1,2",
+     *                  "product":[],
      *                  "deleted_at": null,
      *                  "created_at": "2018-07-18 10:17:04",
      *                  "updated_at": "2018-08-09 02:11:36"
@@ -1020,18 +1026,22 @@ class HomeController extends Controller
 
         $mycoupons = UserCouponRelationModel::where('user_id', $user->id)->with('coupon')->orderBy('created_at', 'desc')->get();
         $mycoupons = $mycoupons->filter(function ($value) {
-            if(!$value->coupon){
+            if (!$value->coupon) {
                 return false;
             }
             if (strtotime($value->coupon->end_time) < strtotime(Carbon::now('Asia/Shanghai'))) {
                 return false;
             } else {
+                $value->product = $value->product();
                 return true;
             }
 
         });
 
         $mycards = CardInfoModel::where('user_id', $user->id)->where('status', 1)->where('end_time', '>', now())->get();
+        foreach ($mycards as $card){
+            $card->product = $card->product();
+        }
         return $this->api(compact('mycards', 'mycoupons'));
     }
 
@@ -1111,7 +1121,7 @@ class HomeController extends Controller
         }
 
         $coupon = CouponInfoModel::find(request('coupon_id'));
-        if(!$coupon){
+        if (!$coupon) {
             $data = [
                 'code' => 10002,
                 'msg' => '改优惠券已被领取完毕!'
@@ -1330,13 +1340,13 @@ class HomeController extends Controller
             $flag = false;
 
             $product = ProductInfoModel::find(request('product_id'));
-            if(!$value->coupon){
-                $flag =false;
+            if (!$value->coupon) {
+                $flag = false;
                 return $flag;
             }
             $products = explode(',', $value->coupon->product_id);
 
-            $price = $product->current_price?$product->current_price:$product->origin_price;
+            $price = $product->current_price ? $product->current_price : $product->origin_price;
             if ((strtotime($value->coupon->end_time) > strtotime(Carbon::now('Asia/Shanghai'))) && in_array($product->category_id, $products) && ($price >= $value->coupon->min_price)) {
                 $flag = true;
             } else {

+ 5 - 0
app/Models/CardInfoModel.php

xqd
@@ -62,4 +62,9 @@ class CardInfoModel extends BaseModel
 
     }
 
+    public function product(){
+        $product = (new ProductCategoryModel())->whereIn('id',explode(',',$this->product_id))->pluck('name');;
+        return $product;
+    }
+
 }

+ 35 - 29
app/Models/OrderInfoModel.php

xqd
@@ -52,41 +52,47 @@ class OrderInfoModel extends BaseModel
         'deposit'
     ];
 
-  public function store(){
-      return (new StoreInfoModel())->find($this->store_id)->name;
-  }
+    public function store()
+    {
+        return (new StoreInfoModel())->find($this->store_id) ? (new StoreInfoModel())->find($this->store_id)->name : $this->store_id;
+    }
 
-    public function getstore(){
-        return $this->belongsTo('App\Models\StoreInfoModel','store_id');
+    public function getstore()
+    {
+        return $this->belongsTo('App\Models\StoreInfoModel', 'store_id');
     }
 
-  public function product(){
-      return $this->belongsTo('App\Models\ProductInfoModel','product_id');
-  }
+    public function product()
+    {
+        return $this->belongsTo('App\Models\ProductInfoModel', 'product_id');
+    }
 
-  public function status(){
-      switch ($this->status){
-          case 1:
-              return '已付款';
-              break;
-          case 2:
-              return '已完成';
-              break;
-          case 3:
-              return '已取消';
-              break;
-          default:
-              return '未付款';
-              break;
+    public function status()
+    {
+        switch ($this->status) {
+            case 1:
+                return '已付款';
+                break;
+            case 2:
+                return '已完成';
+                break;
+            case 3:
+                return '已取消';
+                break;
+            default:
+                return '未付款';
+                break;
 
-      }
-  }
+        }
+    }
 
-  public function paidinfo(){
-      return $this->hasOne('App\Models\PaidInfoModel','order_id');
-  }
+    public function paidinfo()
+    {
+        return $this->hasOne('App\Models\PaidInfoModel', 'order_id');
+    }
 
-    public function refundinfo(){
-        return $this->hasOne('App\Models\RefundInfoModel','order_id');
+    public function refundinfo()
+    {
+        return $this->hasOne('App\Models\RefundInfoModel', 'order_id');
     }
 }