| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace app\common\cart;
- use app\common\BaseRepository;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\Log;
- class CartRepository extends BaseRepository
- {
- /**
- * TODO 商品检测
- * @param $data
- * @return array
- */
- public function checkProduct($data): array
- {
- if( $data['cart_num'] < 0 ) return $this -> getMessage(101);
- $productSelect = Db::query("select * from `rrx_store_product` where `product_id`=? limit 1", [$data['product_id']]);
- if(!$productSelect) return $this -> getMessage(102);
- $product = $productSelect[0];
- $skuSelect = Db::query("select * from `rrx_store_product_attr_value` where `unique`=? and `product_id`=? limit 1", [$data['product_attr_unique'],$data['product_id']]);
- $sku = $skuSelect[0];
- if(!$sku) return $this -> getMessage(103);
- if($sku['product_id'] != $data['product_id']) return $this -> getMessage(104);
- //积分
- if(isset($product['mer_id']) && $product['mer_id'] == '148' && !$data['is_new']) return $this -> getMessage(105);
- //秒杀
- $nowTime = date("Y-m-d H:00:00");//当前小时
- $seckill = Db::query("select * from `rrx_product_seckill` where `seckill_date`=? and `product_id`=? and `status`=1 limit 1",[$nowTime,$data['product_id']]);
- if($seckill && !$data['is_new']) return $this -> getMessage(105);
- return ['product' => $product,'sku' => $sku];
- }
- /**
- * TODO 购物车检测
- * @param $uid
- * @param $product_attr_unique
- * @return array|boolean
- */
- public function checkCart($uid,$product_attr_unique){
- // ['is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid,'product_type' => 0,'product_attr_unique' => $sku];
- $cartSelect = Db::query("select * from `rrx_store_cart` where `is_del`=? and `is_fail`=? and `is_new`=?
- and `is_pay`=? and `uid`=? and `product_type`=? and `product_attr_unique`=? limit 1",
- [0,0,0,0,$uid,0,$product_attr_unique]);
- if($cartSelect) return $cartSelect[0];
- return false;
- }
- /**
- * TODO 购物车数量修改
- * @param $cart_id
- * @param $cart_num
- */
- public function updateCart($cart_id,$cart_num){
- try {
- Db::query("UPDATE `rrx_store_cart` SET `cart_num`=? WHERE `cart_id`=?",[$cart_num,$cart_id]);
- }catch (\Exception $e){
- log::error(parseException($e));
- return $this -> getMessage(108);
- }
- }
- /**
- * TODO 商品检测
- * @param $data
- * @return array
- */
- public function createCart($data){
- try {
- Db::query("INSERT INTO `rrx_store_cart` SET
- `product_id`=?,
- `product_attr_unique`=?,
- `cart_num`=?,
- `is_new`=?,
- `uid`=?,
- `mer_id`=?,
- `create_time`=?",
- [$data['product_id'],$data['product_attr_unique'],$data['cart_num'],$data['is_new'],$data['uid'],$data['mer_id'],date("Y-m-d H:i:s")]);
- //返回购物车ID
- $cartId = Db::query("SELECT LAST_INSERT_ID()");
- return ['cart_id'=>$cartId[0]['LAST_INSERT_ID()']];
- }catch (\Exception $e){
- log::error(parseException($e));
- return $this -> getMessage(107);
- }
- }
- /**
- * TODO 获取单个购物车详情
- * @param $cartId
- * @param $uid
- * @return array
- */
- public function getOne($cartId,$uid){
- //'is_del'=>0,'is_fail'=>0,'is_new'=>0,'is_pay'=>0,'uid' => $uid];
- $cartSelect = Db::query("select * from `rrx_store_cart` where `uid`=? and `cart_id`=? limit 1",[$uid,$cartId]);
- if(!$cartSelect) return $this -> getMessage(109);
- return $cartSelect[0];
- }
- /**
- * TODO 获取购物车列表
- * @param $uid
- * @return array
- */
- public function getListFromUid($uid){
- //SELECT * FROM `rrx_store_product` `rsp` INNER JOIN `rrx_store_product_attr_value` `rspav` ON `rsp`.`product_id`=`rspav`.`product_id` WHERE `rsp`.`product_id` = '434' AND `rspav`.`unique` = 'f53eccfdd090' LIMIT 1
- $list = Db::query("select * from `rrx_store_cart` `rsc`
- INNER JOIN `rrx_store_product_attr` `rspa` on `rsc`.``
- where
- `uid`=? and
- `is_del`=? and
- `is_new`=? and
- `is_pay`=?"
- ,[$uid,0,0,0]);
- $this -> formatCartList($list);
- return [];
- }
- //购物车列表格式化
- public function formatCartList(&$list){
- dump($list);
- // foreach
- }
- }
|