From d8bc3150f291bd3f7abf6ba8e936daff8be8366f Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 2 Aug 2023 15:59:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=90=88=E5=90=8C=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/UserController.php | 30 ++++- app/common/logic/UserLogic.php | 187 ++++++++++++++++++++++++++ 2 files changed, 214 insertions(+), 3 deletions(-) create mode 100755 app/common/logic/UserLogic.php diff --git a/app/api/controller/UserController.php b/app/api/controller/UserController.php index a42ebff45..152948d5b 100755 --- a/app/api/controller/UserController.php +++ b/app/api/controller/UserController.php @@ -15,9 +15,12 @@ namespace app\api\controller; use app\api\logic\UserLogic; +use app\common\logic\UserLogic as CommonUserLogic; use app\api\validate\PasswordValidate; use app\api\validate\SetUserInfoValidate; use app\api\validate\UserValidate; +use Common; +use think\facade\Db; /** * 用户控制器 @@ -138,7 +141,7 @@ class UserController extends BaseApiController $params = (new UserValidate())->post()->goCheck('bindMobile'); $params['user_id'] = $this->userId; $result = UserLogic::bindMobile($params); - if($result) { + if ($result) { return $this->success('绑定成功', [], 1, 1); } return $this->fail(UserLogic::getError()); @@ -149,7 +152,7 @@ class UserController extends BaseApiController $params = $this->request->param(); $params['user_id'] = $this->userId; $result = UserLogic::withdraw($params); - if($result) { + if ($result) { return $this->success('提现申请已提交', [], 1, 1); } return $this->fail(UserLogic::getError()); @@ -162,4 +165,25 @@ class UserController extends BaseApiController return $this->success('success', ['count' => $count, 'data' => $list]); } -} \ No newline at end of file + //**发起合同 */ + public function initiate_contract() + { + $params = $this->request->param(); + $admin_id=Db::name('user')->where('id',$this->userId)->value('admin_id'); + $result = CommonUserLogic::initiate_contract($params,$admin_id); + if($result==true){ + return $this->success('发起成功,等待平台风控部上传合同'); + } + return $this->fail(CommonUserLogic::getError()); + } + // /**生成合同 */ + public function Draftingcontracts() + { + $params = $this->request->param(); + $result = CommonUserLogic::Draftingcontracts($params); + if($result==true){ + return $this->success('生成合同成功'); + } + return $this->fail(CommonUserLogic::getError()); + } +} diff --git a/app/common/logic/UserLogic.php b/app/common/logic/UserLogic.php new file mode 100755 index 000000000..0e5ed5987 --- /dev/null +++ b/app/common/logic/UserLogic.php @@ -0,0 +1,187 @@ + $userId]) + ->findOrEmpty(); + + $user['channel'] = UserTerminalEnum::getTermInalDesc($user['channel']); + // $user->sex = $user->getData('sex'); + $user['qualification'] = json_decode($user->qualification, true); + if ($user->is_contract == 1) { + $user['contract'] = Contract::where(['type' => 2, 'party_b' => $userId])->with(['partyA', 'contractType'])->find(); + } + return $user->toArray(); + } + + + /** + * @notes 更新用户信息 + * @param array $params + * @return User + * @author 段誉 + * @date 2022/9/22 16:38 + */ + public static function setUserInfo(array $params) + { + return User::update([ + 'id' => $params['id'], + $params['field'] => $params['value'] + ]); + } + + + /** + * @notes 调整用户余额 + * @param array $params + * @return bool|string + * @author 段誉 + * @date 2023/2/23 14:25 + */ + public static function adjustUserMoney(array $params) + { + Db::startTrans(); + try { + $user = User::find($params['user_id']); + if (AccountLogEnum::INC == $params['action']) { + //调整可用余额 + $user->user_money += $params['num']; + $user->save(); + //记录日志 + AccountLogLogic::add( + $user->id, + AccountLogEnum::UM_INC_ADMIN, + AccountLogEnum::INC, + $params['num'], + '', + $params['remark'] ?? '' + ); + } else { + $user->user_money -= $params['num']; + $user->save(); + //记录日志 + AccountLogLogic::add( + $user->id, + AccountLogEnum::UM_DEC_ADMIN, + AccountLogEnum::DEC, + $params['num'], + '', + $params['remark'] ?? '' + ); + } + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + return $e->getMessage(); + } + } + //**发起合同 */ + public static function initiate_contract($params, $adminId) + { + $params['party_a'] = Db::name('company')->where('admin_id', $adminId)->value('id'); + if ($params['party_a'] <= 0) { + return self::setError('甲方不存在,请联系平台绑定公司'); + } + $params['check_status'] = 1; + $res = Contract::Initiate_contract($params); + if (true === $res) { + return true; + } + return self::setError('发起失败'); + } + + // /**生成合同 */ + public static function Draftingcontracts($params) + { + + $result = self::detail($params['id']); + if ($result && $result['contract'] && $result['contract']['file'] != '') { + $data = [ + 'name' => $result['nickname'] . '的合同', + 'signatories' => [['fullName' => $result['nickname'], 'identityType' => 1, 'identityCard' => $result['id_card'], 'mobile' => $result['mobile'], 'noNeedVerify' => 1, 'signLevel' => 1]], + 'url' => $result['contract']['file'] + ]; + $res = app(JunziqianController::class)->Signing($data, $result['contract']['id']); + if ($res->success == true) { + Db::name('contract')->where('id', $result['contract']['id'])->update(['contract_no' => $res->data]); + $data = array( + "applyNo" => $res->data, //TODO * + "fullName" => $result['nickname'], //TODO * + "identityCard" => $result['id_card'], //TODO * + "identityType" => 1, //TODO * + ); + $res = app(JunziqianController::class)->SigningLink($data); + if ($res->success == true) { + Db::name('contract')->where('id', $result['contract']['id'])->update(['url' => $res->data]); + //发送短信 + $sms = [ + 'mobile' => $result['mobile'], + 'name' => $result['nickname'], + 'type' => '《' . $result['contract']['contract_type_name'] . '》', + 'code' => 'api/Hetong/url?id=' . $result['contract']['id'], + 'scene' => 'WQ' + ]; + $result = SmsLogic::contractUrl($sms); + if (true === $result) { + return true; + } else { + return self::setError(SmsLogic::getError()); + } + } else { + return self::setError($res->msg); + } + } else { + return self::setError($res->msg); + } + } else { + return self::setError('生成合同成功失败,联系管理员'); + } + } +}