|
|
@@ -12,7 +12,9 @@
|
|
|
namespace App\Services\Common;
|
|
|
|
|
|
use App\Models\AccountModel;
|
|
|
+use App\Models\MemberModel;
|
|
|
use App\Services\BaseService;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 交易管理-服务类
|
|
|
@@ -182,4 +184,125 @@ class AccountService extends BaseService
|
|
|
->count('id');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 调整用户佣金
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function changeBonus($params)
|
|
|
+ {
|
|
|
+ $userId = isset($params['user_id'])? $params['user_id']:0;
|
|
|
+ $money = isset($params['money'])? $params['money']:0;
|
|
|
+ $type = isset($params['type'])? $params['type']:0;
|
|
|
+
|
|
|
+ $userInfo = MemberModel::where(['id'=> $userId,'mark'=>1])->select(['id','login_shop_id','bonus','bonus_total'])->first();
|
|
|
+ $bonus = isset($userInfo['bonus'])? $userInfo['bonus'] : 0;
|
|
|
+ $bonusTotal = isset($userInfo['bonus_total'])? $userInfo['bonus_total'] : 0;
|
|
|
+ if(empty($userInfo)){
|
|
|
+ $this->error = '2201';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 扣除佣金验证
|
|
|
+ if($type == 2 && $money > $bonus){
|
|
|
+ $this->error = '2202';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理
|
|
|
+ DB::beginTransaction();
|
|
|
+ $money = $type==1? $money : -$money;
|
|
|
+ $data = ['bonus'=> max(0, $bonus+$money), 'bonus_total'=> max(0, $bonusTotal+$money),'update_time'=>time()];
|
|
|
+ if(MemberModel::where(['id'=> $userId,'mark'=>1])->update($data)){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = '2203';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $logData = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'shop_id'=> $userInfo['login_shop_id'],
|
|
|
+ 'type'=> 3,
|
|
|
+ 'coin_type'=> 2,
|
|
|
+ 'money'=> $money,
|
|
|
+ 'balance'=> $bonus,
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'remark'=> '佣金调整',
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=>1
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!AccountModel::insertGetId($logData)) {
|
|
|
+ $this->error = 2204;
|
|
|
+ DB::rollBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+
|
|
|
+ // 结算统计
|
|
|
+ FinanceService::make()->settleBonus($bonus, 2);
|
|
|
+
|
|
|
+ $this->error = 2205;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调整用户积分
|
|
|
+ * @param $params
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function changeScore($params)
|
|
|
+ {
|
|
|
+ $userId = isset($params['user_id'])? $params['user_id']:0;
|
|
|
+ $money = isset($params['money'])? $params['money']:0;
|
|
|
+ $type = isset($params['type'])? $params['type']:0;
|
|
|
+
|
|
|
+ $userInfo = MemberModel::where(['id'=> $userId,'mark'=>1])->select(['id','login_shop_id','score'])->first();
|
|
|
+ $score = isset($userInfo['score'])? $userInfo['score'] : 0;
|
|
|
+ if(empty($userInfo)){
|
|
|
+ $this->error = '2201';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 扣除积分验证
|
|
|
+ if($type == 2 && $money > $score){
|
|
|
+ $this->error = '2212';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理
|
|
|
+ DB::beginTransaction();
|
|
|
+ $money = $type==1? $money : -$money;
|
|
|
+ $data = ['score'=> max(0, $score+$money),'update_time'=>time()];
|
|
|
+ if(MemberModel::where(['id'=> $userId,'mark'=>1])->update($data)){
|
|
|
+ DB::rollBack();
|
|
|
+ $this->error = '2213';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $logData = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'shop_id'=> $userInfo['login_shop_id'],
|
|
|
+ 'type'=> 3,
|
|
|
+ 'coin_type'=> 3,
|
|
|
+ 'money'=> $money,
|
|
|
+ 'balance'=> $score,
|
|
|
+ 'create_time'=> time(),
|
|
|
+ 'remark'=> '积分调整',
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=>1
|
|
|
+ ];
|
|
|
+
|
|
|
+ if (!AccountModel::insertGetId($logData)) {
|
|
|
+ $this->error = 2214;
|
|
|
+ DB::rollBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ $this->error = 2215;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|