mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-17 15:02:48 +00:00
删除多余文件
This commit is contained in:
parent
893c912567
commit
8703f051c5
@ -1,159 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author: xaboy<365615158@qq.com>
|
|
||||||
* @day: 2017/12/18
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace app\routine\model\store;
|
|
||||||
|
|
||||||
use basic\ModelBasic;
|
|
||||||
use traits\ModelTrait;
|
|
||||||
|
|
||||||
class StoreBargain extends ModelBasic
|
|
||||||
{
|
|
||||||
use ModelTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 正在开启的砍价活动
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public static function validWhere($status = 1){
|
|
||||||
return self::where('is_del',0)->where('status',$status)->where('start_time','LT',time())->where('stop_time','GT',time());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断砍价产品是否开启
|
|
||||||
* @param int $bargainId
|
|
||||||
* @return int|string
|
|
||||||
*/
|
|
||||||
public static function validBargain($bargainId = 0){
|
|
||||||
$model = self::validWhere();
|
|
||||||
return $model->where('id',$bargainId)->count();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 获取正在进行中的砍价产品
|
|
||||||
* @param string $field
|
|
||||||
*/
|
|
||||||
public static function getList($field = 'id,product_id,title,price,min_price,image'){
|
|
||||||
$model = self::validWhere();
|
|
||||||
$list = $model->field($field)->select();
|
|
||||||
if($list) return $list->toArray();
|
|
||||||
else return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取一条正在进行中的砍价产品
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param string $field
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getBargainTerm($bargainId = 0,$field = 'id,product_id,bargain_num,num,unit_name,image,title,price,min_price,image,description,start_time,stop_time,rule'){
|
|
||||||
if(!$bargainId) return [];
|
|
||||||
$model = self::validWhere();
|
|
||||||
$bargain = $model->field($field)->where('id',$bargainId)->find();
|
|
||||||
if($bargain) return $bargain->toArray();
|
|
||||||
else return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取一条砍价产品
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param string $field
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getBargain($bargainId = 0,$field = 'id,product_id,title,price,min_price,image'){
|
|
||||||
if(!$bargainId) return [];
|
|
||||||
$model = new self();
|
|
||||||
$bargain = $model->field($field)->where('id',$bargainId)->find();
|
|
||||||
if($bargain) return $bargain->toArray();
|
|
||||||
else return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最高价和最低价
|
|
||||||
* @param int $bargainId
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getBargainMaxMinPrice($bargainId = 0){
|
|
||||||
if(!$bargainId) return [];
|
|
||||||
return self::where('id',$bargainId)->field('bargain_min_price,bargain_max_price')->find()->toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取砍价次数
|
|
||||||
* @param int $bargainId
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getBargainNum($bargainId = 0){
|
|
||||||
return self::where('id',$bargainId)->value('bargain_num');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断当前砍价是否活动进行中
|
|
||||||
* @param int $bargainId
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function setBargainStatus($bargainId = 0){
|
|
||||||
$model = self::validWhere();
|
|
||||||
$count = $model->where('id',$bargainId)->count();
|
|
||||||
if($count) return true;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取库存
|
|
||||||
* @param int $bargainId
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getBargainStock($bargainId = 0){
|
|
||||||
return self::where('id',$bargainId)->value('stock');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 修改销量和库存
|
|
||||||
* @param $num
|
|
||||||
* @param $CombinationId
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function decBargainStock($num,$bargainId)
|
|
||||||
{
|
|
||||||
$res = false !== self::where('id',$bargainId)->dec('stock',$num)->inc('sales',$num)->update();
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有砍价产品的浏览量
|
|
||||||
* @return array|false|\PDOStatement|string|\think\Model
|
|
||||||
*/
|
|
||||||
public static function getBargainLook(){
|
|
||||||
return self::field('sum(look) as look')->find();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有砍价产品的分享量
|
|
||||||
* @return array|false|\PDOStatement|string|\think\Model
|
|
||||||
*/
|
|
||||||
public static function getBargainShare(){
|
|
||||||
return self::field('sum(share) as share')->find();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加砍价产品分享次数
|
|
||||||
* @param int $id
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function addBargainShare($id = 0){
|
|
||||||
if(!$id) return false;
|
|
||||||
return self::where('id',$id)->inc('share',1)->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加砍价产品浏览次数
|
|
||||||
* @param int $id
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function addBargainLook($id = 0){
|
|
||||||
if(!$id) return false;
|
|
||||||
return self::where('id',$id)->inc('look',1)->update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,141 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\routine\model\store;
|
|
||||||
|
|
||||||
use app\routine\model\user\User;
|
|
||||||
use basic\ModelBasic;
|
|
||||||
use traits\ModelTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 参与砍价Model
|
|
||||||
* Class StoreBargainUser
|
|
||||||
* @package app\routine\model\store
|
|
||||||
*/
|
|
||||||
class StoreBargainUser extends ModelBasic
|
|
||||||
{
|
|
||||||
use ModelTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据砍价产品获取正在参与的用户头像
|
|
||||||
* @param array $bargain
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getUserList($bargain = array(),$limit = 10){
|
|
||||||
if(count($bargain) < 1) return [];
|
|
||||||
foreach ($bargain as $k=>$v){
|
|
||||||
if(is_array($v)){
|
|
||||||
$uid = self::getUserIdList($v['id']);
|
|
||||||
if(count($uid) > 0) {
|
|
||||||
$userInfo = User::where('uid','IN',implode(',',$uid))->limit($limit)->column('avatar','uid');
|
|
||||||
$bargain[$k]['userInfo'] = $userInfo;
|
|
||||||
$bargain[$k]['userInfoCount'] = count($userInfo);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$bargain[$k]['userInfo'] = [];
|
|
||||||
$bargain[$k]['userInfoCount'] = 0;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$uid = self::getUserIdList($bargain['id']);
|
|
||||||
if(count($uid) > 0) $bargain['userInfo'] = User::where('uid','IN',implode(',',$uid))->column('avatar','uid');
|
|
||||||
else $bargain['userInfo'] = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $bargain;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据砍价产品ID获取正在参与人的uid
|
|
||||||
* @param int $bargainId $bargainId 砍价产品ID
|
|
||||||
* @param int $status $status 状态 1 进行中 2 结束失败 3结束成功
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getUserIdList($bargainId = 0,$status = 1){
|
|
||||||
if(!$bargainId) return [];
|
|
||||||
return self::where('bargain_id',$bargainId)->where('status',$status)->column('uid','id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取参与的ID
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $uid
|
|
||||||
* @param int $status
|
|
||||||
* @return array|mixed
|
|
||||||
*/
|
|
||||||
public static function setUserBargain($bargainId = 0,$uid = 0,$status = 1){
|
|
||||||
if(!$bargainId || !$uid) return [];
|
|
||||||
$bargainIdUserTableId = self::where('bargain_id',$bargainId)->where('uid',$uid)->where('status',$status)->value('id');
|
|
||||||
return $bargainIdUserTableId;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加一条砍价记录
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $uid
|
|
||||||
* @return bool|object
|
|
||||||
*/
|
|
||||||
public static function setBargain($bargainId = 0,$uid = 0){
|
|
||||||
if(!$bargainId || !$uid || !StoreBargain::validBargain($bargainId) || self::be(['id'=>$bargainId,'uid'=>$uid,'status'=>1])) return false;
|
|
||||||
$data['bargain_id'] = $bargainId;
|
|
||||||
$data['uid'] = $uid;
|
|
||||||
$data['bargain_price_min'] = StoreBargain::where('id',$bargainId)->value('min_price');
|
|
||||||
$data['bargain_price'] = StoreBargain::where('id',$bargainId)->value('price');
|
|
||||||
$data['price'] = 0;
|
|
||||||
$data['status'] = 1;
|
|
||||||
$data['add_time'] = time();
|
|
||||||
return self::set($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断当前人是否已经参与砍价
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $uid
|
|
||||||
* @return bool|mixed
|
|
||||||
*/
|
|
||||||
public static function isBargainUser($bargainId = 0,$uid = 0){
|
|
||||||
if(!$bargainId || !$uid || !StoreBargain::validBargain($bargainId)) return false;
|
|
||||||
return self::where('bargain_id',$bargainId)->where('uid',$uid)->value('uid');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户砍掉的价格
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getBargainUserPrice($bargainUserId = 0){
|
|
||||||
return (float)self::where('id',$bargainUserId)->value('price');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户可以砍掉的价格
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getBargainUserDiffPrice($bargainId = 0,$bargainUserId = 0){
|
|
||||||
$price = self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->field('bargain_price,bargain_price_min')->find()->toArray();
|
|
||||||
return (float)bcsub($price['bargain_price'],$price['bargain_price_min'],0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取砍价表ID
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getBargainUserTableId($bargainId = 0,$bargainUserId = 0){
|
|
||||||
return self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->value('id');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改砍价价格
|
|
||||||
* @param int $bargainUserTableId
|
|
||||||
* @param array $price
|
|
||||||
* @return $this|bool
|
|
||||||
*/
|
|
||||||
public static function setBargainUserPrice($bargainUserTableId = 0, $price = array()){
|
|
||||||
if(!$bargainUserTableId) return false;
|
|
||||||
return self::where('id',$bargainUserTableId)->update($price);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,132 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace app\routine\model\store;
|
|
||||||
|
|
||||||
use app\routine\model\user\User;
|
|
||||||
use basic\ModelBasic;
|
|
||||||
use traits\ModelTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 砍价帮砍Model
|
|
||||||
* Class StoreBargainUser
|
|
||||||
* @package app\routine\model\store
|
|
||||||
*/
|
|
||||||
class StoreBargainUserHelp extends ModelBasic
|
|
||||||
{
|
|
||||||
use ModelTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取砍价帮
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getList($bargainUserId = 0,$limit = 15){
|
|
||||||
if(!$bargainUserId) return [];
|
|
||||||
$list = self::where('bargain_user_id',$bargainUserId)->limit($limit)->column('uid,price','id');
|
|
||||||
if($list){
|
|
||||||
foreach ($list as $k=>$v){
|
|
||||||
$userInfo = self::getBargainUserHelpUserInfo($v['uid']);
|
|
||||||
$list[$k]['nickname'] = $userInfo[$v['uid']]['nickname'];
|
|
||||||
$list[$k]['avatar'] = $userInfo[$v['uid']]['avatar'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用的昵称和头像
|
|
||||||
* @param int $uid
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getBargainUserHelpUserInfo($uid = 0){
|
|
||||||
if(!$uid) return [];
|
|
||||||
$userInfo = User::where('uid',$uid)->column('nickname,avatar','uid');
|
|
||||||
return $userInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 帮忙砍价
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @param int $uid
|
|
||||||
* @return bool|object
|
|
||||||
*/
|
|
||||||
public static function setBargainUserHelp($bargainId = 0,$bargainUserId = 0,$uid = 0){
|
|
||||||
if(!self::isBargainUserHelpCount($bargainId,$bargainUserId,$uid) || !$bargainId || !$bargainUserId || !$uid || !StoreBargain::validBargain($bargainId) || !StoreBargainUser::be(['id'=>$bargainId,'uid'=>$bargainUserId,'status'=>1])) return false;
|
|
||||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
|
||||||
$priceSection = StoreBargain::getBargainMaxMinPrice($bargainId); //获取砍价的价格区间
|
|
||||||
$coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
|
|
||||||
$alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
|
|
||||||
$surplusPrice = (float)bcsub($coverPrice,$alreadyPrice,2);//用户剩余要砍掉的价格
|
|
||||||
$data['uid'] = $uid;
|
|
||||||
$data['bargain_id'] = $bargainId;
|
|
||||||
$data['bargain_user_id'] = $bargainUserTableId;
|
|
||||||
$data['price'] = mt_rand($priceSection['bargain_min_price'],$priceSection['bargain_max_price']);
|
|
||||||
$data['add_time'] = time();
|
|
||||||
if($data['price'] > $surplusPrice) $data['price'] = $surplusPrice;
|
|
||||||
$price = bcadd($alreadyPrice,$data['price'],0);
|
|
||||||
$bargainUserData['price'] = $price;
|
|
||||||
self::beginTrans();
|
|
||||||
$res1 = StoreBargainUser::setBargainUserPrice($bargainUserTableId,$bargainUserData);
|
|
||||||
$res2 = self::set($data);
|
|
||||||
$res = $res1 && $res2;
|
|
||||||
self::checkTrans($res);
|
|
||||||
if($res) return $data;
|
|
||||||
else return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断用户是否还可以砍价
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $bargainUserUid
|
|
||||||
* @param int $bargainUserHelpUid
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function isBargainUserHelpCount($bargainId = 0,$bargainUserUid = 0,$bargainUserHelpUid = 0){
|
|
||||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserUid);
|
|
||||||
$bargainNum = StoreBargain::getBargainNum($bargainUserTableId);
|
|
||||||
$count = self::where('bargain_id',$bargainId)->where('bargain_user_id',$bargainUserTableId)->where('uid',$bargainUserHelpUid)->count();
|
|
||||||
if($count < $bargainNum) return true;
|
|
||||||
else return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取砍价帮总人数
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return int|string
|
|
||||||
*/
|
|
||||||
public static function getBargainUserHelpPeopleCount($bargainId = 0,$bargainUserId = 0){
|
|
||||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
|
||||||
if($bargainUserTableId) return self::where('bargain_user_id',$bargainUserTableId)->where('bargain_id',$bargainId)->count();
|
|
||||||
else return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户还剩余的砍价金额
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return float
|
|
||||||
*/
|
|
||||||
public static function getSurplusPrice($bargainId = 0,$bargainUserId = 0){
|
|
||||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
|
||||||
$coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
|
|
||||||
$alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
|
|
||||||
$surplusPrice = (float)bcsub($coverPrice,$alreadyPrice,2);//用户剩余要砍掉的价格
|
|
||||||
return $surplusPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取砍价进度条
|
|
||||||
* @param int $bargainId
|
|
||||||
* @param int $bargainUserId
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function getSurplusPricePercent($bargainId = 0,$bargainUserId = 0){
|
|
||||||
$coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
|
|
||||||
$bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
|
|
||||||
$alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
|
|
||||||
return bcmul(bcdiv($alreadyPrice,$coverPrice,2),100,0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,161 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author: xaboy<365615158@qq.com>
|
|
||||||
* @day: 2017/11/11
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace app\routine\model\store;
|
|
||||||
|
|
||||||
|
|
||||||
use traits\ModelTrait;
|
|
||||||
use basic\ModelBasic;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼团model
|
|
||||||
* Class StoreCombination
|
|
||||||
* @package app\routine\model\store
|
|
||||||
*/
|
|
||||||
class StoreCombination extends ModelBasic
|
|
||||||
{
|
|
||||||
use ModelTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $where
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function get_list($length=10){
|
|
||||||
if($post=input('post.')){
|
|
||||||
$where=$post['where'];
|
|
||||||
$model = new self();
|
|
||||||
$model = $model->alias('c');
|
|
||||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
|
||||||
$model = $model->where('c.is_show',1)->where('c.is_del',0)->where('c.start_time','LT',time())->where('c.stop_time','GT',time());
|
|
||||||
if(!empty($where['search'])){
|
|
||||||
$model = $model->where('c.title','like',"%{$where['search']}%");
|
|
||||||
$model = $model->whereOr('s.keyword','like',"{$where['search']}%");
|
|
||||||
}
|
|
||||||
$model = $model->field('c.*,s.price as product_price');
|
|
||||||
if($where['key']){
|
|
||||||
if($where['sales']==1){
|
|
||||||
$model = $model->order('c.sales desc');
|
|
||||||
}else if($where['sales']==2){
|
|
||||||
$model = $model->order('c.sales asc');
|
|
||||||
}
|
|
||||||
if($where['price']==1){
|
|
||||||
$model = $model->order('c.price desc');
|
|
||||||
}else if($where['price']==2){
|
|
||||||
$model = $model->order('c.price asc');
|
|
||||||
}
|
|
||||||
if($where['people']==1){
|
|
||||||
$model = $model->order('c.people asc');
|
|
||||||
}
|
|
||||||
if($where['default']==1){
|
|
||||||
$model = $model->order('c.sort desc,c.id desc');
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$model = $model->order('c.sort desc,c.id desc');
|
|
||||||
}
|
|
||||||
$page=is_string($where['page'])?(int)$where['page']+1:$where['page']+1;
|
|
||||||
$list = $model->page($page,$length)->select()->toArray();
|
|
||||||
return ['list'=>$list,'page'=>$page];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取所有拼团数据
|
|
||||||
* @param int $limit
|
|
||||||
* @param int $length
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getAll($limit = 0,$length = 0){
|
|
||||||
$model = new self();
|
|
||||||
$model = $model->alias('c');
|
|
||||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
|
||||||
$model = $model->field('c.*,s.price as product_price');
|
|
||||||
$model = $model->order('c.sort desc,c.id desc');
|
|
||||||
$model = $model->where('c.is_show',1);
|
|
||||||
$model = $model->where('c.is_del',0);
|
|
||||||
// $model = $model->where('c.start_time','LT',time());
|
|
||||||
// $model = $model->where('c.stop_time','GT',time());
|
|
||||||
if($limit && $length) $model = $model->limit($limit,$length);
|
|
||||||
$list = $model->select();
|
|
||||||
if($list) return $list->toArray();
|
|
||||||
else return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取一条拼团数据
|
|
||||||
* @param $id
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getCombinationOne($id){
|
|
||||||
$model = new self();
|
|
||||||
$model = $model->alias('c');
|
|
||||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
|
||||||
$model = $model->field('c.*,s.price as product_price');
|
|
||||||
$model = $model->where('c.is_show',1);
|
|
||||||
$model = $model->where('c.is_del',0);
|
|
||||||
$model = $model->where('c.id',$id);
|
|
||||||
// $model = $model->where('c.start_time','LT',time());
|
|
||||||
// $model = $model->where('c.stop_time','GT',time()-86400);
|
|
||||||
$list = $model->find();
|
|
||||||
if($list) return $list->toArray();
|
|
||||||
else return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取推荐的拼团产品
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function getCombinationHost($limit = 0){
|
|
||||||
$model = new self();
|
|
||||||
$model = $model->alias('c');
|
|
||||||
$model = $model->join('StoreProduct s','s.id=c.product_id');
|
|
||||||
$model = $model->field('c.id,c.image,c.price,c.sales,c.title,c.people,s.price as product_price');
|
|
||||||
$model = $model->where('c.is_del',0);
|
|
||||||
$model = $model->where('c.is_host',1);
|
|
||||||
$model = $model->where('c.is_host',1);
|
|
||||||
$model = $model->where('c.start_time','LT',time());
|
|
||||||
$model = $model->where('c.stop_time','GT',time());
|
|
||||||
if($limit) $model = $model->limit($limit);
|
|
||||||
$list = $model->select();
|
|
||||||
if($list) return $list->toArray();
|
|
||||||
else return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改销量和库存
|
|
||||||
* @param $num
|
|
||||||
* @param $CombinationId
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public static function decCombinationStock($num,$CombinationId)
|
|
||||||
{
|
|
||||||
$res = false !== self::where('id',$CombinationId)->dec('stock',$num)->inc('sales',$num)->update();
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 判断库存是否足够
|
|
||||||
* @param $id
|
|
||||||
* @param $cart_num
|
|
||||||
* @return int|mixed
|
|
||||||
*/
|
|
||||||
public static function getCombinationStock($id,$cart_num){
|
|
||||||
$stock = self::where('id',$id)->value('stock');
|
|
||||||
return $stock > $cart_num ? $stock : 0;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 获取产品状态
|
|
||||||
* @param $id
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public static function isValidCombination($id){
|
|
||||||
$model = new self();
|
|
||||||
$model = $model->where('id',$id);
|
|
||||||
$model = $model->where('is_del',0);
|
|
||||||
$model = $model->where('is_show',1);
|
|
||||||
return $model->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user