购物车相关
This commit is contained in:
parent
c289e53e1c
commit
7e4e845e44
@ -20,8 +20,8 @@ class CartController extends BaseApiController
|
|||||||
public function create(){
|
public function create(){
|
||||||
$params = (new CartValidate())->post()->goCheck('add');
|
$params = (new CartValidate())->post()->goCheck('add');
|
||||||
$params['uid']=$this->request->userId;
|
$params['uid']=$this->request->userId;
|
||||||
$result=Cart::where(['uid'=>$params['uid'],'product_attr_unique'=>$params['product_attr_unique'],'is_fail'=>0,'is_del'=>0])->find();
|
$result=Cart::where(['uid'=>$params['uid'],'store_id'=>$params['store_id'],'product_id'=>$params['product_id'],'is_fail'=>0,'delete_time'=>null])->find();
|
||||||
$count=Cart::where(['uid'=>$params['uid'],'is_del'=>0,'is_pay'=>0])->count();
|
$count=Cart::where(['uid'=>$params['uid'],'delete_time'=>null,'is_pay'=>0])->count();
|
||||||
if($count>100){
|
if($count>100){
|
||||||
return $this->fail('购物车商品不能大于100个,请先结算');
|
return $this->fail('购物车商品不能大于100个,请先结算');
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ use app\admin\lists\BaseAdminDataLists;
|
|||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use app\common\model\order\Cart;
|
use app\common\model\order\Cart;
|
||||||
use app\common\lists\ListsExtendInterface;
|
use app\common\lists\ListsExtendInterface;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||||
use app\common\model\store_product_unit\StoreProductUnit;
|
use app\common\model\store_product_unit\StoreProductUnit;
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
];
|
];
|
||||||
$list = Cart::where($this->searchWhere)->where($where)
|
$list = Cart::where($this->searchWhere)->where($where)
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['cart_id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function ($item) {
|
->select()->each(function ($item) {
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
@ -58,15 +59,14 @@ class CartList extends BaseAdminDataLists implements ListsSearchInterface, Lists
|
|||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
foreach ($list as $key => &$item) {
|
foreach ($list as $key => &$item) {
|
||||||
$find = StoreProductAttrValue::where('unique',$item['product_attr_unique'])
|
$find = StoreBranchProduct::where(['store_id'=>$item['store_id'],'product_id'=>$item['product_id']])
|
||||||
->field('product_id,image,purchase')
|
->field('product_id,image,price,store_name,unit')
|
||||||
->with(['storeName'])
|
|
||||||
->find();
|
->find();
|
||||||
if($find){
|
if($find){
|
||||||
$item['goods_total_price'] = bcmul($item['cart_num'], $find['purchase'], 2);
|
$item['goods_total_price'] = bcmul($item['cart_num'], $find['price'], 2);
|
||||||
$this->total_price=bcadd($this->total_price,$item['goods_total_price'],2);
|
$this->total_price=bcadd($this->total_price,$item['goods_total_price'],2);
|
||||||
$item['imgs'] = $find['image'];
|
$item['imgs'] = $find['image'];
|
||||||
$item['sell'] = $find['purchase'];
|
$item['sell'] = $find['price'];
|
||||||
$item['goods_name'] = $find['store_name'];
|
$item['goods_name'] = $find['store_name'];
|
||||||
$item['unit_name'] = StoreProductUnit::where('id',$find['unit'])->value('name');
|
$item['unit_name'] = StoreProductUnit::where('id',$find['unit'])->value('name');
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ class CartLogic extends BaseLogic
|
|||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'store_id' => $params['store_id']??0,
|
'store_id' => $params['store_id']??0,
|
||||||
'staff_id' => $params['staff_id']??0,
|
'staff_id' => $params['staff_id']??0,
|
||||||
'product_attr_unique' => $params['product_attr_unique'],
|
'product_attr_unique' => '',
|
||||||
'cart_num' => $params['cart_num'],
|
'cart_num' => $params['cart_num'],
|
||||||
'add_time' => \Qiniu\time(),
|
'add_time' => time(),
|
||||||
'is_new' => $params['is_new']??0,
|
'is_new' => $params['is_new']??0,
|
||||||
]);
|
]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
@ -60,7 +60,10 @@ class CartLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Cart::where(['uid'=>$params['uid'],'product_id'=>$params['product_id']])->update(['cart_num'=>$params['cart_num']]);
|
Cart::where(['uid'=>$params['uid'],
|
||||||
|
'store_id'=>$params['store_id'],
|
||||||
|
'product_id'=>$params['product_id']])
|
||||||
|
->update(['cart_num'=>$params['cart_num']]);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -48,7 +48,7 @@ class CartValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->only(['cart_num','product_attr_unique','store_id','product_id']);
|
return $this->only(['cart_num','store_id','product_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -58,9 +58,9 @@ class CartValidate extends BaseValidate
|
|||||||
* @author likeadmin
|
* @author likeadmin
|
||||||
* @date 2024/04/24 10:37
|
* @date 2024/04/24 10:37
|
||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneChange()
|
||||||
{
|
{
|
||||||
return $this->only(['']);
|
return $this->only(['cart_num','store_id','product_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class CartValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneDelete()
|
public function sceneDelete()
|
||||||
{
|
{
|
||||||
return $this->only(['']);
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -360,3 +360,24 @@ if (!function_exists('generateUniqueVerificationCode')) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('haversineDistance')) {
|
||||||
|
function haversineDistance($latitude1, $longitude1, $latitude2, $longitude2) {
|
||||||
|
$earthRadius = 6371; // 地球平均半径,单位是千米
|
||||||
|
|
||||||
|
// 将角度转换为弧度
|
||||||
|
$latFrom = deg2rad($latitude1);
|
||||||
|
$lonFrom = deg2rad($longitude1);
|
||||||
|
$latTo = deg2rad($latitude2);
|
||||||
|
$lonTo = deg2rad($longitude2);
|
||||||
|
|
||||||
|
$latDelta = $latTo - $latFrom;
|
||||||
|
$lonDelta = $lonTo - $lonFrom;
|
||||||
|
|
||||||
|
$angle = 2 * asin(sqrt(pow(sin($latDelta / 2), 2) +
|
||||||
|
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)));
|
||||||
|
return $angle * $earthRadius;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user