chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
231
app/services/activity/bargain/StoreBargainUserServices.php
Normal file
231
app/services/activity/bargain/StoreBargainUserServices.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\activity\bargain;
|
||||
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\dao\activity\bargain\StoreBargainUserDao;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class StoreBargainUserServices
|
||||
* @package app\services\activity\bargain
|
||||
* @mixin StoreBargainUserDao
|
||||
*/
|
||||
class StoreBargainUserServices extends BaseServices
|
||||
{
|
||||
|
||||
const EPTQRWNF = 'qbhzEE';
|
||||
|
||||
/**
|
||||
* @var StoreBargainUserDao
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreBargainUserDao $dao;
|
||||
|
||||
/**
|
||||
* 获取砍价
|
||||
* @param int $uid
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserUid
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function helpCount(int $uid, int $bargainId, int $bargainUserUid)
|
||||
{
|
||||
$data = [
|
||||
'userBargainStatus' => false,
|
||||
'count' => 0,
|
||||
'price' => 0,
|
||||
'status' => 0,
|
||||
'alreadyPrice' => 0,
|
||||
'pricePercent' => 0,
|
||||
];
|
||||
$bargainUserTableId = $this->dao->value(['bargain_id' => $bargainId, 'uid' => $bargainUserUid, 'is_del' => 0, 'status' => 1]);// 获取用户参与砍价表编号
|
||||
if ($bargainUserTableId) {
|
||||
$data['userBargainStatus'] = $this->isBargainUserHelpCount($bargainId, $uid, $bargainUserTableId);
|
||||
/** @var StoreBargainUserHelpServices $helpService */
|
||||
$helpService = app()->make(StoreBargainUserHelpServices::class);
|
||||
$count = $helpService->count(['bargain_user_id' => $bargainUserTableId, 'bargain_id' => $bargainId]);// 获取砍价帮总人数
|
||||
[$coverprice, $alreadyPrice, $price, $pricePercent] = $this->getSurplusPrice($bargainUserTableId);
|
||||
$data['count'] = $count;
|
||||
$data['price'] = $price;
|
||||
$data['status'] = $this->dao->value(['id' => $bargainUserTableId], 'status') ?? 0;
|
||||
$data['alreadyPrice'] = $alreadyPrice;
|
||||
$data['pricePercent'] = $pricePercent > 10 ? $pricePercent : 10;
|
||||
} else {
|
||||
/** @var StoreBargainServices $bargainService */
|
||||
$bargainService = app()->make(StoreBargainServices::class);
|
||||
$data['count'] = 0;
|
||||
$data['price'] = $bargainService->value(['id' => $bargainId], 'price - min_price');
|
||||
$data['status'] = $this->dao->value(['id' => $bargainUserTableId], 'status') ?? 0;
|
||||
$data['alreadyPrice'] = 0;
|
||||
$data['pricePercent'] = 0;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价状态
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserUid
|
||||
* @param int $bargainUserHelpUid
|
||||
* @param $bargainUserTableId
|
||||
* @return bool
|
||||
*/
|
||||
public function isBargainUserHelpCount($bargainId, $bargainUserHelpUid, $bargainUserTableId)
|
||||
{
|
||||
/** @var StoreBargainUserHelpServices $userHelp */
|
||||
$userHelp = app()->make(StoreBargainUserHelpServices::class);
|
||||
$count = $userHelp->count(['bargain_id' => $bargainId, 'bargain_user_id' => $bargainUserTableId, 'uid' => $bargainUserHelpUid]);
|
||||
if (!$count) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取砍价剩余金额 或者 砍价百分比
|
||||
* @param $bargainUserTableId
|
||||
* @return array|float|int
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getSurplusPrice($bargainUserTableId)
|
||||
{
|
||||
$bargainUserInfo = $this->dao->get($bargainUserTableId);
|
||||
$coverPrice = $alreadyPrice = $surplusPrice = 0;
|
||||
$pricePercent = 100;
|
||||
if ($bargainUserInfo) {
|
||||
// 获取用户可以砍掉的金额 好友砍价之后获取砍价金额
|
||||
$coverPrice = (float)bcsub((string)$bargainUserInfo['bargain_price'], (string)$bargainUserInfo['bargain_price_min'], 2);
|
||||
// 用户已经砍掉的价格 好友砍价之后获取用户已经砍掉的价格
|
||||
$alreadyPrice = $this->dao->value(['id' => $bargainUserTableId], 'price');
|
||||
// 用户剩余要砍掉的价格
|
||||
$surplusPrice = (float)bcsub((string)$coverPrice, (string)$alreadyPrice, 2);
|
||||
if ($alreadyPrice) {//进度条百分比
|
||||
$pricePercent = (int)bcmul((string)bcdiv((string)$alreadyPrice, (string)$coverPrice, 2), '100', 0);
|
||||
}
|
||||
}
|
||||
return [$coverPrice, $alreadyPrice, $surplusPrice, $pricePercent, $bargainUserInfo];
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加砍价信息
|
||||
* @param int $bargainId
|
||||
* @param int $bargainUserUid
|
||||
* @param array $bargainInfo
|
||||
* @return mixed
|
||||
*/
|
||||
public function setBargain(int $bargainId, int $bargainUserUid, array $bargainInfo)
|
||||
{
|
||||
$data['bargain_id'] = $bargainId;
|
||||
$data['uid'] = $bargainUserUid;
|
||||
$data['bargain_price_min'] = $bargainInfo['min_price'];
|
||||
$data['bargain_price'] = $bargainInfo['price'];
|
||||
$data['price'] = 0;
|
||||
$data['status'] = 1;
|
||||
$data['is_del'] = 0;
|
||||
$data['add_time'] = time();
|
||||
return $this->dao->save($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改砍价状态
|
||||
* @param $uid
|
||||
* @return bool
|
||||
*/
|
||||
public function editBargainUserStatus($uid)
|
||||
{
|
||||
$currentBargain = $this->dao->getColumn(['uid' => $uid, 'is_del' => 0, 'status' => 1], 'bargain_id');
|
||||
/** @var StoreBargainServices $bargainService */
|
||||
$bargainService = app()->make(StoreBargainServices::class);
|
||||
$bargainProduct = $bargainService->validWhere()->column('id');
|
||||
$closeBargain = [];
|
||||
foreach ($currentBargain as $key => &$item) {
|
||||
if (!in_array($item, $bargainProduct)) {
|
||||
$closeBargain[] = $item;
|
||||
}
|
||||
}// 获取已经结束的砍价商品
|
||||
if (count($closeBargain)) $this->dao->update([['uid', '=', $uid], ['status', '=', 1], ['bargain_id', 'in', implode(',', $closeBargain)]], ['status' => 2]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户的砍价商品
|
||||
* @param int $bargainUserUid $bargainUserUid 开启砍价用户编号
|
||||
* @return array
|
||||
*/
|
||||
public function getBargainUserAll(int $bargainUserUid)
|
||||
{
|
||||
if (!$bargainUserUid) return [];
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->userAll($bargainUserUid, $page, $limit);
|
||||
foreach ($list as &$item) {
|
||||
$item['residue_price'] = bcsub((string)$item['bargain_price'], (string)$item['price'], 2);
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
|
||||
[$coverprice, $alreadyPrice, $price, $pricePercent] = $this->getSurplusPrice((int)$item['id']);
|
||||
$item['pay_status'] = $price <= 0 && $item['status'] != 3;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消砍价
|
||||
* @param $bargainId
|
||||
* @param $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public function cancelBargain($bargainId, $uid)
|
||||
{
|
||||
$status = $this->dao->getBargainUserStatus($bargainId, $uid);
|
||||
if ($status != 1) throw new ValidateException('状态错误');
|
||||
$id = $this->dao->value(['bargain_id' => $bargainId, 'uid' => $uid, 'is_del' => 0], 'id');
|
||||
|
||||
return $this->dao->update($id, ['is_del' => 1, 'status' => 2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 砍价列表
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public function bargainUserList($where)
|
||||
{
|
||||
[$page, $limit] = $this->getPageValue();
|
||||
$list = $this->dao->bargainUserList($where, $page, $limit);
|
||||
$count = $this->dao->count($where);
|
||||
/** @var StoreBargainUserHelpServices $bargainUserHelpService */
|
||||
$bargainUserHelpService = app()->make(StoreBargainUserHelpServices::class);
|
||||
$nums = $bargainUserHelpService->getNums();
|
||||
$time = time();
|
||||
foreach ($list as &$item) {
|
||||
$item['num'] = $item['people_num'] - ($nums[$item['id']] ?? 0);
|
||||
$item['already_num'] = $nums[$item['id']] ?? 0;
|
||||
$item['now_price'] = bcsub((string)$item['bargain_price'], (string)$item['price'], 2);
|
||||
$item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', (int)$item['add_time']) : '';
|
||||
if ($item['status'] == 1 && isset($item['datatime']) && $item['datatime'] && $item['datatime'] < $time) {//进行中 验证时间是否结束
|
||||
$item['status'] = 2;
|
||||
}
|
||||
if (isset($item['datatime']) && $item['datatime']) {
|
||||
$item['datatime'] = date('Y-m-d H:i:s', (int)$item['datatime']);
|
||||
} else {
|
||||
$item['datatime'] = '';
|
||||
}
|
||||
}
|
||||
return compact('list', 'count');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user