diff --git a/app/api/lists/order/CartList.php b/app/api/lists/order/CartList.php index 359e402..29d61ef 100644 --- a/app/api/lists/order/CartList.php +++ b/app/api/lists/order/CartList.php @@ -9,6 +9,7 @@ use app\common\model\order\Cart; use app\common\model\retail\Cashierclass; use app\common\lists\ListsExtendInterface; use app\common\model\goods\Goods; +use app\common\model\goods\Unit; /** * 购物车列表 @@ -44,7 +45,11 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists { $userId = $this->request->userId; if (!$userId) return []; - $list = Cart::where($this->searchWhere)->where('uid', $userId) + $where=[ + 'uid'=>$userId, + 'is_pay'=>0 + ]; + $list = Cart::where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) ->order(['cart_id' => 'desc']) ->select()->each(function ($item) { @@ -55,9 +60,16 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists $total_price = 0; foreach ($list as $key => &$item) { - $sell = Goods::where('id', $item['goods_id'])->value('sell'); - $item['goods_total_price'] = bcmul($item['cart_num'], $sell, 2); - $total_price += $item['goods_total_price']; + $find = Goods::where(['id' => $item['goods_id']])->field('name,imgs,unit,sell')->find(); + if($find){ + $item['goods_total_price'] = bcmul($item['cart_num'], $find['sell'], 2); + $total_price += $item['goods_total_price']; + $item['goods_name'] = $find['name']; + $item['imgs'] = $find['imgs']; + $item['sell'] = $find['sell']; + $item['unit_name'] = Unit::where('id',$find['unit'])->value('name'); + } + } $this->total_price=$total_price; return $list; @@ -71,7 +83,13 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists */ public function count(): int { - return Cart::where($this->searchWhere)->count(); + $userId = $this->request->userId; + if (!$userId) return 0; + $where=[ + 'uid'=>$userId, + 'is_pay'=>0 + ]; + return Cart::where($this->searchWhere)->where($where)->count(); } public function extend() diff --git a/app/api/lists/user/UserAddressList.php b/app/api/lists/user/UserAddressList.php index b7e4b66..b6bacad 100644 --- a/app/api/lists/user/UserAddressList.php +++ b/app/api/lists/user/UserAddressList.php @@ -41,6 +41,7 @@ class UserAddressList extends BaseAdminDataLists implements ListsSearchInterface $user_id=$this->request->userId; if(!$user_id) return []; return UserAddress::where($this->searchWhere)->where('uid',$user_id) + ->field('address_id,real_name,detail,phone,is_default') ->limit($this->limitOffset, $this->limitLength) ->order(['address_id' => 'desc']) ->select() diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index 512aa13..beff21b 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -4,6 +4,7 @@ namespace app\api\logic\order; use app\common\logic\BaseLogic; use app\common\model\goods\Goods; +use app\common\model\goods\Unit; use app\common\model\merchat\Merchant; use app\common\model\opurchase\Opurchaseclass; use app\common\model\opurchase\Opurchaseinfo; @@ -36,16 +37,23 @@ class OrderLogic extends BaseLogic try { /** 计算价格 */ foreach ($cart_select as $k => $v) { - $sell = Goods::where(['id' => $v['goods']])->value('sell'); - $cart_select[$k]['total'] = bcmul($v['cart_num'], $sell, 2); - $cart_select[$k]['price'] = $sell; + $find = Goods::where(['id' => $v['goods']])->field('name,imgs,unit,sell')->find(); + if(!$find){ + continue; + } + $cart_select[$k]['total'] = bcmul($v['cart_num'], $find['sell'], 2); + $cart_select[$k]['price'] = $find['sell']; + $cart_select[$k]['name'] = $find['name']; + $cart_select[$k]['imgs'] = $find['imgs']; + $cart_select[$k]['unit_name'] = Unit::where(['id' => $find['unit']])->value('name'); } $order = [ 'time' => time(), 'number' => static::getNewOrderId('PF'), 'total' => array_sum(array_column($cart_select, 'total')), 'pay_type' => $params['pay_type'] ?? 0, - 'cart_id' => implode(',', $cartId) + 'cart_id' => implode(',', $cartId), + 'delivery_msg'=>' 预计48小时发货 ' ]; } catch (\Exception $e) { self::setError($e->getMessage()); diff --git a/app/api/logic/user/AddressLogic.php b/app/api/logic/user/AddressLogic.php index c115d2c..fc52f81 100644 --- a/app/api/logic/user/AddressLogic.php +++ b/app/api/logic/user/AddressLogic.php @@ -26,11 +26,15 @@ class AddressLogic extends BaseLogic { Db::startTrans(); try { + if($params['is_default']==1){ + UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]); + } UserAddress::create([ 'uid' => $params['uid'], 'real_name' => $params['real_name'], 'phone' => $params['phone'], 'detail' => $params['detail'], + 'is_default' => $params['is_default'], ]); Db::commit(); return true; @@ -53,10 +57,14 @@ class AddressLogic extends BaseLogic { Db::startTrans(); try { + if($params['is_default']==1){ + UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]); + } $data = [ 'real_name' => $params['real_name'], 'phone' => $params['phone'], 'detail' => $params['detail'], + 'is_default' => $params['is_default'], ]; UserAddress::where('uid', $params['uid'])->where('address_id', $params['address_id'])->update($data); Db::commit(); @@ -91,6 +99,6 @@ class AddressLogic extends BaseLogic */ public static function detail($params): array { - return UserAddress::field('address_id,real_name,phone,detail')->findOrEmpty($params['address_id'])->toArray(); + return UserAddress::field('address_id,real_name,phone,detail,is_default')->findOrEmpty($params['address_id'])->toArray(); } } diff --git a/app/api/validate/UserAddressValidate.php b/app/api/validate/UserAddressValidate.php index d67cd49..998b625 100644 --- a/app/api/validate/UserAddressValidate.php +++ b/app/api/validate/UserAddressValidate.php @@ -23,6 +23,7 @@ class UserAddressValidate extends BaseValidate 'phone' => 'require', 'detail' => 'require', 'address_id' => 'require', + "is_default"=>"require|in:0,1" ]; @@ -37,6 +38,9 @@ class UserAddressValidate extends BaseValidate 'phone' => '收货人电话', 'detail' => '收货人详细地址', 'address_id' => '地址id', + "is_default"=>"默认地址" + + ]; ];