first commit
This commit is contained in:
352
金壶/ydyd_service/application/common/service/UserService.php
Normal file
352
金壶/ydyd_service/application/common/service/UserService.php
Normal file
@@ -0,0 +1,352 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
|
||||
use app\api\controller\ApiController;
|
||||
use app\facade\AppConstant;
|
||||
use app\ydyd_service\model\BuyerModel;
|
||||
use app\ydyd_service\model\UserAddressModel;
|
||||
use app\ydyd_service\model\UserBankCardModel;
|
||||
use app\ydyd_service\model\UserCertificateModel;
|
||||
use app\ydyd_service\model\UsersModel;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\facade\Config;
|
||||
use think\facade\Log;
|
||||
|
||||
class UserService
|
||||
{
|
||||
public function checkAuth($params)
|
||||
{
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$buy = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->find();
|
||||
if (!$buy) {
|
||||
return 'authBaisc';
|
||||
}
|
||||
$count = UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", "buyer"]])->count();
|
||||
if (!$count) {
|
||||
return 'authCertificate';
|
||||
}
|
||||
$count = UserBankCardModel::where("user_id", "=", $params['user_id'])->count();
|
||||
if (!$count) {
|
||||
return 'authBank';
|
||||
}
|
||||
// $status = UsersModel::where("user_id", "=", $params['user_id'])->value('buyer_status');
|
||||
if($buy['verify_status'] == 0){
|
||||
return 'auditing';
|
||||
}
|
||||
if($buy['verify_status'] == 2){
|
||||
return 'waiting';
|
||||
}
|
||||
if($buy['verify_status'] == 1){
|
||||
return 'finish';
|
||||
}
|
||||
}
|
||||
|
||||
public function authBaisc($params)
|
||||
{
|
||||
try {
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
if (!isset($params['name']) || !$params['name'] || $params['name'] == 'undefined') {
|
||||
throw new Exception('企业名称不能为空');
|
||||
}
|
||||
if (!isset($params['sub_type']) || !$params['sub_type'] || $params['sub_type'] == 'undefined') {
|
||||
throw new Exception('请先选择企业类型');
|
||||
}
|
||||
if (!isset($params['consignee']) || !$params['consignee'] || $params['consignee'] == 'undefined') {
|
||||
throw new Exception('联系人不能为空');
|
||||
}
|
||||
if (!isset($params['phone']) || !$params['phone'] || $params['phone'] == 'undefined' || !is_numeric($params['phone']) || !is_mobile($params['phone'])) {
|
||||
throw new Exception('手机号码不正确');
|
||||
}
|
||||
if(isset($params['area_id']) && $params['area_id'] || $params['phone'] != 'area_id'){
|
||||
$area_id = explode("-",$params['area_id']);
|
||||
if(count($area_id) == 3){
|
||||
$params['area_id'] = $area_id[2];
|
||||
}
|
||||
}else{
|
||||
throw new Exception('注册区域不能为空');
|
||||
}
|
||||
if(isset($params['business_address']) && $params['business_address'] == 'undefined'){
|
||||
$params['business_address'] = '';
|
||||
}
|
||||
Db::startTrans();
|
||||
//buyer表部分
|
||||
$buy = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->find();
|
||||
$buyer_data['buyer_user_id'] = $params['user_id'];
|
||||
$buyer_data['name'] = $params['name'];
|
||||
$buyer_data['sub_type'] = $params['sub_type'];
|
||||
$buyer_data['business_address'] = $params['business_address'];
|
||||
$buyer_data['area_id'] = $params['area_id'];
|
||||
$buyer_data['consignee'] = $params['consignee'] ?? '';
|
||||
$buyer_data['tel'] = $params['phone'] ?? '';
|
||||
if ($buy) {
|
||||
$buyer_data['verify_status'] = 0;
|
||||
$buyer_data['business_address'] = $buyer_data['business_address'] ?? '';
|
||||
BuyerModel::where("buyer_user_id", "=", $params['user_id'])->update($buyer_data);
|
||||
if($buy['sub_type'] != $buyer_data['sub_type']){
|
||||
UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", "buyer"]])->delete();
|
||||
}
|
||||
} else {
|
||||
$apply_time_string = date('Y-m-d H:i:s', time());
|
||||
$to_insert_data = $buyer_data;
|
||||
$to_insert_data['apply_time'] = $apply_time_string;
|
||||
BuyerModel::create($buyer_data);
|
||||
UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", "buyer"]])->delete();
|
||||
}
|
||||
|
||||
//地址部分
|
||||
$usr_addr = Db::name("user_address")->where('user_id', $params['user_id'])->find();
|
||||
$addr_data['user_id'] = $params['user_id'];
|
||||
$addr_data['area_id'] = $params['area_id'];
|
||||
$addr_data['address'] = $params['business_address'] ?? '';
|
||||
$addr_data['consignee'] = $params['consignee'] ?? '';
|
||||
$addr_data['tel'] = $params['phone'] ?? '';
|
||||
if ($usr_addr) {
|
||||
UserAddressModel::where('user_id', $params['user_id'])->update($addr_data);
|
||||
} else {
|
||||
UserAddressModel::create($addr_data);
|
||||
}
|
||||
|
||||
//客服部分
|
||||
if (isset($params['service_number']) && $params['service_number']) {
|
||||
$cs_user_id = Db::name('admin_user')->where(['cs_code' => $params['service_number'], 'cs_status' => 1])->value('admin_user_id');
|
||||
if ($cs_user_id) {
|
||||
$update_data['custom_service_id'] = $cs_user_id;
|
||||
$update_data['custom_service_type'] = 2;
|
||||
$update_data['cs_assign_time'] = date('Y-m-d H:i:s',time());
|
||||
UsersModel::where(['user_id' => $params['user_id']])->update($update_data);
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function viewBaisc($params)
|
||||
{
|
||||
try {
|
||||
$ret = [];
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$count = Db::name('buyer')->where("buyer_user_id", "=", $params['user_id'])->count();
|
||||
if (!$count) {
|
||||
return $ret;
|
||||
}
|
||||
//buyer表部分
|
||||
$buyer_data = Db::name('buyer')->where("buyer_user_id", "=", $params['user_id'])
|
||||
->field('buyer_user_id,area_id,name,business_address,sub_type,consignee,tel')->find();
|
||||
if($buyer_data){
|
||||
if($buyer_data['business_address'] == 'undefined'){
|
||||
$buyer_data['business_address'] = '';
|
||||
}
|
||||
$ret = $buyer_data;
|
||||
$area_list = AppConstant::getAreaList();
|
||||
$area_name = [];
|
||||
if (isset($area_list[$buyer_data['area_id']]['grand_pa_id'])){
|
||||
$grand_pa_id = $area_list[$buyer_data['area_id']]['grand_pa_id'];
|
||||
$area_name[]['area_name'] = $area_list[$grand_pa_id]['area_name'];
|
||||
}
|
||||
if (isset($area_list[$buyer_data['area_id']]['parent_area_id'])){
|
||||
$parent_area_id = $area_list[$buyer_data['area_id']]['parent_area_id'];
|
||||
$area_name[]['area_name'] = $area_list[$parent_area_id]['area_name'];
|
||||
}
|
||||
$area_name[]['area_name'] = $area_list[$buyer_data['area_id']]['area_name'];
|
||||
$ret['area_name'] = $area_name;
|
||||
//客服部分
|
||||
$custom_service_id = Db::name('users')->where(['user_id' => $params['user_id']])->value('custom_service_id');
|
||||
$ret['service_number'] = Db::name('admin_user')->where(['admin_user_id' => $custom_service_id])->value('cs_code');
|
||||
$ret['service_number'] = $ret['service_number']?:'';
|
||||
}
|
||||
return $ret;
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function authCertificate($params)
|
||||
{
|
||||
try {
|
||||
// Log::error(json_encode($params));
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
if (!isset($params['role_type']) || !$params['role_type']) {
|
||||
throw new Exception('角色不能为空');
|
||||
}
|
||||
Db::startTrans();
|
||||
$sub_type = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->value('sub_type');
|
||||
$params['sub_type'] = $sub_type;
|
||||
// UserBankCardModel::where("user_id", "=", $params['user_id'])->delete();
|
||||
//UserCertificate表部分
|
||||
if (isset($params['sub_type'])) {
|
||||
$buyer_role_cert_info = Config::get('const.ROLE_CERT_INFO')['buyer']['sub_type'][$params['sub_type']]['certificate_list'];
|
||||
$add_data = [];
|
||||
UserCertificateModel::where("user_id", "=", $params['user_id'])->where("role_type", "=", $params['role_type'])->delete();
|
||||
foreach ($params as $k => $url) {
|
||||
if(isset($buyer_role_cert_info[$k])){
|
||||
// Log::error($k.':'.$url);
|
||||
$tmp = [];
|
||||
if ((!$url || $url=='undefined') && $buyer_role_cert_info[$k]) {
|
||||
$name = get_certificate_type_text($k);
|
||||
throw new Exception($name.'资质证明不能为空');
|
||||
}
|
||||
$url = str_replace('https://','',$url);
|
||||
$url = str_replace('http://','',$url);
|
||||
$tmp['user_id'] = $params['user_id'];
|
||||
$tmp['role_type'] = $params['role_type'];
|
||||
$tmp['certificate_type'] = $k;
|
||||
$tmp['img_url'] = $url;
|
||||
$add_data[] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($add_data) && $add_data) {
|
||||
$obj = new UserCertificateModel;
|
||||
$obj->saveAll($add_data);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function viewCertificate($params)
|
||||
{
|
||||
try {
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$sub_type = BuyerModel::where("buyer_user_id", "=", $params['user_id'])->value('sub_type');
|
||||
if(!$sub_type){
|
||||
return [];
|
||||
}
|
||||
$array = UserCertificateModel::where([["user_id", "=", $params['user_id']], ["role_type", "=", 'buyer']])->column('certificate_type,img_url');
|
||||
$list = Config::get('const.ROLE_CERT_INFO')['buyer']['sub_type'][$sub_type];
|
||||
if(!isset($list['certificate_list'])){
|
||||
throw new Exception('企业类型不存在');
|
||||
}
|
||||
$data = $list['certificate_list'];
|
||||
$ret = [];
|
||||
foreach ($data as $k=>$v)
|
||||
{
|
||||
$item = [];
|
||||
$item['value'] = $k;
|
||||
$item['name'] = get_certificate_type_text($k);
|
||||
$item['required'] = $v;
|
||||
$item['image'] = $item['required']?get_certificate_type_img($k):'';
|
||||
$item['path'] = [];
|
||||
if($array && isset($array[$k]) && $array[$k] && $array[$k] != 'undefined'){
|
||||
$item['path'][] = 'https://'.$array[$k];
|
||||
}
|
||||
$ret[] = $item;
|
||||
}
|
||||
return $ret;
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function authBank($params)
|
||||
{
|
||||
try {
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
Log::info('user_id:'.$params['user_id']);
|
||||
Log::info('json:'.json_encode($params));
|
||||
if (!isset($params['invoice_rise']) || !$params['invoice_rise']) {
|
||||
throw new Exception('发票抬头不能为空');
|
||||
}
|
||||
if($params['invoice_rise'] == 'undefined'){
|
||||
$params['invoice_rise'] = '';
|
||||
}
|
||||
if (!isset($params['tax_number']) || !$params['tax_number'] || $params['tax_number'] == 'undefined') {
|
||||
throw new Exception('纳税人识别码不能为空');
|
||||
}
|
||||
if (!isset($params['bank_name']) || !$params['bank_name'] || $params['bank_name'] == 'undefined') {
|
||||
throw new Exception('开户行不能为空');
|
||||
}
|
||||
if (!isset($params['bank_account']) || !$params['bank_account'] || $params['bank_account'] == 'undefined') {
|
||||
throw new Exception('对公账号不能为空');
|
||||
}
|
||||
Db::startTrans();
|
||||
UserBankCardModel::where("user_id", "=", $params['user_id'])->delete();
|
||||
//UserBank表部分
|
||||
$bank_data['user_id'] = $params['user_id'];
|
||||
$bank_data['bank_name'] = $params['bank_name'] ?? '';
|
||||
$bank_data['bank_account'] = $params['bank_account'] ?? '';
|
||||
// $bank_data['account_name'] = $params['account_name'] ?? '';
|
||||
$bank_data['create_time'] = date('Y-m-d H:i:s',time());
|
||||
$buy_data['invoice_title'] = $params['invoice_rise'];
|
||||
$buy_data['tax_number'] = $params['tax_number'];
|
||||
$buy_data['invoice'] = 2;
|
||||
Db::name('buyer')->where('buyer_user_id', "=", $params['user_id'])->update($buy_data);
|
||||
if (isset($bank_data) && $bank_data) {
|
||||
$obj = new UserBankCardModel;
|
||||
$obj->save($bank_data);
|
||||
|
||||
Db::name('users')->where('user_id', "=", $params['user_id'])->update(['buyer_status'=>2]);
|
||||
Db::name('buyer')->where('buyer_user_id', "=", $params['user_id'])->update(['verify_status'=>0]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (Exception $exception) {
|
||||
Db::rollback();
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function viewBank($params)
|
||||
{
|
||||
try {
|
||||
$ret['is_new'] = false;
|
||||
if (!isset($params['user_id']) || !$params['user_id']) {
|
||||
throw new Exception('用户不存在');
|
||||
}
|
||||
$count = UserBankCardModel::where("user_id", "=", $params['user_id'])->count();
|
||||
if (!$count) {
|
||||
$ret['is_new'] = true;
|
||||
return $ret;
|
||||
}
|
||||
$bank_data = Db::name('user_bank_card')->where("user_id", "=", $params['user_id'])->find();
|
||||
$buy_data = Db::name('buyer')->where('buyer_user_id', "=", $params['user_id'])->field('invoice_title,tax_number')->find();
|
||||
|
||||
if($bank_data && $buy_data){
|
||||
$ret = array_merge($bank_data,$buy_data);
|
||||
}
|
||||
return $ret;
|
||||
} catch (Exception $exception) {
|
||||
throw new Exception($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//修改密码
|
||||
public function editPassword($params)
|
||||
{
|
||||
try {
|
||||
//更新users表数据
|
||||
$secure_password_key = (string)mt_rand(100000, 999999);
|
||||
$adddata['password'] = md5($params['password'] . $secure_password_key);
|
||||
$adddata['secure_password_key'] = $secure_password_key;
|
||||
|
||||
$user_id = Db::name('users')->where('phone', $params['phone'])->update($adddata);
|
||||
Db::commit();
|
||||
return $user_id;
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user