43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\user;
|
|
|
|
use app\api\controller\BaseApiController;
|
|
use app\common\model\user\User;
|
|
use app\common\model\user\UserBalance;
|
|
use app\common\validate\user\UserBalanceValidate;
|
|
use think\facade\Log;
|
|
use think\response\Json;
|
|
|
|
class UserBalanceController extends BaseApiController
|
|
{
|
|
public array $notNeedLogin = ['addBalanceRecord'];
|
|
public function addBalanceRecord(): Json
|
|
{
|
|
// 获取参数
|
|
$params = (new UserBalanceValidate())->post()->goCheck('add');
|
|
// 添加数据
|
|
try {
|
|
$result = UserBalance::create([
|
|
'user_id' => $params['user_id'],
|
|
'record_id' => $params['record_id'],
|
|
'record_table' => $params['record_table'],
|
|
'amount' => $params['amount'],
|
|
'type' => $params['type'],
|
|
'pay_type' => $params['pay_type'],
|
|
'mark' => $params['mark'],
|
|
'appid' => $this->request->header('appid'),
|
|
'create_time' => time(),
|
|
]);
|
|
if(!empty($result->id)){
|
|
return $this->success('添加成功');
|
|
}else{
|
|
return $this->fail('添加失败');
|
|
}
|
|
}catch (\Exception $e) {
|
|
//记录日志
|
|
Log::error($e->getMessage());
|
|
return $this->fail('系统错误');
|
|
}
|
|
}
|
|
} |