更新
This commit is contained in:
parent
c47567239b
commit
70e8df79ff
@ -9,6 +9,7 @@ use app\common\model\order\Cart;
|
|||||||
use app\common\model\retail\Cashierclass;
|
use app\common\model\retail\Cashierclass;
|
||||||
use app\common\lists\ListsExtendInterface;
|
use app\common\lists\ListsExtendInterface;
|
||||||
use app\common\model\goods\Goods;
|
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;
|
$userId = $this->request->userId;
|
||||||
if (!$userId) return [];
|
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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['cart_id' => 'desc'])
|
->order(['cart_id' => 'desc'])
|
||||||
->select()->each(function ($item) {
|
->select()->each(function ($item) {
|
||||||
@ -55,9 +60,16 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
|
|
||||||
$total_price = 0;
|
$total_price = 0;
|
||||||
foreach ($list as $key => &$item) {
|
foreach ($list as $key => &$item) {
|
||||||
$sell = Goods::where('id', $item['goods_id'])->value('sell');
|
$find = Goods::where(['id' => $item['goods_id']])->field('name,imgs,unit,sell')->find();
|
||||||
$item['goods_total_price'] = bcmul($item['cart_num'], $sell, 2);
|
if($find){
|
||||||
|
$item['goods_total_price'] = bcmul($item['cart_num'], $find['sell'], 2);
|
||||||
$total_price += $item['goods_total_price'];
|
$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;
|
$this->total_price=$total_price;
|
||||||
return $list;
|
return $list;
|
||||||
@ -71,7 +83,13 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
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()
|
public function extend()
|
||||||
|
@ -41,6 +41,7 @@ class UserAddressList extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
$user_id=$this->request->userId;
|
$user_id=$this->request->userId;
|
||||||
if(!$user_id) return [];
|
if(!$user_id) return [];
|
||||||
return UserAddress::where($this->searchWhere)->where('uid',$user_id)
|
return UserAddress::where($this->searchWhere)->where('uid',$user_id)
|
||||||
|
->field('address_id,real_name,detail,phone,is_default')
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['address_id' => 'desc'])
|
->order(['address_id' => 'desc'])
|
||||||
->select()
|
->select()
|
||||||
|
@ -4,6 +4,7 @@ namespace app\api\logic\order;
|
|||||||
|
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\model\goods\Goods;
|
use app\common\model\goods\Goods;
|
||||||
|
use app\common\model\goods\Unit;
|
||||||
use app\common\model\merchat\Merchant;
|
use app\common\model\merchat\Merchant;
|
||||||
use app\common\model\opurchase\Opurchaseclass;
|
use app\common\model\opurchase\Opurchaseclass;
|
||||||
use app\common\model\opurchase\Opurchaseinfo;
|
use app\common\model\opurchase\Opurchaseinfo;
|
||||||
@ -36,16 +37,23 @@ class OrderLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
/** 计算价格 */
|
/** 计算价格 */
|
||||||
foreach ($cart_select as $k => $v) {
|
foreach ($cart_select as $k => $v) {
|
||||||
$sell = Goods::where(['id' => $v['goods']])->value('sell');
|
$find = Goods::where(['id' => $v['goods']])->field('name,imgs,unit,sell')->find();
|
||||||
$cart_select[$k]['total'] = bcmul($v['cart_num'], $sell, 2);
|
if(!$find){
|
||||||
$cart_select[$k]['price'] = $sell;
|
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 = [
|
$order = [
|
||||||
'time' => time(),
|
'time' => time(),
|
||||||
'number' => static::getNewOrderId('PF'),
|
'number' => static::getNewOrderId('PF'),
|
||||||
'total' => array_sum(array_column($cart_select, 'total')),
|
'total' => array_sum(array_column($cart_select, 'total')),
|
||||||
'pay_type' => $params['pay_type'] ?? 0,
|
'pay_type' => $params['pay_type'] ?? 0,
|
||||||
'cart_id' => implode(',', $cartId)
|
'cart_id' => implode(',', $cartId),
|
||||||
|
'delivery_msg'=>' 预计48小时发货 '
|
||||||
];
|
];
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
|
@ -26,11 +26,15 @@ class AddressLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
|
if($params['is_default']==1){
|
||||||
|
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
|
||||||
|
}
|
||||||
UserAddress::create([
|
UserAddress::create([
|
||||||
'uid' => $params['uid'],
|
'uid' => $params['uid'],
|
||||||
'real_name' => $params['real_name'],
|
'real_name' => $params['real_name'],
|
||||||
'phone' => $params['phone'],
|
'phone' => $params['phone'],
|
||||||
'detail' => $params['detail'],
|
'detail' => $params['detail'],
|
||||||
|
'is_default' => $params['is_default'],
|
||||||
]);
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
@ -53,10 +57,14 @@ class AddressLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
|
if($params['is_default']==1){
|
||||||
|
UserAddress::where('uid',$params['uid'])->update(['is_default'=>0]);
|
||||||
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'real_name' => $params['real_name'],
|
'real_name' => $params['real_name'],
|
||||||
'phone' => $params['phone'],
|
'phone' => $params['phone'],
|
||||||
'detail' => $params['detail'],
|
'detail' => $params['detail'],
|
||||||
|
'is_default' => $params['is_default'],
|
||||||
];
|
];
|
||||||
UserAddress::where('uid', $params['uid'])->where('address_id', $params['address_id'])->update($data);
|
UserAddress::where('uid', $params['uid'])->where('address_id', $params['address_id'])->update($data);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
@ -91,6 +99,6 @@ class AddressLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ class UserAddressValidate extends BaseValidate
|
|||||||
'phone' => 'require',
|
'phone' => 'require',
|
||||||
'detail' => 'require',
|
'detail' => 'require',
|
||||||
'address_id' => 'require',
|
'address_id' => 'require',
|
||||||
|
"is_default"=>"require|in:0,1"
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -37,6 +38,9 @@ class UserAddressValidate extends BaseValidate
|
|||||||
'phone' => '收货人电话',
|
'phone' => '收货人电话',
|
||||||
'detail' => '收货人详细地址',
|
'detail' => '收货人详细地址',
|
||||||
'address_id' => '地址id',
|
'address_id' => '地址id',
|
||||||
|
"is_default"=>"默认地址"
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user