mirror of
https://github.com/crmeb/CRMEB.git
synced 2025-12-21 18:10:16 +00:00
小程序更新
This commit is contained in:
parent
4e198e30be
commit
c0e5233d91
159
application/routine/model/store/StoreBargain.php
Normal file
159
application/routine/model/store/StoreBargain.php
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
<?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
202
application/routine/model/store/StoreBargainUser.php
Normal file
202
application/routine/model/store/StoreBargainUser.php
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
<?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(['bargain_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,$status = 1){
|
||||||
|
return self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->where('status',$status)->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户的砍价产品
|
||||||
|
* @param $uid
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getBargainUserAll($uid = 0){
|
||||||
|
if(!$uid) return [];
|
||||||
|
$model = new self;
|
||||||
|
$model = $model->alias('u');
|
||||||
|
$model = $model->field('u.id,u.bargain_id,u.bargain_price,u.bargain_price_min,u.price,u.status,b.title,b.image,b.stop_time');
|
||||||
|
$model = $model->join('StoreBargain b','b.id=u.bargain_id');
|
||||||
|
$model = $model->where('u.uid',$uid);
|
||||||
|
$model = $model->order('u.id desc');
|
||||||
|
$list = $model->select();
|
||||||
|
if($list) return $list->toArray();
|
||||||
|
else return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改用户砍价状态 支付订单
|
||||||
|
* @param int $bargainId
|
||||||
|
* @param int $uid
|
||||||
|
* @return $this|bool
|
||||||
|
*/
|
||||||
|
public static function setBargainUserStatus($bargainId = 0, $uid = 0){
|
||||||
|
$count = self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->count();
|
||||||
|
if(!$count) return false;
|
||||||
|
$userPrice = (float)self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->value('price');
|
||||||
|
$price = self::getBargainUserDiffPrice($bargainId,$uid);
|
||||||
|
if(bcsub($price,$userPrice,0) > 0) return false;
|
||||||
|
return self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->update(['status'=>3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改砍价状态为 砍价失败
|
||||||
|
* @param int $bargainUserTableId
|
||||||
|
* @return $this|bool
|
||||||
|
*/
|
||||||
|
public static function editBargainUserStatus($bargainUserTableId = 0){
|
||||||
|
if(!$bargainUserTableId) return false;
|
||||||
|
return self::where('id',$bargainUserTableId)->update(['status'=>2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取砍价成功的用户信息
|
||||||
|
* @return array|false|\PDOStatement|string|\think\Collection
|
||||||
|
*/
|
||||||
|
public static function getBargainUserStatusSuccess(){
|
||||||
|
$bargainUser = self::where('status',3)->order('id desc')->field('uid,bargain_price_min,bargain_id')->select();
|
||||||
|
if($bargainUser) {
|
||||||
|
$bargainUser = $bargainUser->toArray();
|
||||||
|
foreach ($bargainUser as $k=>$v){
|
||||||
|
$bargainUser[$k]['info'] = User::where('uid',$v['uid'])->value('nickname').'砍价成功了'.$v['bargain_price_min'].'砍到了'.StoreBargain::where('id',$v['bargain_id'])->value('title');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$bargainUser[]['info'] = '砍价上线了,快邀请您的好友来砍价';
|
||||||
|
}
|
||||||
|
return $bargainUser;
|
||||||
|
}
|
||||||
|
}
|
||||||
142
application/routine/model/store/StoreBargainUserHelp.php
Normal file
142
application/routine/model/store/StoreBargainUserHelp.php
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
<?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(['bargain_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'] = self::randomFloat($priceSection['bargain_min_price'],$priceSection['bargain_max_price']);
|
||||||
|
$data['add_time'] = time();
|
||||||
|
if($data['price'] > $surplusPrice) $data['price'] = $surplusPrice;
|
||||||
|
$price = bcadd($alreadyPrice,$data['price'],2);
|
||||||
|
$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 $min
|
||||||
|
* @param int $max
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function randomFloat($min = 0,$max = 1){
|
||||||
|
$num = $min + mt_rand() / mt_getrandmax() * ($max - $min);
|
||||||
|
return sprintf("%.2f",$num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断用户是否还可以砍价
|
||||||
|
* @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($bargainId);
|
||||||
|
$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){
|
||||||
|
if(!$bargainId || !$bargainUserId) return 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
160
application/routine/model/store/StoreCombination.php
Normal file
160
application/routine/model/store/StoreCombination.php
Normal file
@ -0,0 +1,160 @@
|
|||||||
|
<?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.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
73
application/routine/view/crmebN/pages/home/home.js
Normal file
73
application/routine/view/crmebN/pages/home/home.js
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// pages/home/home.js
|
||||||
|
Page({
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面的初始数据
|
||||||
|
*/
|
||||||
|
data: {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面加载
|
||||||
|
*/
|
||||||
|
onLoad: function (options) {
|
||||||
|
|
||||||
|
},
|
||||||
|
setTouchMove: function (e) {
|
||||||
|
var that = this;
|
||||||
|
if (e.touches[0].clientY < 500 && e.touches[0].clientY > 0) {
|
||||||
|
that.setData({
|
||||||
|
top: e.touches[0].clientY
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面初次渲染完成
|
||||||
|
*/
|
||||||
|
onReady: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面显示
|
||||||
|
*/
|
||||||
|
onShow: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面隐藏
|
||||||
|
*/
|
||||||
|
onHide: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生命周期函数--监听页面卸载
|
||||||
|
*/
|
||||||
|
onUnload: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面相关事件处理函数--监听用户下拉动作
|
||||||
|
*/
|
||||||
|
onPullDownRefresh: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页面上拉触底事件的处理函数
|
||||||
|
*/
|
||||||
|
onReachBottom: function () {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户点击右上角分享
|
||||||
|
*/
|
||||||
|
onShareAppMessage: function () {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
1
application/routine/view/crmebN/pages/home/home.json
Normal file
1
application/routine/view/crmebN/pages/home/home.json
Normal file
@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
6
application/routine/view/crmebN/pages/home/home.wxml
Normal file
6
application/routine/view/crmebN/pages/home/home.wxml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<!-- 返回首页 -->
|
||||||
|
<view class="view" style=" top:{{top}}px;" catchtouchmove="setTouchMove">
|
||||||
|
<navigator url='/pages/index/index' hover-class='none' open-type = "switchTab" >
|
||||||
|
<image src="/images/home.png"></image>
|
||||||
|
</navigator>
|
||||||
|
</view>
|
||||||
3
application/routine/view/crmebN/pages/home/home.wxss
Normal file
3
application/routine/view/crmebN/pages/home/home.wxss
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/* pages/home/home.wxss */
|
||||||
|
.view{position: fixed ; /*相对定位*/bottom:50%;height:82rpx;width:82rpx;border-radius:50%;color: white;text-align: center;z-index:99;right:10rpx;margin: 0% 0rpx -41rpx 0%;}
|
||||||
|
.view image{width:82rpx;height:82rpx;border-radius:50%;}
|
||||||
Loading…
x
Reference in New Issue
Block a user