| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\common\model;
- use app\api\services\UserServices;
- use app\common\model\TimeModel;
- //use app\model\RedPoolModel;
- //use app\model\RedStorePoolModel;
- use app\common\model\UserDataModel;
- use think\Exception;
- use think\facade\Db;
- use think\Model;
- class ShopCartModel extends Model
- {
- protected $name = "shop_cart";
- // 购物车列表
- public function cartList($uid){
- $list = self::alias('c')
- ->where('c.uid', $uid)
- ->where('c.is_del', 0)
- ->leftJoin('shop_goods g', 'c.goods_id = g.goods_id')
- ->rightJoin('shop_goods_spec_relation r', 'c.goods_id = r.goods_id')
- ->field('c.id,c.goods_id,c.num,g.goods_name,g.goods_sn,g.goods_img,g.rebate_score,g.created_time,g.price,g.spec_name,r.spec_id')
- ->order('c.create_time desc')
- ->select()->toArray();
- return $list;
- }
- // 编辑购物车数量
- public function editCart($uid, $cart_id, $num){
- self::where('id', $cart_id)->where('uid', $uid)->save([
- 'num'=>$num
- ]);
- }
- // 添加到购物车
- public function addCart($uid, $goods_id, $num){
- if ($info = self::where('uid', $uid)->where('goods_id', $goods_id)->find()){
- self::where('id', $info['id'])->save(['create_time'=>sr_getcurtime(time()), 'num'=>$info['num']+$num]);
- }else{
- self::insert([
- 'goods_id'=>$goods_id,
- 'uid'=>$uid,
- 'create_time'=>sr_getcurtime(time()),
- 'num'=>$num
- ]);
- }
- }
- // 删除购物车
- public function delCart($uid, $cart_ids){
- self::where('id', 'in', $cart_ids)->delete();
- }
- }
|