Browse Source

复制健康E家改好的商城,接口

lizhen_gitee 4 months ago
parent
commit
292e20e5e3

+ 44 - 12
addons/unishop/behavior/Order.php

@@ -120,18 +120,47 @@ class Order
      */
     public function createOrderBefore(&$params, $extra)
     {
+        if(empty($extra['cart'])){
 
-        $specs = explode(',', $extra['spec']);
-        foreach ($specs as &$spec) {
-            $spec = str_replace('|', ',', $spec);
-        }
-        $numbers = explode(',', $extra['number']);
-        $productIds = explode(',', $extra['product_id']);
+            $specs = explode(',', $extra['spec']);
+            foreach ($specs as &$spec) {
+                $spec = str_replace('|', ',', $spec);
+            }
+            $numbers = explode(',', $extra['number']);
+            $productIds = explode(',', $extra['product_id']);
+
+            if (count($specs) !== count($numbers) || count($specs) !== count($productIds)) {
+                throw new Exception(__('Parameter error'));
+            }
+
+        }else{
+
+            $carts = Db::name('unishop_cart')->field('id,product_id,spec,number')
+                ->whereIn('id', $extra['cart'])
+                ->order(['id' => 'desc'])
+                ->select();
+
+//            dump($carts);
+
+            $numbers    = array_column($carts,'number');
+            $productIds = array_column($carts,'product_id');
+            $specs      = array_column($carts,'spec');
+
+            foreach ($productIds as $key => $productId) {
+                $productIds[$key] = Hashids::encodeHex($productId);
+            }
+
+            foreach ($specs as $key => $spec) {
+                $specs[$key] = is_null($spec) ? '' : $spec;
+            }
 
-        if (count($specs) !== count($numbers) || count($specs) !== count($productIds)) {
-            throw new Exception(__('Parameter error'));
         }
 
+        /*dump($numbers);
+        dump($productIds);
+        dump($specs);
+        exit;*/
+
         // 订单价格
         $orderPrice = 0;
 
@@ -174,21 +203,23 @@ class Order
         }
 
         // 条件三
-        $delivery = (new DeliveryRuleModel())->cityInScopeOfDelivery($extra['city_id'], $extra['delivery_id']);
+        /*$delivery = (new DeliveryRuleModel())->cityInScopeOfDelivery($extra['city_id'], $extra['delivery_id']);
         if (!$delivery) {
             throw new Exception(__('Your receiving address is not within the scope of delivery'));
         } else {
             if ($delivery['min'] > array_sum($numbers)) {
                 throw new Exception(__('You must purchase at least %s item to use this shipping method', $delivery['min']));
             }
-        }
+        }*/
+        $delivery = [];
+
         $address = (new Address)->where(['id' => $extra['address_id'], 'user_id' => $extra['userId']])->find();
         if (!$address) {
             throw new Exception(__('Address not exist'));
         }
 
         // 条件四
-        if ($extra['coupon_id']) {
+        /*if ($extra['coupon_id']) {
             $coupon = Coupon::get($extra['coupon_id']);
             if ($coupon['switch'] == Coupon::SWITCH_OFF || $coupon['deletetime'] || $coupon['starttime'] > time() || $coupon['endtime'] < time()) {
                 throw new Exception('此优惠券不可用');
@@ -199,7 +230,8 @@ class Order
             }
         } else {
             $coupon = [];
-        }
+        }*/
+        $coupon = [];
 
         $params = [$products, $delivery, $coupon, $baseProductInfo, $address, $orderPrice, $specs, $numbers];
     }

+ 17 - 11
addons/unishop/controller/Address.php

@@ -25,7 +25,7 @@ class Address extends Base
      * 允许频繁访问的接口
      * @var array
      */
-    protected $frequently = ['area'];
+    protected $frequently = ['area','all','info'];
 
     /**
      * @ApiTitle    (全部收货地址)
@@ -49,15 +49,15 @@ class Address extends Base
      */
     public function all()
     {
-        $page = $this->request->post('page', 1);
-        $pagesize = $this->request->post('pagesize', 15);
+        $page = input('page', 1);
+        $pagesize = input('pagesize', 15);
 
         $data = (new AddressModel())
-            ->with([
+            /*->with([
                 'province' => function($query) {$query->field('id,name');},
                 'city' => function($query) {$query->field('id,name');},
                 'area' => function($query) {$query->field('id,name');}
-            ])
+            ])*/
             ->where('user_id', $this->auth->id)
             ->order(['is_default' => 'desc', 'id' => 'desc'])
             ->limit(($page - 1) * $pagesize, $pagesize)
@@ -90,7 +90,7 @@ class Address extends Base
      */
     public function add()
     {
-        $data = $this->request->post();
+        $data = input();
         try {
             $validate = Loader::validate('\\addons\\unishop\\validate\\Address');
             if (!$validate->check($data, [], 'add')) {
@@ -136,7 +136,7 @@ class Address extends Base
      */
     public function edit()
     {
-        $data = $this->request->post();
+        $data = input();
         try {
             new Validate();
             $validate = Loader::validate('\\addons\\unishop\\validate\\Address');
@@ -170,7 +170,7 @@ class Address extends Base
      */
     public function delete()
     {
-        $address_id = $this->request->get('id', 0);
+        $address_id = input('id', 0);
 
         $data = (new AddressModel())
             ->where([
@@ -200,7 +200,7 @@ class Address extends Base
      */
     public function area()
     {
-        $pid = $this->request->get('pid', 1);
+        $pid = input('pid', 1);
         Cache::clear('area_pid_'.$pid);
         if (Cache::has('area_pid_'.$pid)) {
             $area = Cache::get('area_pid_'.$pid);
@@ -240,8 +240,14 @@ class Address extends Base
      */
     public function info()
     {
-        $id = $this->request->get('id');
-        $address = (new AddressModel())->where(['id' => $id, 'user_id' => $this->auth->id])->find()->toArray();
+        $id = input('id');
+        $address = (new AddressModel())
+           /* ->with([
+                'province' => function($query) {$query->field('id,name');},
+                'city' => function($query) {$query->field('id,name');},
+                'area' => function($query) {$query->field('id,name');}
+            ])*/
+            ->where(['id' => $id, 'user_id' => $this->auth->id])->find()->toArray();
         $this->success('', $address);
     }
 

+ 24 - 3
addons/unishop/controller/Base.php

@@ -30,13 +30,22 @@ class Base extends Api
      */
     protected $frequently = [];
 
-    public function _initialize()
+    /*public function _initialize()
     {
         parent::_initialize();
 
         $this->loadUniShopLang();
 
         $this->limitVisit();
+    }*/
+
+    public function __construct()
+    {
+        parent::__construct();
+
+        $this->loadUniShopLang();
+
+        $this->limitVisit();
     }
 
     /**
@@ -44,8 +53,8 @@ class Base extends Api
      * @param int $millisecond
      * @ApiInternal
      */
-    public function limitVisit($millisecond = 200) {
-        $millisecond = $this->request->request('millisecond', $millisecond);
+    public function limitVisit_bak($millisecond = 200) {
+        //$millisecond = $this->request->request('millisecond', $millisecond);
 
         // 限制200毫秒 防止1秒两刀 (双击甚至三击,同一时间导致接口请求两次以上)
         $action = $this->request->action();
@@ -60,6 +69,18 @@ class Base extends Api
         }
     }
 
+    public function limitVisit($millisecond = 200) {
+
+        $action = $this->request->action();
+        if (!in_array($action, $this->frequently) && $this->auth && $this->auth->isLogin() && $millisecond > 0) {
+            $apilimit = $this->apiLimit();
+            if(!$apilimit){
+                $this->error('操作过于频繁');
+            }
+
+        }
+    }
+
     /**
      * 加载语言文件
      */

+ 39 - 15
addons/unishop/controller/Cart.php

@@ -24,7 +24,7 @@ class Cart extends Base
      * 允许频繁访问的接口
      * @var array
      */
-    protected $frequently = ['number_change', 'choose_change'];
+    protected $frequently = ['number_change','index', 'choose_change'];
 
     /**
      * @ApiTitle    (列表)
@@ -61,17 +61,27 @@ class Cart extends Base
             ->order(['createtime' => 'desc'])
             ->select();
         if (!$carts) {
-            $this->success('', []);
+//            $this->success('', []);
+
+            $result = [
+                'choose_price_total' => '0',
+                'choose_number' => 0,
+                'list' => [],
+            ];
+            $this->success('', $result);
         }
 
         $data = [];
         $productExtend = new \addons\unishop\extend\Product;
 
+        $choose_price_total = '0';//已选中的总价格
+        $choose_number = 0;//已选中的个数
         foreach ($carts as $item) {
             $oldProduct = json_decode($item['snapshot'], true);
             $oldData = $productExtend->getBaseData($oldProduct, $item['spec'] ?? '');
 
-            if (empty($item['product'])) {
+            if (empty($item['product'])) { //商品被删了的情况
+                continue;//不要了
                 $tempData = $oldData;
                 $tempData['isset'] = false; // 失效
                 $tempData['title'] = $oldProduct['title'];
@@ -84,6 +94,7 @@ class Cart extends Base
 
                 $tempData['isset'] = true;
                 if ($productData['switch'] == Product::SWITCH_OFF) {
+                    continue;//不要了
                     $tempData['isset'] = false; // 失效
                     $tempData['choose'] = 0;
                 }
@@ -96,13 +107,25 @@ class Cart extends Base
             $tempData['image'] = Config::getImagesFullUrl($oldData['image']);
             $tempData['oldPrice'] = round($oldData['sales_price'], 2);
             $tempData['nowPrice'] = round($tempData['sales_price'], 2);
+            //新增此商品总价
+            $tempData['Price_total'] = bcmul($tempData['sales_price'],$tempData['number'],2);
+            //已选中商品,总价格
+            if($item['choose'] == 1){
+                $choose_price_total = bcadd($choose_price_total,$tempData['Price_total'],2);
+                $choose_number += $tempData['number'];
+            }
 
             $tempData['product_id'] = Hashids::encodeHex($item['product_id']);
 
             $data[] = $tempData;
         }
 
-        $this->success('', $data);
+        $result = [
+            'choose_price_total' => $choose_price_total,
+            'choose_number' => $choose_number,
+            'list' => $data,
+        ];
+        $this->success('', $result);
     }
 
 
@@ -117,7 +140,8 @@ class Cart extends Base
      */
     public function add()
     {
-        $id = $this->request->get('id', 0);
+        $id = input('id', 0);
+        $number = input('number',1);
 
         $id = \addons\unishop\extend\Hashids::decodeHex($id);
 
@@ -126,7 +150,7 @@ class Cart extends Base
             $this->error('产品不存在或已下架');
         }
 
-        $spec = $this->request->get('spec', '');
+        $spec = input('spec', '');
         $productBase = (new \addons\unishop\extend\Product())->getBaseData($product->getData(), $spec);
         if (!$productBase['stock'] || $productBase['stock'] <= 0) {
             $this->error('库存不足');
@@ -139,14 +163,14 @@ class Cart extends Base
         $oldCart = $cartModel->find();
 
         if ($oldCart) {
-            $this->error('商品已存在购物车');
-//            $oldCart->number++;
-//            $result = $oldCart->save();
+            //$this->error('商品已存在购物车');
+            $oldCart->number += $number;
+            $result = $oldCart->save();
         } else {
             $cartModel->user_id = $user_id;
             $cartModel->product_id = $id;
             $spec && $cartModel->spec = $spec;
-            $cartModel->number = 1;
+            $cartModel->number = $number;
             $cartModel->snapshot = json_encode($product->getData(), true);
             $result = $cartModel->save();
         }
@@ -169,7 +193,7 @@ class Cart extends Base
      */
     public function delete()
     {
-        $id = $this->request->post('id', 0);
+        $id = input('id', 0);
         $userId = $this->auth->id;
         $result = CartModel::destroy(function ($query) use ($id, $userId) {
             $query->whereIn('id', $id)->where(['user_id' => $userId]);
@@ -192,8 +216,8 @@ class Cart extends Base
      */
     public function number_change()
     {
-        $cart_id = $this->request->get('id', 0);
-        $number = $this->request->get('number', 1);
+        $cart_id = input('id', 0);
+        $number = input('number', 1);
         $cart = CartModel::get(['id' => $cart_id, 'user_id' => $this->auth->id]);
         if (empty($cart)) {
             $this->error('此商品不存在购物车');
@@ -218,8 +242,8 @@ class Cart extends Base
      */
     public function choose_change()
     {
-        $trueArr = $this->request->post('trueArr', false);
-        $falseArr = $this->request->post('falseArr', false);
+        $trueArr = input('trueArr', false);
+        $falseArr = input('falseArr', false);
         $user_id = $this->auth->id;
         try {
             $cart = new CartModel();

+ 46 - 2
addons/unishop/controller/Category.php

@@ -3,13 +3,14 @@
 namespace addons\unishop\controller;
 
 use app\common\controller\Api;
-
+use think\Db;
 /**
  * 分类
  */
 class Category extends Api
 {
 
+    protected $frequently = ['all','menu','inlist'];
     protected $noNeedLogin = ['all','menu','inlist'];
     protected $noNeedRight = ['*'];
 
@@ -40,7 +41,7 @@ class Category extends Api
         $all = $this->model
             ->where('type','product')
             ->where('status','normal')
-            ->field('id,name,pid,image,type,flag,weigh')
+            ->field('id,name,nickname,pid,image,type,flag,weigh')
             ->order('weigh ASC')
             ->cache(20)
             ->select();
@@ -50,6 +51,49 @@ class Category extends Api
         $this->success('',$all);
     }
 
+    public function inlist(){
+        $list = Db::name('unishop_category')
+            ->where('status','normal')
+            ->field('id,name,nickname,keywords')
+            ->order('weigh ASC')
+            ->cache(20)
+            ->select();
+
+        $this->success('',$list);
+    }
+
+    public function inlist_old(){
+        $list = Db::name('unishop_category')
+            ->where('status','normal')
+            ->field('id,name,nickname,pid')
+            ->order('weigh ASC')
+            ->cache(20)
+            ->select();
+
+        //按级拆分
+        $list_1 = [];
+        $list_2 = [];
+
+        foreach($list as $key => $value){
+            if($value['pid'] == 0){
+                $list_1[] = $value;
+            }else{
+                $list_2[] = $value;
+            }
+        }
+
+        //市级并到省级
+        foreach($list_1 as $k1 => $v1){
+            foreach($list_2 as $k2 => $v2){
+                if($v1['id'] == $v2['pid']){
+                    $list_1[$k1]['child'][] = $v2;
+                }
+            }
+        }
+
+        $this->success('',$list_1);
+    }
+
 
     /**
      * @ApiTitle    (首页广告下面的分类)

+ 291 - 48
addons/unishop/controller/Order.php

@@ -23,6 +23,7 @@ use think\Exception;
 use addons\unishop\model\Address as AddressModel;
 use think\Hook;
 use think\Loader;
+use addons\epay\library\Service;
 
 /**
  * 订单
@@ -34,7 +35,7 @@ class Order extends Base
      * 允许频繁访问的接口
      * @var array
      */
-    protected $frequently = ['getorders'];
+    protected $frequently = ['getorders','getOrders','detail','refund_reason'];
 
     protected $noNeedLogin = ['count'];
 
@@ -91,21 +92,25 @@ class Order extends Base
      */
     public function create()
     {
-        $productId = $this->request->post('id', 0);
+        $productId = input('id', 0);
 
         try {
             $user_id = $this->auth->id;
 
             // 单个商品
             if ($productId) {
+                $number = input('number',1,'intval');
+                $number = intval($number);
                 $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
                 $product = (new Product)->where(['id' => $productId, 'switch' => Product::SWITCH_ON, 'deletetime' => null])->find();
                 /** 产品基础数据 **/
-                $spec = $this->request->post('spec', '');
-                $productData[0] = $product->getDataOnCreateOrder($spec);
+                $spec = input('spec', '');
+
+                $productData[0] = $product->getDataOnCreateOrder($spec,$number);
+
             } else {
                 // 多个商品
-                $cart = $this->request->post('cart');
+                $cart = input('cart');
                 $carts = (new \addons\unishop\model\Cart)
                     ->whereIn('id', $cart)
                     ->with(['product'])
@@ -123,18 +128,24 @@ class Order extends Base
             }
 
             /** 默认地址 **/
-            $address = (new AddressModel)->where(['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES])->find();
+            $address_map = ['user_id' => $user_id, 'is_default' => AddressModel::IS_DEFAULT_YES];
+
+            $address_id = input('address_id',0);
+            if($address_id){
+                $address_map = ['user_id' => $user_id, 'id' => $address_id];
+            }
+            $address = (new AddressModel)->where($address_map)->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 +154,35 @@ 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(),
             ]);
 
         } catch (Exception $e) {
@@ -190,7 +212,13 @@ class Order extends Base
      */
     public function submit()
     {
-        $data = $this->request->post();
+        $data = input();
+
+        $pay_type = input('pay_type','alipay');
+        if(!in_array($pay_type,['wechat','alipay','wallet'])){
+            $this->error();
+        }
+
         try {
             $validate = Loader::validate('\\addons\\unishop\\validate\\Order');
             if (!$validate->check($data, [], 'submit')) {
@@ -241,7 +269,7 @@ class Order extends Base
      */
     public function getDelivery()
     {
-        $cityId = $this->request->get('city_id', 0);
+        $cityId = input('city_id', 0);
         $delivery = (new DeliveryRuleModel())->getDelivetyByArea($cityId);
         $this->success('', $delivery['list']);
     }
@@ -287,9 +315,9 @@ class Order extends Base
     public function getOrders()
     {
         // 0=全部,1=待付款,2=待发货,3=待收货,4=待评价,5=售后
-        $type = $this->request->get('type', 0);
-        $page = $this->request->get('page', 1);
-        $pagesize = $this->request->get('pagesize', 10);
+        $type = input('type', 0);
+        $page = input('page', 1);
+        $pagesize = input('pagesize', 10);
         try {
 
             $orderModel = new \addons\unishop\model\Order();
@@ -314,7 +342,7 @@ class Order extends Base
      */
     public function cancel()
     {
-        $order_id = $this->request->get('order_id', 0);
+        $order_id = input('order_id', 0);
         $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
 
         $orderModel = new \addons\unishop\model\Order();
@@ -333,17 +361,212 @@ class Order extends Base
                 break;
         }
 
-        if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) {
+        /*if ($order['have_paid'] != \addons\unishop\model\Order::PAID_NO) {
             $this->error('此订单已支付,无法取消');
+        }*/
+        if ($order['have_delivered'] != \addons\unishop\model\Order::DELIVERED_NO) {
+            $this->error('此订单已发货,无法取消');
         }
 
-        if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
-            $order->status = \addons\unishop\model\Order::STATUS_CANCEL;
-            $order->save();
+//        if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_paid'] == \addons\unishop\model\Order::PAID_NO) {
+        if ($order['status'] == \addons\unishop\model\Order::STATUS_NORMAL && $order['have_delivered'] == \addons\unishop\model\Order::DELIVERED_NO) {
+
+            Db::startTrans();
+            /*$order->status = \addons\unishop\model\Order::STATUS_CANCEL;
+            $order->save();*/
+
+
+            //已付款的,自动退款
+            if($order['have_paid'] != \addons\unishop\model\Order::PAID_NO){
+                $refund_amount = $order['total_price'];
+                $refund_status = 3;
+
+                // 退款
+                $params = [
+                    'refund_status' => $refund_status,
+                    'updatetime'    => time(),
+                    'refund_amount' => $refund_amount,
+                    'status' => \addons\unishop\model\Order::STATUS_CANCEL,
+                ];
+                if($refund_status == 3) {
+                    $params['had_refund'] = time();
+                }
+
+                $result = Db::name('unishop_order')->where(['id' => $order_id])->update($params);
+                if (!$result) {
+                    Db::rollback();
+                    $this->error('取消失败');
+                }
+
+                //同意并执行退款
+                if($refund_status == 3 && $refund_amount > 0){
+                    $order = Db::name('unishop_order')->where('id',$order_id)->find();
+
+                    if($order['pay_type'] == 2){
+                        $wallet = new \app\common\model\Wallet();
+                        $wallet_rs = $wallet->lockChangeAccountRemain($order['user_id'],'money',$refund_amount,32,'商城取消订单退款'.$order['out_trade_no'],'unishop_order',$order_id);
+                        if($wallet_rs['status'] === false){
+                            Db::rollback();
+                            $this->error($wallet_rs['msg']);
+                        }
+                    }elseif($order['pay_type'] == 3 || $order['pay_type'] == 4){
+                        $refund_result = $this->old_refund($order,$refund_amount);
+                        if($refund_result !== true){
+                            Db::rollback();
+                            $this->error($refund_result);
+                        }
+                    }
+
+                }
+            }else{
+                $params = [
+                    'status' => \addons\unishop\model\Order::STATUS_CANCEL,
+                ];
+                $result = Db::name('unishop_order')->where(['id' => $order_id])->update($params);
+                if ($result === false) {
+                    Db::rollback();
+                    $this->error('取消失败');
+                }
+            }
+
+            Db::commit();
+
             $this->success('取消成功', true);
         }
     }
 
+    // 退款
+    public function old_refund($order, $refund_price)
+    {
+
+        $table = 'unishop_order';
+        $remark = '订单退款';
+
+        if($order['pay_type'] == 3){
+            $order['pay_type'] = 'wechat';
+        }
+        if($order['pay_type'] == 4){
+            $order['pay_type'] = 'alipay';
+        }
+
+        // 生成退款单
+        $refund_data = [
+            'order_id' => $order['id'],
+            'out_refund_no'=> createUniqueNo('R'),
+            'pay_fee'  => $order['total_price'],
+            'refund_price' => $refund_price,
+            'pay_type' => $order['pay_type'],
+            'status' => 0,
+            'createtime' => time(),
+            'updatetime' => time(),
+            'table' => $table,
+            'table_id' => $order['id'],
+        ];
+        $refund_log_id = Db::name('pay_order_refund_log')->insertGetId($refund_data);
+        if(!$refund_log_id){
+            return '退款失败';
+        }
+
+        if ($order['pay_type'] == 'wechat' || $order['pay_type'] == 'alipay') {
+            // 微信|支付宝退款
+
+            // 退款数据
+            $order_data = [
+                'out_trade_no' => $order['pay_out_trade_no']
+            ];
+
+            if ($order['pay_type'] == 'wechat') {
+                $total_fee = $order['total_price'] * 100;
+                $refund_fee = $refund_price * 100;
+
+                $order_data = array_merge($order_data, [
+                    'out_refund_no' => $refund_data['out_refund_no'],
+                    'total_fee' => $total_fee,
+                    'refund_fee' => $refund_fee,
+                    'refund_desc' => $remark,
+                ]);
+            } else {
+                $order_data = array_merge($order_data, [
+                    'out_request_no' => $refund_data['out_refund_no'],
+                    'refund_amount' => $refund_price,
+                ]);
+            }
+
+            //
+            if ($order['pay_type'] == 'wechat') {
+                $wxpay = new \app\common\library\Wxpay;
+                $result = $wxpay->WxPayRefund($order_data);
+                // 微信通知回调 pay->notifyr
+                if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
+                    Db::name('pay_order_refund_log')->where('id',$refund_log_id)->update(['status'=>1]);
+                    return true;
+                } else {
+                    return $result['return_msg'];
+                }
+            } else {
+
+                $result = Service::submitRefund($order['total_price'],$refund_price,$order['pay_out_trade_no'],$refund_data['out_refund_no'],$order['pay_type'],$remark,'');
+
+                if($result['code'] == '10000'){
+                    Db::name('pay_order_refund_log')->where('id',$refund_log_id)->update(['status'=>1]);
+                    return true;
+                }else{
+                    return $result['msg'];
+                }
+
+
+
+                /* return 'alipay wrong way';
+                 $alipay = new \app\common\library\AliPay;
+                 $result = $alipay->AliPayRefund($order_data);
+                 // 支付宝通知回调 pay->notifyx
+                 return $result;*/
+
+                /*if ($result['code'] == "10000") {
+                    return true;
+                } else {
+                    throw new \Exception($result['msg']);
+                }*/
+            }
+
+            // {        // 微信返回结果
+            //     "return_code":"SUCCESS",
+            //     "return_msg":"OK",
+            //     "appid":"wx39cd0799d4567dd0",
+            //     "mch_id":"1481069012",
+            //     "nonce_str":"huW9eIAb5BDPn0Ma",
+            //     "sign":"250316740B263FE53F5DFF50AF5A8FA1",
+            //     "result_code":"SUCCESS",
+            //     "transaction_id":"4200000497202004072822298902",
+            //     "out_trade_no":"202010300857029180027000",
+            //     "out_refund_no":"1586241595",
+            //     "refund_id":"50300603862020040700031444448",
+            //     "refund_channel":[],
+            //     "refund_fee":"1",
+            //     "coupon_refund_fee":"0",
+            //     "total_fee":"1",
+            //     "cash_fee":"1",
+            //     "coupon_refund_count":"0",
+            //     "cash_refund_fee":"1
+            // }
+
+            // {        // 支付宝返回结果
+            //     "code": "10000",
+            //     "msg": "Success",
+            //     "buyer_logon_id": "157***@163.com",
+            //     "buyer_user_id": "2088902485164146",
+            //     "fund_change": "Y",
+            //     "gmt_refund_pay": "2020-08-15 16:11:45",
+            //     "out_trade_no": "202002460317545607015300",
+            //     "refund_fee": "0.01",
+            //     "send_back_fee": "0.00",
+            //     "trade_no": "2020081522001464141438570535"
+            // }
+        }
+
+        return true;
+    }
+
     /**
      * @ApiTitle    (删除订单)
      * @ApiSummary  (只能删除已取消或已退货的订单)
@@ -356,7 +579,7 @@ class Order extends Base
      */
     public function delete()
     {
-        $order_id = $this->request->get('order_id', 0);
+        $order_id = input('order_id', 0);
         $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
 
         $orderModel = new \addons\unishop\model\Order();
@@ -390,7 +613,7 @@ class Order extends Base
      */
     public function received()
     {
-        $order_id = $this->request->get('order_id', 0);
+        $order_id = input('order_id', 0);
         $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
 
         $orderModel = new \addons\unishop\model\Order();
@@ -426,12 +649,12 @@ class Order extends Base
      */
     public function comment()
     {
-        $rate = $this->request->post('rate', 5);
-        $anonymous = $this->request->post('anonymous', 0);
-        $comment = $this->request->post('comment');
-        $order_id = $this->request->post('order_id', 0);
+        $rate = input('rate', 5);
+        $anonymous = input('anonymous', 0);
+        $comment = input('comment');
+        $order_id = input('order_id', 0);
         $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
-        $product_id = $this->request->post('product_id');
+        $product_id = input('product_id');
         $product_id = \addons\unishop\extend\Hashids::decodeHex($product_id);
 
         $orderProductModel = new \addons\unishop\model\OrderProduct();
@@ -589,7 +812,7 @@ class Order extends Base
      */
     public function detail()
     {
-        $order_id = $this->request->get('order_id', 0);
+        $order_id = input('order_id', 0);
         $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
 
         try {
@@ -623,12 +846,10 @@ class Order extends Base
 
                 // 送货地址
                 $address = json_decode($order['extend']['address_json'], true);
-                $area = (new \addons\unishop\model\Area())
-                    ->whereIn('id', [$address['province_id'], $address['city_id'], $address['area_id']])
-                    ->column('name', 'id');
+
                 $delivery['username'] = $address['name'];
                 $delivery['mobile'] = $address['mobile'];
-                $delivery['address'] = $area[$address['province_id']] . ' ' . $area[$address['city_id']] . ' ' . $area[$address['area_id']] . ' ' . $address['address'];
+                $delivery['address'] = $address['province_name'] . ' ' . $address['city_name'] . ' ' . $address['area_name'] . ' ' . $address['address'];
                 $order['delivery'] = $delivery;
 
                 // 是否已评论
@@ -690,7 +911,7 @@ class Order extends Base
      */
     public function refundInfo()
     {
-        $order_id = $this->request->post('order_id');
+        $order_id = input('order_id');
         $order_id = \addons\unishop\extend\Hashids::decodeHex($order_id);
 
         $orderModel = new \addons\unishop\model\Order();
@@ -749,7 +970,7 @@ class Order extends Base
      */
     public function refund()
     {
-        $order_id = $this->request->post('order_id');
+        $order_id = input('order_id');
         $order_id = Hashids::decodeHex($order_id);
         $orderModel = new \addons\unishop\model\Order();
         $order = $orderModel->where(['id' => $order_id, 'user_id' => $this->auth->id])->find();
@@ -757,16 +978,29 @@ class Order extends Base
         if (!$order) {
             $this->error(__('Order not exist'));
         }
-        if ($order['have_paid'] == 0) {
+        /*if ($order['have_paid'] == 0) {
             $this->error(__('订单未支付,可直接取消,无需申请售后'));
+        }*/
+        if ($order['have_delivered'] == 0) {
+            $this->error(__('订单未发货,可直接取消,无需申请售后'));//发货的才能走售后,未发货的走取消
+        }
+        if($order->status == 0){
+            $this->error('当前订单不能申请退款');
+        }
+        if($order->status == -1){
+            $this->error('当前订单已经申请过退款');
         }
 
-        $amount = $this->request->post('amount', 0);
-        $serviceType = $this->request->post('service_type');
-        $receivingStatus = $this->request->post('receiving_status');
-        $reasonType = $this->request->post('reason_type');
-        $refundExplain = $this->request->post('refund_explain');
-        $orderProductId = $this->request->post('order_product_id');
+        //$amount = input('amount', 0);
+        $amount = $order->total_price;
+        $serviceType = input('service_type',1);
+        $receivingStatus = input('receiving_status',1);
+        $reasonType = input('reason_type','');
+        $refundExplain = input('refund_explain','');
+        $images = input('images','');
+//        $orderProductId = input('order_product_id');
+        $orderProductId = Db::name('unishop_order_product')->where('order_id',$order_id)->column('product_id');
+        $orderProductId = implode(',', $orderProductId);
 
         if (!$orderProductId) {
             $this->error(__('Please select goods'));
@@ -794,6 +1028,7 @@ class Order extends Base
             $orderRefund->reason_type = $reasonType;
             $orderRefund->amount = $amount;
             $orderRefund->refund_explain = $refundExplain;
+            $orderRefund->images = $images;
             $orderRefund->save();
 
             $productIdArr = explode(',', $orderProductId);
@@ -833,8 +1068,8 @@ class Order extends Base
      */
     public function refundDelivery()
     {
-        $orderId = $this->request->post('order_id');
-        $expressNumber = $this->request->post('express_number');
+        $orderId = input('order_id');
+        $expressNumber = input('express_number');
 
         if (!$expressNumber) {
             $this->error(__('Please fill in the express number'));
@@ -883,7 +1118,7 @@ class Order extends Base
      */
     public function express() {
 
-        $params = $this->request->post();
+        $params = input();
         if (!class_exists(\addons\expressquery\library\Expressquery::class)) {
             $this->error('请先安装插件《物流信息接口》', []);
         }
@@ -903,4 +1138,12 @@ class Order extends Base
             'company' => $expressInfo['name'] ?? '快递单号'
         ]);
     }
+
+    /*
+     * 申请退货原因
+     * */
+    public function refund_reason(){
+        $list = Db::name('unishop_refundreason')->order('weigh asc')->select();
+        $this->success(1,$list);
+    }
 }

+ 132 - 17
addons/unishop/controller/Product.php

@@ -16,6 +16,7 @@ use think\Exception;
 class Product extends Base
 {
     protected $noNeedLogin = ['detail', 'lists'];
+    protected $frequently = ['detail', 'lists'];
 
     /**
      * @ApiTitle    (产品详情)
@@ -48,7 +49,7 @@ class Product extends Base
      */
     public function detail()
     {
-        $productId = $this->request->get('id');
+        $productId = input('id');
         $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
 
         try {
@@ -107,7 +108,8 @@ class Product extends Base
             if ($evaluate) {
                 $data->evaluate_list = collection($evaluate)->append(['createtime_text'])->toArray();
             }
-            $data = $data->append(['images_text', 'spec_list', 'spec_table_list'])->toArray();
+            $data = $data->append(['images_text','videothumb', 'spec_list', 'spec_table_list'])->toArray();
+            unset($data['switch']);
         } catch (Exception $e) {
             $this->error($e->getMessage());
         }
@@ -134,17 +136,29 @@ class Product extends Base
      */
     public function lists()
     {
-        $page = $this->request->get('page', 1);
-        $pagesize = $this->request->get('pagesize', 20);
-        $by = $this->request->get('by', 'weigh');
-        $desc = $this->request->get('desc', 'desc');
+        $page = input('page', 1);
+        $pagesize = input('pagesize', 20);
+        $by = input('by', 'weigh');
+        $desc = input('desc', 'desc');
 
-        $sid = $this->request->get('sid'); // 二级分类Id
-        $fid = $this->request->get('fid'); // 一级分类Id
+//        $sid = input('sid'); // 二级分类Id
+        $fid = input('fid'); // 一级分类Id
+
+        $keyword = input('keyword','');//搜索
+
+        //图片搜索
+        $image = input('image','');
+        if(!empty($image)){
+            $keyword = $this->search_by_image($image);
+            //dump($keyword);
+            if(empty($keyword)){
+                $this->success('', []);
+            }
+        }
 
         $productModel = new productModel();
 
-        if ($fid && !$sid) {
+       /* if ($fid && !$sid) {
             $categoryModel = new \addons\unishop\model\Category();
             $sArr = $categoryModel->where('pid', $fid)->field('id')->select();
             $sArr = array_column($sArr, 'id');
@@ -152,23 +166,124 @@ class Product extends Base
             $productModel->where('category_id', 'in', $sArr);
         } else {
             $sid && $productModel->where(['category_id' => $sid]);
+        }*/
+
+        $fid && $productModel->where(['category_id' => $fid]);
+
+        if(!empty($keyword)){
+            $productModel->where('title', 'LIKE', '%'.$keyword.'%');
         }
 
         $result = $productModel
             ->where(['switch' => productModel::SWITCH_ON])
             ->page($page, $pagesize)
             ->order($by, $desc)
-            ->field('id,title,image,sales_price,sales,real_sales')
+            ->field('id,title,info,image,sales_price,sales,real_sales')
             ->select();
 
         if ($result) {
             $result = collection($result)->toArray();
         } else {
-            $this->error('没有更多数据');
+            $result = [];
         }
         $this->success('', $result);
     }
 
+    //腾讯云拍照识别商品
+    //{"Response":{"Products":[{"Name":"按摩椅","Parents":"家用电器-个护健康","Confidence":99,"XMin":107,"YMin":59,"XMax":447,"YMax":366}],"RequestId":"187745fc-0497-441e-88f5-f3f17d854016"}}
+    private function search_by_image($image){
+
+        $image = $image.'?imageMogr2/thumbnail/800x800';
+
+        $tencent_yun = config('tencent_yun');
+        $secret_id   = $tencent_yun['secret_id'];
+        $secret_key  = $tencent_yun['secret_key'];
+
+        $token       = "";
+        $service     = "tiia";
+        $host        = "tiia.tencentcloudapi.com";
+        $req_region  = "ap-beijing";
+        $version     = "2019-05-29";
+        $action      = "DetectProduct";
+        $payload     = json_encode(['ImageUrl' => localpath_to_netpath($image)]);
+        $endpoint    = "https://tiia.tencentcloudapi.com";
+        $algorithm   = "TC3-HMAC-SHA256";
+        $timestamp   = time();
+        $date        = gmdate("Y-m-d", $timestamp);
+
+// ************* 步骤 1:拼接规范请求串 *************
+        $http_request_method = "POST";
+        $canonical_uri = "/";
+        $canonical_querystring = "";
+        $ct = "application/json; charset=utf-8";
+        $canonical_headers = "content-type:".$ct."\nhost:".$host."\nx-tc-action:".strtolower($action)."\n";
+        $signed_headers = "content-type;host;x-tc-action";
+        $hashed_request_payload = hash("sha256", $payload);
+        $canonical_request = "$http_request_method\n$canonical_uri\n$canonical_querystring\n$canonical_headers\n$signed_headers\n$hashed_request_payload";
+
+// ************* 步骤 2:拼接待签名字符串 *************
+        $credential_scope = "$date/$service/tc3_request";
+        $hashed_canonical_request = hash("sha256", $canonical_request);
+        $string_to_sign = "$algorithm\n$timestamp\n$credential_scope\n$hashed_canonical_request";
+
+// ************* 步骤 3:计算签名 *************
+        $secret_date    = hash_hmac("sha256", $date, "TC3".$secret_key, true);
+        $secret_service = hash_hmac("sha256", $service, $secret_date, true);
+        $secret_signing = hash_hmac("sha256", "tc3_request", $secret_service, true);
+        $signature      = hash_hmac("sha256", $string_to_sign, $secret_signing);
+
+// ************* 步骤 4:拼接 Authorization *************
+        $authorization = "$algorithm Credential=$secret_id/$credential_scope, SignedHeaders=$signed_headers, Signature=$signature";
+
+// ************* 步骤 5:构造并发起请求 *************
+        $headers = [
+            "Authorization"  => $authorization,
+            "Content-Type"   => "application/json; charset=utf-8",
+            "Host"           => $host,
+            "X-TC-Action"    => $action,
+            "X-TC-Timestamp" => $timestamp,
+            "X-TC-Version"   => $version
+        ];
+        if ($req_region) {
+            $headers["X-TC-Region"] = $req_region;
+        }
+        if ($token) {
+            $headers["X-TC-Token"] = $token;
+        }
+        $headers = array_map(function ($k, $v) { return "$k: $v"; }, array_keys($headers), $headers);
+
+        try {
+            $timeOut = 3;
+            $ch = curl_init();
+            curl_setopt($ch, CURLOPT_URL, $endpoint);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+            curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
+            curl_setopt($ch, CURLOPT_HEADER, 0);
+            curl_setopt($ch, CURLOPT_POST, 1);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+            $response = curl_exec($ch);
+            curl_close($ch);
+
+            //return $response;
+            $response = json_decode($response,true);
+            if(is_array($response) && isset($response['Response']['Products'][0]['Name'])){
+                $searchname = $response['Response']['Products'][0]['Name'];
+                if(!empty($searchname)){
+                    return $searchname;
+                }
+            }
+            return '';
+        } catch (Exception $err) {
+            //echo $err->getMessage();
+            return '';
+        }
+
+    }
+
+
     /**
      * @ApiTitle (收藏/取消)
      * @ApiSummary (收藏/取消)
@@ -180,7 +295,7 @@ class Product extends Base
      */
     public function favorite()
     {
-        $id = $this->request->get('id', 0);
+        $id = input('id', 0);
         $id = \addons\unishop\extend\Hashids::decodeHex($id);
 
         $user_id = $this->auth->id;
@@ -233,8 +348,8 @@ class Product extends Base
      */
     public function favoriteList()
     {
-        $page = $this->request->get('page', 1);
-        $pageSize = $this->request->get('pagesize', 20);
+        $page = input('page', 1);
+        $pageSize = input('pagesize', 20);
 
         $list = (new Favorite)->where(['user_id' => $this->auth->id])->with(['product'])->page($page, $pageSize)->select();
 
@@ -279,9 +394,9 @@ class Product extends Base
      */
     public function evaluate()
     {
-        $page = $this->request->get('page', 1);
-        $pageSize = $this->request->get('pagesize', 20);
-        $productId = $this->request->get('product_id');
+        $page = input('page', 1);
+        $pageSize = input('pagesize', 20);
+        $productId = input('product_id');
         $productId = \addons\unishop\extend\Hashids::decodeHex($productId);
 
         // 评价信息

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

@@ -36,6 +36,9 @@ class Product
                     if ($key) {
                         $data = $specItem[$key];
                     } else {
+                        $specItem['stock'] = intval($specItem['stock']);//数据类型
+                        $specItem['sales'] = intval($specItem['sales']);//数据类型
+
                         $data = $specItem;
                         $data['key'] = $k;
                     }

+ 2 - 1
addons/unishop/lang/zh-cn/order.php

@@ -7,7 +7,8 @@ return [
     'Product not exist' => '商品不存在',
 
     'Online'           => '在线支付',
-    'Offline'          => '到货付款',
+    'Offline'          => '钱包余额',
+    'Wallet'           => '钱包余额',
     'wxPay'            => '微信付款',
     'aliPay'           => '支付宝付',
     'Please fill in the refund amount'           => '请填写退款金额',

+ 1 - 0
addons/unishop/model/Config.php

@@ -50,6 +50,7 @@ class Config extends Model
      */
     public static function getImagesFullUrl($value = '')
     {
+        if(empty($value)) return $value;
         if (stripos($value, 'http') === 0 || $value === '' || stripos($value, 'data:image') === 0) {
             return $value;
         } else {

+ 22 - 8
addons/unishop/model/Order.php

@@ -46,7 +46,7 @@ class Order extends Model
     const STATUS_CANCEL = 0; // 用户取消订单
     const STATUS_REFUND = -1; // 申请售后
 
-    // 申请售后状态 0=无,1=申请中,2=通过(让用户发货),3=通过,4=拒绝
+    // 申请售后状态 0=无,1=申请中,2=通过(让用户发货)或无需退货,3=通过,4=拒绝
     const REFUND_STATUS_NONE = 0;
     const REFUND_STATUS_APPLY = 1;
     const REFUND_STATUS_DELIVERY = 2;
@@ -93,7 +93,7 @@ class Order extends Model
      */
     public function getPaidtimeAttr($value, $data)
     {
-        return $data['have_paid'] > 0 ? date('Y-m-d H:i:s', $data['have_paid']) : 0;
+        return $data['have_paid'] > 0 ? date('Y-m-d H:i:s', $data['have_paid']) : '';
     }
 
     /**
@@ -102,7 +102,7 @@ class Order extends Model
      */
     public function getDeliveredtimeAttr($value, $data)
     {
-        return $data['have_delivered'] > 0 ? date('Y-m-d H:i:s', $data['have_delivered']) : 0;
+        return $data['have_delivered'] > 0 ? date('Y-m-d H:i:s', $data['have_delivered']) : '';
     }
 
     /**
@@ -111,7 +111,7 @@ class Order extends Model
      */
     public function getReceivedtimeAttr($value, $data)
     {
-        return $data['have_received'] > 0 ? date('Y-m-d H:i:s', $data['have_received']) : 0;
+        return $data['have_received'] > 0 ? date('Y-m-d H:i:s', $data['have_received']) : '';
     }
 
     /**
@@ -120,7 +120,7 @@ class Order extends Model
      */
     public function getCommentedtimeAttr($value, $data)
     {
-        return $data['have_commented'] > 0 ? date('Y-m-d H:i:s', $data['have_commented']) : 0;
+        return $data['have_commented'] > 0 ? date('Y-m-d H:i:s', $data['have_commented']) : '';
     }
 
     /**
@@ -234,15 +234,28 @@ class Order extends Model
         $snowflake = new Snowflake();
         $id = $snowflake->id();
         // 优惠费用
-        $discountPrice = isset($coupon['value']) ? $coupon['value'] : 0;
+//        $discountPrice = isset($coupon['value']) ? $coupon['value'] : 0;
+        $discountPrice = 0;
         // 订单费用
         //$orderPrice;
         // 运费
-        $deliveryPrice = Delivery::algorithm($delivery, array_sum($numbers));
+//        $deliveryPrice = Delivery::algorithm($delivery, array_sum($numbers));
+        $deliveryPrice = '0';
+        foreach ($products as $product) {
+            $deliveryPrice = bcadd($deliveryPrice,$product['yunfei_price'],2);
+        }
+
         // 总费用
         $totalPrice = bcadd(bcsub($orderPrice, $discountPrice, 2), $deliveryPrice, 2);
 
         $out_trade_no = date('Ymd',time()).uniqid().$userId;
+
+        $db_pay_type = [
+            'wallet' => 2,
+            'wechat' => 3,
+            'alipay' => 4,
+        ];
+
         (new self)->save([
             'id' => $id,
             'user_id' => $userId,
@@ -251,6 +264,7 @@ class Order extends Model
             'discount_price' => $discountPrice,
             'delivery_price' => $deliveryPrice,
             'total_price' => $totalPrice,
+            'pay_type' => $db_pay_type[$data['pay_type']],
             'ip' => $_SERVER['REMOTE_ADDR'] ?? '',
             'remark' => $data['remark'] ?? '',
             'status' => self::STATUS_NORMAL,
@@ -261,7 +275,7 @@ class Order extends Model
             'order_id' => $id,
             'coupon_id' => $coupon ? $coupon['id'] : 0,
             'coupon_json' => json_encode($coupon),
-            'delivery_id' => $delivery['id'],
+            'delivery_id' => $delivery ? $delivery['id'] : 0,
             'delivery_json' => json_encode($delivery),
             'address_id' => $address['id'],
             'address_json' => json_encode($address),

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

@@ -57,6 +57,7 @@ class Product extends Model
         'real_look',
         'real_sales',
         'images',
+        'videothumb',
         'specList',
         'specTableList',
     ];
@@ -69,6 +70,18 @@ class Product extends Model
     public function getImageAttr($value) {
         return Config::getImagesFullUrl($value);
     }
+    public function getVideoFileAttr($value) {
+        return Config::getImagesFullUrl($value);
+    }
+    public function getVideothumbAttr($value, $data) {
+        $rs = '';
+        if(!empty($data['video_file'])){
+            $images_url = explode('.', $data['video_file']);
+            unset($images_url[count($images_url) - 1]);
+            $rs = join('.', $images_url) . '_0.jpg';
+        }
+        return Config::getImagesFullUrl($rs);
+    }
 
     /**
      * 加密商品id
@@ -122,7 +135,14 @@ class Product extends Model
     public function getSpecTableListAttr($value, $data) {
         $specs = !empty($data['specTableList']) ? json_decode($data['specTableList'], true) : [];
         foreach ($specs as &$spec) {
+            unset($spec['code']);
+
             $spec['image'] = Config::getImagesFullUrl($spec['image']);
+
+            $spec['value_text'] = '';
+            if(!empty($spec['value'])){
+                $spec['value_text'] = implode(',',$spec['value']);
+            }
         }
         return $specs;
     }
@@ -155,6 +175,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;
     }
 

+ 8 - 8
addons/unishop/validate/Address.php

@@ -21,9 +21,9 @@ class Address extends Validate
         'mobile' => 'require|number|max:20',
         'address' => 'require|max:255',
         'is_default' => 'integer',
-        'province_id' => 'require',
-        'city_id' => 'require',
-        'area_id' => 'require',
+//        'province_id' => 'require',
+//        'city_id' => 'require',
+//        'area_id' => 'require',
     ];
 
     /**
@@ -38,17 +38,17 @@ class Address extends Validate
         'address.required' => '地址不能为空',
         'address.max' => '地址不能超过255字',
         'is_default.integer' => '默认地址格式不对',
-        'province_id.require' => '请选择省份',
-        'city_id.require' => '请选择城市',
-        'area_id.require' => '请选择地区',
+//        'province_id.require' => '请选择省份',
+//        'city_id.require' => '请选择城市',
+//        'area_id.require' => '请选择地区',
     ];
 
     /**
      * 验证场景
      */
     protected $scene = [
-        'add'  => ['name', 'mobile', 'address', 'is_default', 'province_id', 'city_id', 'area_id'],
-        'edit' => ['id', 'name', 'mobile', 'address', 'is_default', 'province_id', 'city_id', 'area_id'],
+        'add'  => ['name', 'mobile', 'address', 'is_default'/*, 'province_id', 'city_id', 'area_id'*/],
+        'edit' => ['id', 'name', 'mobile', 'address', 'is_default'/*, 'province_id', 'city_id', 'area_id'*/],
     ];
 
 }

+ 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'], // 秒杀创建订单
     ];
 
 }