|
@@ -16,8 +16,11 @@ use app\model\Order;
|
|
|
use app\model\OrderSheet;
|
|
|
use app\model\PayDetail;
|
|
|
use app\model\SysCategory;
|
|
|
+use app\model\SysDept;
|
|
|
use app\model\SysSerial;
|
|
|
+use app\model\SysUser;
|
|
|
use support\Db;
|
|
|
+use support\exception\BusinessException;
|
|
|
use support\Request;
|
|
|
|
|
|
class MemberService
|
|
@@ -127,11 +130,21 @@ class MemberService
|
|
|
}
|
|
|
|
|
|
$row['source'] = "APP";
|
|
|
+ $row['belong'] = [];
|
|
|
if (!empty($row['member_extend_json'])) {
|
|
|
$extendJson = json_decode($row['member_extend_json'], true);
|
|
|
if (isset($extendJson['come_from'])) {
|
|
|
$row['source'] = $extendJson['come_from'] ?? '';
|
|
|
}
|
|
|
+ if (isset($extendJson['belong'])){
|
|
|
+ $user = SysUser::where('user_id',$extendJson['belong']['user_id'])->select('user_name','user_mobile')->first();
|
|
|
+ if($user){
|
|
|
+ $row['belong']['user_id'] = $extendJson['belong']['user_id'];
|
|
|
+ $row['belong']['username'] = $user->user_name;
|
|
|
+ $row['belong']['user_mobile'] = $user->user_mobile;
|
|
|
+ }
|
|
|
+ $row['belong']['deptName'] = SysDept::where('dept_id',$extendJson['belong']['premises'])->value('dept_name');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -441,14 +454,25 @@ class MemberService
|
|
|
// 先写主表,要ID
|
|
|
$memberData = [
|
|
|
'member_id' => $memberId,
|
|
|
- 'member_is_owner' => $params['is_owner'],
|
|
|
- 'member_classify' => $params['classify'],
|
|
|
- 'member_status' => $params['status'],
|
|
|
- 'member_mobile' => $params['mobile'],
|
|
|
+ 'member_is_owner' => $params['is_owner'] ?? 'N',
|
|
|
+ 'member_classify' => $params['classify'] ?? '',
|
|
|
+ 'member_status' => $params['status'] ?? 'ISABLED',
|
|
|
+ 'member_mobile' => $params['mobile'] ?? '',
|
|
|
// 'member_from' => $params['source'],
|
|
|
- 'member_extend_json' => json_encode(['come_from' => $params['source']]),
|
|
|
+ // 'member_extend_json' => json_encode(['come_from' => $params['source']]),
|
|
|
'member_addtimes' => time(),
|
|
|
];
|
|
|
+
|
|
|
+ $extendJson['come_from'] = $params['source'];
|
|
|
+ if(!empty($params['user_id'])){
|
|
|
+ $deptId = SysUser::where('user_id',$params['user_id'])->value('join_user_dept_id');
|
|
|
+ if(!$deptId){
|
|
|
+ throw new BusinessException('请先关联业务员和门店');
|
|
|
+ }
|
|
|
+ $extendJson['belong'] = ['user_id'=>$params['user_id'],'premises'=>$deptId];
|
|
|
+ }
|
|
|
+ $memberData['member_extend_json'] = json_encode($extendJson);
|
|
|
+
|
|
|
Member::insert($memberData);
|
|
|
|
|
|
// 账户表
|
|
@@ -475,9 +499,9 @@ class MemberService
|
|
|
'member_cert_nation' => $params['member_cert_nation'] ?? '',
|
|
|
'member_cert_name' => $params['cert_name'] ?? '',
|
|
|
'member_cert_nbr' => $params['cert_nbr'] ?? '',
|
|
|
- 'member_cert_birth' => $params['birth'] ? date('Y-m-d', strtotime($params['birth'])) : '',
|
|
|
+ 'member_cert_birth' => !empty($params['birth']) ? date('Y-m-d', strtotime($params['birth'])) : '',
|
|
|
'member_cert_gender' => $params['gender'] ?? '',
|
|
|
- 'member_cert_province' => $params['province'] ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
|
|
|
+ 'member_cert_province' => !empty($params['province']) ? json_encode($params['province'], JSON_UNESCAPED_UNICODE) : '[]',
|
|
|
'member_cert_city' => $params['city'] ?? '',
|
|
|
'member_cert_addr' => $params['addr'] ?? '',
|
|
|
// 'member_cert_face' => str_replace(getenv('STORAGE_DOMAIN'), '', $params['member_cert_face']),
|
|
@@ -487,12 +511,16 @@ class MemberService
|
|
|
// member info
|
|
|
$infoData = [
|
|
|
'join_info_member_id' => $memberId,
|
|
|
- 'member_info_nickname' => $params['account_name'],
|
|
|
- 'member_info_headimg' => getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar'])
|
|
|
+ 'member_info_nickname' => $params['account_name'] ?? '',
|
|
|
+ 'member_info_headimg' => !empty($params['avatar']) ? getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']) : ''
|
|
|
];
|
|
|
MemberInfo::insert($infoData);
|
|
|
|
|
|
Db::commit();
|
|
|
+ }catch(BusinessException $e){
|
|
|
+ Db::rollBack();
|
|
|
+
|
|
|
+ return json_fail($e->getMessage());
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollBack();
|
|
|
dump($e->getMessage() . ';line:' . $e->getLine());
|
|
@@ -524,6 +552,14 @@ class MemberService
|
|
|
$extendJson = json_decode($member->member_extend_json, true);
|
|
|
}
|
|
|
$extendJson['come_from'] = $params['source'];
|
|
|
+ // 门店、业务员
|
|
|
+ if(!empty($params['user_id'])){
|
|
|
+ $deptId = SysUser::where('user_id',$params['user_id'])->value('join_user_dept_id');
|
|
|
+ if(!$deptId){
|
|
|
+ throw new BusinessException('请先关联业务员和门店');
|
|
|
+ }
|
|
|
+ $extendJson['belong'] = ['user_id'=>$params['user_id'],'premises'=>$deptId];
|
|
|
+ }
|
|
|
// 先写主表,要ID
|
|
|
$memberData = [
|
|
|
'member_id' => $memberId,
|
|
@@ -534,6 +570,7 @@ class MemberService
|
|
|
// 'member_from' => $params['source'],
|
|
|
'member_extend_json' => json_encode($extendJson)
|
|
|
];
|
|
|
+
|
|
|
Member::where('member_id', $params['member_id'])->update($memberData);
|
|
|
// member cert
|
|
|
$certData = [
|
|
@@ -555,9 +592,10 @@ class MemberService
|
|
|
MemberCert::where('join_cert_member_id', $params['member_id'])->update($certData);
|
|
|
}
|
|
|
// member info
|
|
|
- if (strpos($params['avatar'], getenv('APP_IMAGE_DOMAIN')) !== false || strpos($params['avatar'], getenv('SYSTEM_AVATAR_DOMAIN')) !== false) {
|
|
|
+ $avatar = '';
|
|
|
+ if ($params['avatar'] && (strpos($params['avatar'], getenv('APP_IMAGE_DOMAIN')) !== false || strpos($params['avatar'], getenv('SYSTEM_AVATAR_DOMAIN')) !== false)) {
|
|
|
$avatar = $params['avatar'];
|
|
|
- } else {
|
|
|
+ } else if($params['avatar']) {
|
|
|
$avatar = getenv('SYSTEM_AVATAR_DOMAIN') . str_replace(getenv('STORAGE_DOMAIN'), '', $params['avatar']);
|
|
|
}
|
|
|
|