APPLE 3 лет назад
Родитель
Сommit
a347d41ccc

+ 37 - 0
app/Http/Controllers/Admin/AccountController.php

@@ -12,6 +12,7 @@
 namespace App\Http\Controllers\Admin;
 
 
+use App\Http\Validator\AccountValidator;
 use App\Services\Common\AccountService;
 use App\Services\Common\FinanceService;
 
@@ -49,4 +50,40 @@ class AccountController extends Backend
         );
         return $message;
     }
+
+    /**
+     * 调整佣金
+     * @param AccountValidator $validator
+     * @return array
+     */
+    public function changeBonus(AccountValidator $validator)
+    {
+        // 获取参数
+        $params = $validator->check(request()->all(), 'change');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+
+        if(!AccountService::make()->changeBonus($params)){
+            return message(AccountService::make()->getError(), true);
+        }else{
+            return message(AccountService::make()->getError(), false);
+        }
+    }
+
+    // 调整积分
+    public function changeScore(AccountValidator $validator)
+    {
+        // 获取参数
+        $params = $validator->check(request()->all(), 'change');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+
+        if(!AccountService::make()->changeScore($params)){
+            return message(AccountService::make()->getError(), true);
+        }else{
+            return message(AccountService::make()->getError(), false);
+        }
+    }
 }

+ 48 - 0
app/Http/Validator/AccountValidator.php

@@ -0,0 +1,48 @@
+<?php
+namespace App\Http\Validator;
+class AccountValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'user_id'=> 'required|min:1|max:10',
+        'money'=> 'required',
+        'type'=> 'required',
+    ];
+
+    // 当前模型所有错误提示信息
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'user_id' => '用户ID',
+        'money' => '金额',
+        'type' => '操作类型',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'info'=> ['id'],
+        'change'=> ['user_id','money','type'],
+        'del'=> ['id'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 123 - 0
app/Services/Common/AccountService.php

@@ -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;
+    }
 }

+ 1 - 1
app/Services/Common/FinanceService.php

@@ -112,7 +112,7 @@ class FinanceService extends BaseService
      * 平台结算
      * @param $money
      * @param int $changeType
-     * @param int $type
+     * @param int $type 类型:1-增加,2-扣除
      * @return mixed
      */
     public function settleBonus($money, $changeType = 1, $type = 1)

+ 2 - 7
app/Services/Common/GoodsService.php

@@ -116,7 +116,7 @@ class GoodsService extends BaseService
             foreach ($list['data'] as &$item) {
                 $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
                 $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
-                $item['real_price'] = round($item['price'] - $item['sell_price'] + $item['source_price']);
+//                $item['real_price'] = round($item['price'] - $item['sell_price'] + $item['source_price']);
             }
         }
 
@@ -171,7 +171,6 @@ class GoodsService extends BaseService
                 $item['create_time'] = $item['create_time'] ? datetime($item['create_time'], 'Y-m-d H:i:s') : '';
                 $item['confirm_time'] = $item['confirm_time'] ? datetime($item['confirm_time'], 'Y-m-d H:i:s') : '';
                 $item['thumb'] = isset($item['thumb']) && $item['thumb'] ? get_image_url($item['thumb']) : '';
-
             }
         }
 
@@ -208,11 +207,7 @@ class GoodsService extends BaseService
             $data['price'] = $data['sell_price'];
         }
 
-        if (!isset($data['real_price']) || empty($data['real_price'])) {
-            $data['real_price'] = ($data['price']-$data['sell_price']+$data['source_price']);
-        }
-
-//
+        $data['real_price'] = ($data['price']-$data['sell_price']+$data['source_price']);
 //        $feeRate = ConfigService::make()->getConfigByCode('sell_fee_rate');
 //        $feeRate = $feeRate? $feeRate : '2.5';
 //        $data['fee'] = round($data['price'] * $feeRate/100, 0);