|
|
@@ -14,6 +14,7 @@ namespace App\Services\Common;
|
|
|
use App\Models\AccountModel;
|
|
|
use App\Models\GoodsModel;
|
|
|
use App\Models\MemberModel;
|
|
|
+use App\Models\ShopModel;
|
|
|
use App\Models\TradeModel;
|
|
|
use App\Services\BaseService;
|
|
|
use App\Services\ConfigService;
|
|
|
@@ -390,38 +391,6 @@ class TradeService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取店铺交易统计
|
|
|
- * @param $shopId
|
|
|
- * @param int $status
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getShopTradeTotal($shopId, $status = 0)
|
|
|
- {
|
|
|
- $where = ['shop_id' => $shopId, 'mark' => 1];
|
|
|
- if ($status) {
|
|
|
- $where['status'] = $status;
|
|
|
- }
|
|
|
- return $this->model->where($where)
|
|
|
- ->sum('real_price');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取交易数
|
|
|
- * @param $shopId
|
|
|
- * @param int $status
|
|
|
- * @return mixed
|
|
|
- */
|
|
|
- public function getShopTradeCount($shopId, $status = 0)
|
|
|
- {
|
|
|
- $where = ['shop_id' => $shopId, 'mark' => 1];
|
|
|
- if ($status) {
|
|
|
- $where['status'] = $status;
|
|
|
- }
|
|
|
- return $this->model->where($where)
|
|
|
- ->count('id');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* 获取用户交易统计
|
|
|
* @param $userId
|
|
|
* @param int $status
|
|
|
@@ -496,11 +465,90 @@ class TradeService extends BaseService
|
|
|
/**
|
|
|
* 获取用户佣金统计
|
|
|
* @param $userId
|
|
|
+ * @param int $time
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getTradeBonusTotal($userId, $time = 0)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:trade:bonus:{$userId}_".(is_array($time)? implode('-', $time):$time);
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
+ if($data){
|
|
|
+ return round($data, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = ['a.user_id' => $userId,'type'=> 2,'a.coin_type'=> 2,'a.status'=>1,'a.mark'=>1];
|
|
|
+ $data = AccountModel::from('account_log as a')
|
|
|
+ ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
|
|
|
+ ->where($where)
|
|
|
+ ->where(function ($query) use ($time) {
|
|
|
+ // 本月
|
|
|
+ if ($time == 1) {
|
|
|
+ $query->where('a.create_time', '>=', strtotime(date('Y-m-01')));
|
|
|
+ } // 今日
|
|
|
+ else if ($time == 2) {
|
|
|
+ $query->where('a.create_time', '>=', strtotime(date('Y-m-d')));
|
|
|
+ }else if ($time){
|
|
|
+ $month = date('Y-m', $time/1000);
|
|
|
+ $lastDay = strtotime("{$month}-01 +1 month -1 day");
|
|
|
+ if($month){
|
|
|
+ $query->where('a.create_time', '>=', $time/1000);
|
|
|
+ $query->where('a.create_time', '<', $lastDay+86400);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->sum('a.money');
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
+ return round($data, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户收益统计
|
|
|
+ * @param $userId
|
|
|
+ * @param int $time
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function getTradeProfitTotal($userId, $time = 0)
|
|
|
+ {
|
|
|
+ $cacheKey = "caches:trade:profit:{$userId}_".(is_array($time)? implode('-', $time):$time);
|
|
|
+ $data = RedisService::get($cacheKey);
|
|
|
+ if($data){
|
|
|
+ return round($data, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = ['a.user_id' => $userId,'type'=> 2,'a.coin_type'=> 5,'a.status'=>1,'a.mark'=>1];
|
|
|
+ $data = AccountModel::from('account_log as a')
|
|
|
+ ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
|
|
|
+ ->where($where)
|
|
|
+ ->where(function ($query) use ($time) {
|
|
|
+ // 本月
|
|
|
+ if ($time == 1) {
|
|
|
+ $query->where('a.create_time', '>=', strtotime(date('Y-m-01')));
|
|
|
+ } // 今日
|
|
|
+ else if ($time == 2) {
|
|
|
+ $query->where('a.create_time', '>=', strtotime(date('Y-m-d')));
|
|
|
+ }else if ($time){
|
|
|
+ $month = date('Y-m', $time/1000);
|
|
|
+ $lastDay = strtotime("{$month}-01 +1 month -1 day");
|
|
|
+ if($month){
|
|
|
+ $query->where('a.create_time', '>=', $time/1000);
|
|
|
+ $query->where('a.create_time', '<', $lastDay+86400);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->sum('a.money');
|
|
|
+ RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
+ return round($data, 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户佣金统计
|
|
|
+ * @param $userId
|
|
|
* @param int $status
|
|
|
* @param int $time
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function getTradeBonusTotal($userId, $status = 0, $time = 0)
|
|
|
+ public function getTradeBonusTotal1($userId, $status = 0, $time = 0)
|
|
|
{
|
|
|
$cacheKey = "caches:trade:bonus:{$userId}_".(is_array($status)? implode('-', $status):$status)."_".(is_array($time)? implode('-', $time):$time);
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
@@ -539,7 +587,6 @@ class TradeService extends BaseService
|
|
|
RedisService::set($cacheKey, $data, rand(3,5));
|
|
|
return round($data, 2);
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 获取用户收益统计
|
|
|
* @param $userId
|
|
|
@@ -547,7 +594,7 @@ class TradeService extends BaseService
|
|
|
* @param int $time
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public function getTradeProfitTotal($userId, $status = 0, $time = 0)
|
|
|
+ public function getTradeProfitTotal1($userId, $status = 0, $time = 0)
|
|
|
{
|
|
|
$cacheKey = "caches:trade:profit:{$userId}_".(is_array($status)? implode('-', $status):$status)."_".(is_array($time)? implode('-', $time):$time);
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
@@ -822,38 +869,64 @@ class TradeService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if(!MemberModel::where(['id'=> $userId])->update(['member_level'=>1,'update_time'=>time()])){
|
|
|
+ $memberInfo = MemberModel::where(['id' => $info['user_id'], 'mark' => 1])->first();
|
|
|
+ $parentId = isset($memberInfo['parent_id']) ? $memberInfo['parent_id'] : 0;
|
|
|
+ $meritsCount = isset($memberInfo['merits_count']) ? $memberInfo['merits_count'] : 0;
|
|
|
+ $updateData = ['merits_count'=> $meritsCount+$info['real_price'],'merits_time'=>date('Y-m-d H:i:s'),'member_level'=>1,'update_time'=>time()];
|
|
|
+ if(!MemberModel::where(['id'=> $userId])->update($updateData)){
|
|
|
$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;
|
|
|
$parentInfo = MemberModel::where(['id' => $parentId, 'mark' => 1])->first();
|
|
|
- if ($memberInfo && $parentId && $parentInfo) {
|
|
|
- $bonusRate = ConfigService::make()->getConfigByCode('bonus_rate');
|
|
|
- $bonusRate = $bonusRate ? $bonusRate : 5;
|
|
|
- $bonus = $info['real_price'] * $bonusRate / 100;
|
|
|
+ $bonusRate = ConfigService::make()->getConfigByCode('bonus_rate');
|
|
|
+ $bonusRate = $bonusRate ? $bonusRate : 5;
|
|
|
+ $bonus = $info['real_price'] * $bonusRate / 100;
|
|
|
+ $profitRate = ConfigService::make()->getConfigByCode('profit_rate');
|
|
|
+ $profitRate = $profitRate ? $profitRate : 0;
|
|
|
+ $profit = $info['real_price'] * $profitRate / 100;
|
|
|
+ if (!$this->model->where(['id' => $id, 'mark' => 1])->update(['bonus' => $bonus,'profit'=> $profit, 'update_time' => time()])) {
|
|
|
+ $this->error = 2051;
|
|
|
+ DB::rollBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- $profitRate = ConfigService::make()->getConfigByCode('profit_rate');
|
|
|
- $profitRate = $profitRate ? $profitRate : 0;
|
|
|
- $profit = $info['real_price'] * $profitRate / 100;
|
|
|
+ // 收益记录
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'shop_id' => $info['shop_id'],
|
|
|
+ 'source_uid' => $userId,
|
|
|
+ 'source_order_sn' => $info['order_sn'],
|
|
|
+ 'type' => 2,
|
|
|
+ 'coin_type' => 5,
|
|
|
+ 'money' => $profit,
|
|
|
+ 'balance' => 0,
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'update_time' => time(),
|
|
|
+ 'remark' => '抢拍收益',
|
|
|
+ 'status' => 1,
|
|
|
+ 'mark' => 1
|
|
|
+ ];
|
|
|
|
|
|
- if ($bonus > 0) {
|
|
|
- if (!$this->model->where(['id' => $id, 'mark' => 1])->update(['bonus' => $bonus,'profit'=> $profit, 'update_time' => time()])) {
|
|
|
- $this->error = 2051;
|
|
|
- DB::rollBack();
|
|
|
- return true;
|
|
|
- }
|
|
|
+ if (!AccountModel::insertGetId($data)) {
|
|
|
+ $this->error = 2051;
|
|
|
+ DB::rollBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- if (!MemberModel::where(['id' => $parentId, 'mark' => 1])->update(['bonus' => $parentInfo['bonus'] + $bonus,'bonus_total'=> $parentInfo['bonus_total']+$bonus, 'update_time' => time()])) {
|
|
|
+ // 佣金入账
|
|
|
+ if ($memberInfo && $parentId && $parentInfo && $bonus>0) {
|
|
|
+ $meritsTotal = isset($parentInfo['merits_total'])? $parentInfo['merits_total'] : 0;
|
|
|
+ $updateData = ['merits_total'=> $meritsTotal + $info['real_price'],'bonus' => $parentInfo['bonus'] + $bonus,'bonus_total'=> $parentInfo['bonus_total']+$bonus, 'update_time' => time()];
|
|
|
+ if (!MemberModel::where(['id' => $parentId, 'mark' => 1])->update($updateData)) {
|
|
|
$this->error = 2051;
|
|
|
DB::rollBack();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ // 佣金记录
|
|
|
$data = [
|
|
|
'user_id' => $parentId,
|
|
|
'shop_id' => $info['shop_id'],
|
|
|
@@ -878,11 +951,17 @@ class TradeService extends BaseService
|
|
|
|
|
|
// 结算统计
|
|
|
FinanceService::make()->settleBonus($bonus, 2);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
DB::commit();
|
|
|
+
|
|
|
+ // 店铺统计
|
|
|
+ $shopId = isset($info['shop_id']) ? $info['shop_id'] : 0;
|
|
|
+ $shopInfo = ShopModel::where(['id'=> $shopId])->first();
|
|
|
+ if($shopInfo){
|
|
|
+ ShopModel::where(['id'=> $shopId])->update(['trade_count'=> $shopInfo['trade_count'], 'trade_total'=> $info['real_price']+$shopInfo['trade_total']]);
|
|
|
+ }
|
|
|
+
|
|
|
$this->error = 2049;
|
|
|
return true;
|
|
|
}
|
|
|
@@ -912,11 +991,20 @@ class TradeService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
if (!$this->model->where(['id' => $id])->update(['status' => 4, 'is_sell' => 1, 'update_time' => time()])) {
|
|
|
+ DB::rollBack();
|
|
|
$this->error = 2054;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ if (!GoodsModel::where(['goods_id' => $info['goods_id']])->update(['confirm_status' => 2, 'update_time' => time()])) {
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = 2054;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
$this->error = 2055;
|
|
|
return true;
|
|
|
}
|
|
|
@@ -971,7 +1059,7 @@ class TradeService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (!GoodsModel::where(['id' => $info['goods_id']])->update(['last_sell_time'=>time(), 'price' => $price1+$addPrice,'real_price'=> $realPrice + $addPrice,'is_trade'=> 2, 'update_time' => time()])) {
|
|
|
+ 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, 'update_time' => time()])) {
|
|
|
$this->error = 2056;
|
|
|
DB::rollBack();
|
|
|
return false;
|
|
|
@@ -986,7 +1074,7 @@ class TradeService extends BaseService
|
|
|
}
|
|
|
// 停止拆分
|
|
|
else if($info['sell_price'] == $stopSplitPrice){
|
|
|
- if (!GoodsModel::where(['id' => $info['goods_id']])->update(['status' => 2,'split_stop'=>1, 'update_time' => time()])) {
|
|
|
+ if (!GoodsModel::where(['id' => $info['goods_id']])->update(['status' => 2,'confirm_status'=>1,'split_stop'=>1, 'update_time' => time()])) {
|
|
|
$this->error = 2054;
|
|
|
DB::rollBack();
|
|
|
return false;
|