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