diff --git a/app/common/dao/store/order/StoreCartDao.php b/app/common/dao/store/order/StoreCartDao.php index 0880d239..3b15391f 100644 --- a/app/common/dao/store/order/StoreCartDao.php +++ b/app/common/dao/store/order/StoreCartDao.php @@ -64,7 +64,7 @@ class StoreCartDao extends BaseDao */ public function getAll(int $uid) { - $query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0]) + $query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0,'is_dg'=>0]) ->with([ 'product' => function ($query) { $query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type'); diff --git a/app/common/dao/store/order/StoreCartDaoDg.php b/app/common/dao/store/order/StoreCartDaoDg.php index 5519eb8a..5114f758 100644 --- a/app/common/dao/store/order/StoreCartDaoDg.php +++ b/app/common/dao/store/order/StoreCartDaoDg.php @@ -16,7 +16,7 @@ namespace app\common\dao\store\order; use app\common\dao\BaseDao; use app\common\model\BaseModel; -use app\common\model\store\order\StoreCartDg as StoreCart; +use app\common\model\store\order\StoreCart; use app\common\model\user\UserAddress; use think\Collection; use think\db\exception\DataNotFoundException; @@ -64,7 +64,7 @@ class StoreCartDaoDg extends BaseDao */ public function getAll(int $uid) { - $query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0]) + $query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'is_dg' => 1, 'is_save' => 0]) ->with([ 'product' => function ($query) { $query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type'); @@ -139,7 +139,7 @@ class StoreCartDaoDg extends BaseDao */ public function getCartCount(int $uid) { - $data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0])->field('SUM(cart_num) as count')->select(); + $data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'is_dg' => 1, 'is_save' => 0])->field('SUM(cart_num) as count')->select(); $data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0; return $data; } diff --git a/app/common/repositories/store/product/ProductDgRepository.php b/app/common/repositories/store/product/ProductDgRepository.php index d4031cd9..2d0362ea 100644 --- a/app/common/repositories/store/product/ProductDgRepository.php +++ b/app/common/repositories/store/product/ProductDgRepository.php @@ -1819,6 +1819,8 @@ class ProductDgRepository extends BaseRepository 'is_del' => 0, 'is_new' => 0, 'is_fail' => 0, + 'is_dg' => 1, + 'is_save' => 0, 'product_type' => 0, 'product_id' => $productId, 'uid' => $uid, diff --git a/app/controller/api/store/order/StoreCartDg.php b/app/controller/api/store/order/StoreCartDg.php index 7b6283ef..2d2b31df 100644 --- a/app/controller/api/store/order/StoreCartDg.php +++ b/app/controller/api/store/order/StoreCartDg.php @@ -19,12 +19,11 @@ use app\common\repositories\store\product\ProductAttrValueRepository; use app\common\repositories\store\product\ProductGroupRepository; use app\common\repositories\store\product\ProductPresellRepository; use app\common\repositories\store\product\ProductRepository; +use app\common\repositories\store\product\ProductDgRepository; use app\common\repositories\store\product\StoreDiscountProductRepository; use app\common\repositories\store\product\StoreDiscountRepository; use app\common\repositories\store\StoreSeckillActiveRepository; use app\common\repositories\user\UserRepository; -use app\common\repositories\store\product\ProductDgRepository; - use MongoDB\BSON\MaxKey; use think\App; use think\facade\Db; @@ -125,6 +124,7 @@ class StoreCartDg extends BaseController //添加购物车 $data['uid'] = $this->request->uid(); $data['mer_id'] = $result['product']['mer_id']; + $data['is_dg'] = 1; $cart = $storeCart = $this->repository->create($data); } event('user.cart', compact('user','storeCart')); @@ -215,9 +215,9 @@ class StoreCartDg extends BaseController } // 删除购物车里数据 $where[] = ['cart_id','in',$params['cart_ids']]; - $data['is_del'] = 1; + $data['is_save'] = 1; $data['nopay_id'] = $nopay_id; - Db::table('eb_store_cart_dg')->where($where)->update($data); + Db::table('eb_store_cart')->where($where)->update($data); Db::commit(); return app('json')->success('保存成功'); } catch (Exception $e) { @@ -240,7 +240,7 @@ class StoreCartDg extends BaseController $where['b.status'] = 0; $where['a.uid'] = $this->request->uid(); $data['b.status'] = 1; - Db::table('eb_store_cart_dg')->alias('a') + Db::table('eb_store_cart')->alias('a') ->join('eb_store_cart_dg_nopay b','a.nopay_id = b.id') ->where($where) ->update($data); @@ -252,7 +252,18 @@ class StoreCartDg extends BaseController ->page($page,$limit) ->withAttr('goods',function ($value,$data){ $www[] = ['a.cart_id','in',$data['cart_ids']]; - return Db::table('eb_store_cart_dg')->alias('a')->join('eb_store_product b','a.product_id = b.product_id')->field('a.cart_num,b.product_id,b.store_name,b.price')->where($www)->select(); + $goods = Db::table('eb_store_cart')->alias('a')->join('eb_store_product b','a.product_id = b.product_id')->field("a.cart_num,b.product_id,b.store_name,b.price")->where($www)->select(); + return $goods; + }) + ->withAttr('total',function ($value,$data){ + $www2[] = ['a.cart_id','in',$data['cart_ids']]; + $goods = Db::table('eb_store_cart')->alias('a')->join('eb_store_product b','a.product_id = b.product_id')->field("sum(a.cart_num) as total")->where($www2)->find(); + return $goods['total']; + }) + ->withAttr('total_price',function ($value,$data){ + $www3[] = ['a.cart_id','in',$data['cart_ids']]; + $goods = Db::table('eb_store_cart')->alias('a')->join('eb_store_product b','a.product_id = b.product_id')->field("sum(b.price) as total_price")->where($www3)->find(); + return $goods['total_price']; }) ->select(); if($list){