Explorar o código

商城,下单

lizhen_gitee hai 11 meses
pai
achega
f8752a7502

+ 19 - 8
addons/unishop/controller/Order.php

@@ -125,16 +125,16 @@ class Order extends Base
             /** 默认地址 **/
             $address = (new AddressModel)->where(['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES])->find();
             if ($address) {
-                $area = (new Area)->whereIn('id', [$address->province_id, $address->city_id, $address->area_id])->column('name', 'id');
+                /*$area = (new Area)->whereIn('id', [$address->province_id, $address->city_id, $address->area_id])->column('name', 'id');
                 $address = $address->toArray();
                 $address['province']['name'] = $area[$address['province_id']];
                 $address['city']['name'] = $area[$address['city_id']];
-                $address['area']['name'] = $area[$address['area_id']];
+                $address['area']['name'] = $area[$address['area_id']];*/
             }
 
 
             /** 可用优惠券 **/
-            $coupon = CouponModel::all(function ($query) {
+            /*$coupon = CouponModel::all(function ($query) {
                 $time = time();
                 $query
                     ->where(['switch' => CouponModel::SWITCH_ON])
@@ -143,24 +143,34 @@ class Order extends Base
             });
             if ($coupon) {
                 $coupon = collection($coupon)->toArray();
-            }
+            }*/
 
 
             /** 运费数据 **/
-            $cityId = $address['city_id'] ? $address['city_id'] : 0;
-            $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
+            /*$cityId = $address['city_id'] ? $address['city_id'] : 0;
+            $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);*/
+
+            $order_price = 0;
+            $delivery_price = 0;
 
             foreach ($productData as &$product) {
                 $product['image'] = Config::getImagesFullUrl($product['image']);
                 $product['sales_price'] = round($product['sales_price'], 2);
                 $product['market_price'] = round($product['market_price'], 2);
+
+                $order_price = bcadd($order_price,$product['total_price'],2);
+                $delivery_price = bcadd($delivery_price,$product['yunfei_price'],2);
             }
 
             $this->success('', [
                 'product' => $productData,
                 'address' => $address,
-                'coupon' => $coupon,
-                'delivery' => $delivery['list'],
+//                'coupon' => $coupon,
+//                'delivery' => $delivery['list'],
+                'order_price' => $order_price,
+                'delivery_price' => $delivery_price,
+                'total_price' => bcadd($order_price,$delivery_price,2),
+
                 'wallet' => Db::name('user_wallet')->where('user_id',$this->auth->id)->find(),
             ]);
 
@@ -192,6 +202,7 @@ class Order extends Base
     public function submit()
     {
         $data = input();
+        $data['city_id'] = 2;
         try {
             $validate = Loader::validate('\\addons\\unishop\\validate\\Order');
             if (!$validate->check($data, [], 'submit')) {

+ 3 - 0
addons/unishop/model/Product.php

@@ -160,6 +160,9 @@ class Product extends Model
         $data['number'] = $number;
         $data['id'] = Hashids::encodeHex($product['id']);
 
+        $data['yunfei_price'] = $product['yunfei_price'];
+        $data['total_price'] = bcmul($data['sales_price'],$number,2);
+
         return $data;
     }
 

+ 5 - 5
addons/unishop/validate/Order.php

@@ -18,7 +18,7 @@ class Order extends Validate
     protected $rule = [
         'product_id' => 'require',
         'number' => 'require',
-        'city_id' => 'require|integer',
+//        'city_id' => 'require|integer',
         'delivery_id' => 'require|integer',
         'remark' => 'max:250',
         'address_id' => 'require',
@@ -31,8 +31,8 @@ class Order extends Validate
     protected $message = [
         'product_id.required' => '产品编号不能为空',
         'number.require' => '商品数量不能为空',
-        'city_id.require' => '收货地址不能为空',
-        'city_id.integer' => '收货地址格式错误',
+//        'city_id.require' => '收货地址不能为空',
+//        'city_id.integer' => '收货地址格式错误',
         'delivery_id.require' => '请选择配送方式',
         'delivery_id.integer' => '配送方式格式错误',
         'remark.max' => '备注不能超过250个文字',
@@ -44,8 +44,8 @@ class Order extends Validate
      * 验证场景
      */
     protected $scene = [
-        'submit'  => ['product_id', 'number', 'city_id', 'address_id', 'delivery_id', 'remark'], // 创建订单
-        'submitFlash'  => ['product_id', 'number', 'city_id', 'address_id', 'delivery_id', 'remark', 'flash_id'], // 秒杀创建订单
+        'submit'  => ['product_id', 'number', /*'city_id',*/ 'address_id', 'delivery_id', 'remark'], // 创建订单
+        'submitFlash'  => ['product_id', 'number',/* 'city_id',*/ 'address_id', 'delivery_id', 'remark', 'flash_id'], // 秒杀创建订单
     ];
 
 }