Просмотр исходного кода

Wesmiler 人人车 初始化项目 0816

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

+ 0 - 1
application/admin/controller/taxi/User.php

@@ -67,7 +67,6 @@ class User extends AdminController
      * @author weichuanbao<654745815@qq.com>
      * @date 2022/1/7 0007
      */
-     
     public function partnership($ids)
     {
         $row = $this->model->with('user')->find($ids);

+ 7 - 3
application/api/controller/v1/Taxi.php

@@ -4,6 +4,7 @@
 namespace app\api\controller\v1;
 
 use app\api\controller\ApiController;
+use app\api\model\taxi\MotorRecord;
 use app\api\service\SmsCode;
 use app\common\validate\IDMustBePositiveInt;
 use EasyWeChat\Factory;
@@ -379,10 +380,11 @@ class Taxi extends ApiController
 
                     // 退款扣除金额直接给司机
                     if($taxiUserId && $cost_price>0){
-                        model('common/Users')->changeBalance(
+                        model('common/Users')->changePartnership(
                             $taxiUserId,
                             $cost_price,
                             "取消成功,扣除用户金额到账【" . $cost_price . "】",
+                            30,
                             true
                         );
                     }
@@ -396,10 +398,11 @@ class Taxi extends ApiController
 
                     // 退款扣除金额直接给司机
                     if($taxiUserId && $cost_price>0){
-                        model('common/Users')->changeBalance(
+                        model('common/Users')->changePartnership(
                             $taxiUserId,
                             $cost_price,
                             "取消成功,扣除用户金额到账【" . $cost_price . "】",
+                            30,
                             true
                         );
                     }
@@ -434,10 +437,11 @@ class Taxi extends ApiController
                     else {
                         // 退款扣除金额直接给司机
                         if($taxiUserId && $cost_price>0){
-                            model('common/Users')->changeBalance(
+                            model('common/Users')->changePartnership(
                                 $taxiUserId,
                                 $cost_price,
                                 "取消成功,扣除用户金额到账【" . $cost_price . "】",
+                                30,
                                 true
                             );
                         }

+ 2 - 2
application/api/controller/v1/Wechat.php

@@ -758,7 +758,7 @@ class Wechat extends ApiController
     
         // 检查用户余额
         $user = $this->auth->user();
-        var_dump($user);
+
         if ($user[$payType] < $paylog['total_price']) {
             return $this->ApiJson(-1, '支付失败,账户余额不足!');
         }
@@ -806,7 +806,7 @@ class Wechat extends ApiController
 //                    $thing7 = '电话请保持通畅,师傅正在赶往路上,请稍候';
 
                     // 订单结算给摩的代理
-                    model('\app\api\model\taxi\Award')->send($goodsOrder);
+                    //model('\app\api\model\taxi\Award')->send($goodsOrder);
                     break;
                 // 技能订单
                 case "skill":

+ 1 - 1
application/api/model/taxi/Award.php

@@ -28,7 +28,7 @@ class Award extends BaseModel
                 ])
                 ->where('area_id', $order['area_id'])
                 ->find();
-            if ($motorAgent) {
+            if ($motorAgent && $motorAgent->user) {
                 $money = bcmul($order['price'], $percent/100, 2);
                 $motorAgent->user->motor_agent_money += $money;
                 $motorAgent->user->save();

+ 48 - 0
application/common/model/Users.php

@@ -3,6 +3,7 @@
 
 namespace app\common\model;
 
+use app\api\model\taxi\MotorRecord;
 use app\common\model\UsersBalanceRecord;
 
 class Users extends BaseModel
@@ -120,4 +121,51 @@ class Users extends BaseModel
             $this->rollback();
         }
     }
+
+    /**
+     * 用户资金变动
+     *
+     * @author 许祖兴 < zuxing.xu@lettered.cn>
+     * @date 2020/7/14 10:34
+     *
+     * @param int $userId 用户ID
+     * @param float $amount 变动金额
+     * @param string $remark 备注说明
+     * @param string $type 类型:10-分红,20-提现,30-资产司机收入
+     * @param bool $inc 是否增长
+     * @throws \think\exception\PDOException
+     */
+    public function changePartnership($userId,$amount, $remark = "", $type=30, $inc = false)
+    {
+        $action = $inc ? 'setInc' : 'setDec';
+        $this->startTrans();
+        try {
+            // 查余额
+            $user = $this->lock(true)->where(['id' => $userId])->find();
+            // 资金变动
+            $this->where(['id' => $userId])->{$action}('partnership',$amount);
+            // 记录写入
+            $data = [
+                'type' => $type,
+                'money' => $amount,
+                'user_id' => $userId,
+                'tag' => $inc ? 10 : 20,
+                'created_at' => time(),
+                'updated_at' => time(),
+                'memo' => $remark
+            ];
+            // 加减
+            if ($inc){
+                $data['before'] = $user['partnership'];
+                $data['after'] = sprintf("%.2f", round($user['partnership'] + $amount, 2));
+            }else{
+                $data['before'] = $user['partnership'];
+                $data['after'] = sprintf("%.2f", round($user['partnership'] - $amount, 2));
+            }
+            MotorRecord::create($data,true);
+            $this->commit();
+        }catch (\Exception $e){
+            $this->rollback();
+        }
+    }
 }

+ 1 - 1
public/manage/pages/users/motor_agent/index.html

@@ -193,7 +193,7 @@
             cols: [[
                 {type: 'checkbox'},
                 {field: 'user', title: '用户昵称', width: 130, templet: function (d) {
-                        return d.user.nickname;
+                        return d.user? d.user.nickname : '';
                     }},
                 {field: 'username', title: '用户名', width: 100},
                 {field: 'mobile', title: '手机号', width: 150},