|
|
@@ -247,7 +247,7 @@ class TradeService extends BaseService
|
|
|
$query->where('a.pay_time', '>=', $time)->orWhere('a.create_time', '>=', $time);
|
|
|
}
|
|
|
})
|
|
|
- ->select(['a.*', 'b.nickname', 'b.code as user_code', 'b.mobile as mobile', 'c.name as shop_name', 'c.code as shop_code', 'g.goods_name', 'g.thumb'])
|
|
|
+ ->select(['a.*', 'b.nickname', 'b.code as user_code', 'b.mobile as mobile', 'c.name as shop_name', 'c.code as shop_code', 'g.goods_name','g.code', 'g.thumb'])
|
|
|
->orderBy('a.create_time', 'desc')
|
|
|
->orderBy('a.id', 'desc')
|
|
|
->paginate($pageSize > 0 ? $pageSize : 9999999);
|
|
|
@@ -390,6 +390,29 @@ class TradeService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取用户当天
|
|
|
+ * @param $userId
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getCountByDay($userId)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:trade:count:{$userId}";
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
+ if($data){
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->model->where(['user_id'=> $userId, 'status'=> 4,'is_sell'=> 2,'mark'=>1])
|
|
|
+ ->where('create_time','>=',strtotime(date('Y-m-d')))
|
|
|
+ ->count('id');
|
|
|
+ if($data){
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 添加或编辑
|
|
|
* @return array
|
|
|
* @since 2020/11/11
|
|
|
@@ -752,6 +775,34 @@ class TradeService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取用户抢拍数量
|
|
|
+ * @param $userId
|
|
|
+ * @param string $time
|
|
|
+ * @return array|mixed
|
|
|
+ */
|
|
|
+ public function getTradeByDay($userId, $time=''){
|
|
|
+ $cacheKey = "caches:trade:snapNum:{$userId}";
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
+ if($data){
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->model->where(['user_id'=> $userId,'mark'=>1])
|
|
|
+ ->whereIn('status',[1,2,3,4])
|
|
|
+ ->where(function($query) use($time){
|
|
|
+ if($time){
|
|
|
+ $query->where('create_time','>=', $time);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->count('id');
|
|
|
+ if($data){
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 抢购
|
|
|
* @param $params
|
|
|
* @param $userId
|
|
|
@@ -798,8 +849,15 @@ class TradeService extends BaseService
|
|
|
$startTime = isset($shopInfo['start_time']) ? $shopInfo['start_time'] : '';
|
|
|
$endTime = isset($shopInfo['end_time']) ? $shopInfo['end_time'] : '';
|
|
|
|
|
|
+ // 抢拍数量限制
|
|
|
+ $snapNum = ConfigService::make()->getConfigByCode('member_snap_num');
|
|
|
+ $snapNum = $snapNum>0? $snapNum : 5;
|
|
|
+
|
|
|
// 店长自己抢
|
|
|
if ($shopInfo['user_id'] == $userId) {
|
|
|
+ $shopownerSnapNum = ConfigService::make()->getConfigByCode('shopowner_snap_num');
|
|
|
+ $snapNum = $shopownerSnapNum>0? $shopownerSnapNum : 5;
|
|
|
+
|
|
|
$snapTime = ConfigService::make()->getConfigByCode('snap_time');
|
|
|
$snapTime = $snapTime ? $snapTime : 5;
|
|
|
$curTime = strtotime(date('Y-m-d') . ' ' . $startTime) + 1;
|
|
|
@@ -820,6 +878,13 @@ class TradeService extends BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 抢拍数量验证
|
|
|
+ $curSnapNum = TradeService::make()->getTradeByDay($userId, strtotime(date('Y-m-d')));
|
|
|
+ if($curSnapNum>=$snapNum){
|
|
|
+ $this->error = lang(2096,['num'=> $snapNum]);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
// 验证收款账号
|
|
|
if (!MemberBankService::make()->getBindInfo($userId)) {
|
|
|
$this->error = 2037;
|
|
|
@@ -883,6 +948,8 @@ class TradeService extends BaseService
|
|
|
DB::commit();
|
|
|
$this->error = 2041;
|
|
|
RedisService::keyDel($lockCacheKey);
|
|
|
+ // 抢拍成功,清除当天已抢拍数量统计
|
|
|
+ RedisService::keyDel("caches:trade:snapNum:{$userId}");
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -1190,25 +1257,22 @@ class TradeService extends BaseService
|
|
|
|
|
|
// 满足涨价上架
|
|
|
if ($price1 + $addPrice < $info['split_price']) {
|
|
|
- // 平台服务费
|
|
|
- $serviceRate = ConfigService::make()->getConfigByCode('service_fee_rate');
|
|
|
- $serviceRate = $serviceRate ? $serviceRate : 8;
|
|
|
- $serviceFee = round(($realPrice) * $serviceRate / 100, 0);
|
|
|
- if (!$this->model->where(['id' => $id])->update(['status' => 4, 'service_fee' => $serviceFee, 'new_price' => $price1 + $addPrice, 'new_real_price' => $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
|
|
|
+ // 更新价格
|
|
|
+ if (!$this->model->where(['id' => $id])->update(['status' => 4, 'new_price' => $price1 + $addPrice, 'new_real_price' => $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
|
|
|
$this->error = 2056;
|
|
|
DB::rollBack();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (!GoodsModel::where(['id' => $info['goods_id']])->update(['last_sell_time' => time(), 'price' => $price1 + $addPrice, 'real_price' => $realPrice + $addPrice, 'is_trade' => 2, 'confirm_status' => 1, 'remark' => '上架审核 ' . date('Y-m-d H:i:s'), 'update_time' => time()])) {
|
|
|
+ // 更新其他交易状态
|
|
|
+ $this->model->where(['goods_id' => $info['goods_id'], 'status' => 4, 'mark' => 1])->whereNotIn('id', [$id])->update(['is_out' => 1, 'update_time' => time()]);
|
|
|
+
|
|
|
+ if (!GoodsModel::where(['id' => $info['goods_id']])->update(['user_id'=>$info['user_id'],'last_sell_time' => time(), 'price' => $price1 + $addPrice, 'real_price' => $realPrice + $addPrice, 'is_trade' => 2, 'confirm_status' => 1, 'remark' => '上架审核 ' . date('Y-m-d H:i:s'), 'update_time' => time()])) {
|
|
|
$this->error = 2056;
|
|
|
DB::rollBack();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 服务费统计
|
|
|
- FinanceService::make()->settleBonus($serviceFee, 1);
|
|
|
-
|
|
|
DB::commit();
|
|
|
|
|
|
// 佣金结算
|
|
|
@@ -1220,7 +1284,21 @@ class TradeService extends BaseService
|
|
|
return true;
|
|
|
} // 停止拆分
|
|
|
else if ($info['sell_price'] == $stopSplitPrice) {
|
|
|
- if (!GoodsModel::where(['id' => $info['goods_id']])->update(['status' => 2, 'confirm_status' => 1, 'split_stop' => 1, 'update_time' => time()])) {
|
|
|
+ // 更新审核状态
|
|
|
+ if (!$this->model->where(['id' => $id])->update(['status' => 4, 'is_sell' => 2, 'update_time' => time()])) {
|
|
|
+ $this->error = 2056;
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更改商品归属人
|
|
|
+ if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id' => $info['user_id'], 'update_time' => time()])) {
|
|
|
+ $this->error = 2050;
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!GoodsModel::where(['id' => $info['goods_id']])->update(['status' => 1, 'confirm_status' => 2, 'split_stop' => 1, 'update_time' => time()])) {
|
|
|
$this->error = 2054;
|
|
|
DB::rollBack();
|
|
|
return false;
|
|
|
@@ -1236,6 +1314,23 @@ class TradeService extends BaseService
|
|
|
return true;
|
|
|
} // 满足拆分
|
|
|
else if ($info['split_price']) {
|
|
|
+ // 更新审核状态
|
|
|
+ if (!$this->model->where(['id' => $id])->update(['status' => 4, 'is_sell' => 2, 'update_time' => time()])) {
|
|
|
+ $this->error = 2056;
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新其他交易状态
|
|
|
+ $this->model->where(['goods_id' => $info['goods_id'], 'status' => 4, 'mark' => 1])->whereNotIn('id', [$id])->update(['is_out' => 1, 'update_time' => time()]);
|
|
|
+
|
|
|
+ // 更改商品归属人
|
|
|
+ if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id' => $info['user_id'], 'update_time' => time()])) {
|
|
|
+ $this->error = 2050;
|
|
|
+ DB::rollBack();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
if (!GoodsService::make()->split($info['goods_id'], $info)) {
|
|
|
$this->error = 2058;
|
|
|
DB::rollBack();
|
|
|
@@ -1267,14 +1362,7 @@ class TradeService extends BaseService
|
|
|
{
|
|
|
// 更新商品交易状态
|
|
|
DB::beginTransaction();
|
|
|
- $this->model->where(['goods_id' => $info['goods_id'], 'status' => 4, 'mark' => 1])->whereNotIn('id', [$tradeId])->update(['is_out' => 1, 'update_time' => time()]);
|
|
|
|
|
|
- // 更改商品归属人
|
|
|
- if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id' => $info['user_id'], 'update_time' => time()])) {
|
|
|
- $this->error = 2050;
|
|
|
- DB::rollBack();
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
$memberInfo = MemberModel::where(['id' => $info['user_id'], 'mark' => 1])->first();
|
|
|
$parentId = isset($memberInfo['parent_id']) ? $memberInfo['parent_id'] : 0;
|
|
|
@@ -1294,12 +1382,23 @@ class TradeService extends BaseService
|
|
|
$profitRate = ConfigService::make()->getConfigByCode('profit_rate');
|
|
|
$profitRate = $profitRate ? $profitRate : 0;
|
|
|
$profit = $info['real_price'] * $profitRate / 100;
|
|
|
- if (!$this->model->where(['id' => $tradeId, 'mark' => 1])->update(['bonus' => $bonus, 'profit' => $profit, 'update_time' => time()])) {
|
|
|
+
|
|
|
+ // 平台服务费
|
|
|
+ $serviceRate = ConfigService::make()->getConfigByCode('service_fee_rate');
|
|
|
+ $serviceRate = $serviceRate ? $serviceRate : 8;
|
|
|
+ $serviceFee = round($info['real_price'] * $serviceRate / 100, 0);
|
|
|
+
|
|
|
+ if (!$this->model->where(['id' => $tradeId, 'mark' => 1])->update(['bonus' => $bonus,'service_fee'=> $serviceFee, 'profit' => $profit, 'update_time' => time()])) {
|
|
|
$this->error = 2051;
|
|
|
DB::rollBack();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ // 服务费统计
|
|
|
+ if($serviceFee>0){
|
|
|
+ FinanceService::make()->settleBonus($serviceFee, 1);
|
|
|
+ }
|
|
|
+
|
|
|
// 收益记录
|
|
|
$data = [
|
|
|
'user_id' => $info['user_id'],
|