测试版2.3.2发布
This commit is contained in:
@@ -5,6 +5,7 @@ use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\CustomerApply;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\CustomerTax;
|
||||
use Gdoo\User\Services\UserService;
|
||||
|
||||
class CustomerApplyHook
|
||||
{
|
||||
@@ -27,8 +28,12 @@ class CustomerApplyHook
|
||||
|
||||
public function onBeforeAudit($params) {
|
||||
$id = $params['id'];
|
||||
$apply = DB::table('customer_apply')->where('id', $id)
|
||||
|
||||
$apply = DB::table('customer_apply')
|
||||
->where('id', $id)
|
||||
->selectRaw('
|
||||
code,
|
||||
name,
|
||||
type_id,
|
||||
department_id,
|
||||
remark,
|
||||
@@ -39,7 +44,7 @@ class CustomerApplyHook
|
||||
city_id,
|
||||
county_id,
|
||||
address,
|
||||
name,
|
||||
status,
|
||||
warehouse_address,
|
||||
warehouse_contact,
|
||||
warehouse_phone,
|
||||
@@ -60,37 +65,32 @@ class CustomerApplyHook
|
||||
bank_address
|
||||
')->first();
|
||||
|
||||
// 新建用户
|
||||
$_user = [
|
||||
'role_id' => 2,
|
||||
'group_id' => 2,
|
||||
'username' => $apply['code'],
|
||||
'name' => $apply['name'],
|
||||
'department_id' => $apply['department_id'],
|
||||
'phone' => $apply['head_phone'],
|
||||
'password' => '123456',
|
||||
'status' => 1,
|
||||
];
|
||||
$user = UserService::updateData(0, $_user);
|
||||
$apply['user_id'] = $user->id;
|
||||
|
||||
// 新建客户
|
||||
$customer = new Customer;
|
||||
$customer->fill($apply);
|
||||
$customer->save();
|
||||
|
||||
// 新建用户
|
||||
$_user = [
|
||||
'role_id' => 2,
|
||||
'group_id' => 2,
|
||||
'username' => $customer['id'],
|
||||
'name' => $customer['name'],
|
||||
'department_id' => $customer['department_id'],
|
||||
'phone' => $customer['head_phone'],
|
||||
'password' => bcrypt('123456'),
|
||||
'status' => 1,
|
||||
];
|
||||
$user = new User;
|
||||
$user->fill($_user)->save();
|
||||
$customer['user_id'] = $user->id;
|
||||
|
||||
// 重新更新客户数据
|
||||
$customer->code = $customer['id'];
|
||||
$customer->save();
|
||||
|
||||
// 自动新建开票单位
|
||||
// 新建开票单位
|
||||
CustomerTax::insert([
|
||||
'code' => $customer->code,
|
||||
'name' => $customer->name,
|
||||
'customer_id' => $customer->id,
|
||||
'class_id' => $customer->class_id,
|
||||
'department_id' => $customer->department_id,
|
||||
'code' => $customer->code,
|
||||
'name' => $customer->name,
|
||||
'bank_name' => $apply['bank_name'],
|
||||
'tax_number' => $apply['tax_number'],
|
||||
'bank_account' => $apply['bank_account'],
|
||||
@@ -98,18 +98,11 @@ class CustomerApplyHook
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 回写申请的客户编码
|
||||
$_apply = CustomerApply::find($id);
|
||||
$_apply->code = $customer['code'];
|
||||
$_apply->save();
|
||||
|
||||
// 客户档案写入外部接口
|
||||
// 客户档案同步外部接口
|
||||
$department = DB::table('department')->where('id', $customer['department_id'])->first();
|
||||
$class = DB::table('customer_class')->where('id', $customer['class_id'])->first();
|
||||
$customer['class_code'] = $class['code'];
|
||||
$customer['department_code'] = $department['code'];
|
||||
$customer['headCode'] = $customer['code'];
|
||||
|
||||
$ret = plugin_sync_api('postCustomer', $customer);
|
||||
if ($ret['error_code'] > 0) {
|
||||
abort_error($ret['msg']);
|
||||
|
||||
@@ -4,6 +4,7 @@ use DB;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\CustomerTax;
|
||||
use Gdoo\User\Services\UserService;
|
||||
|
||||
class CustomerHook
|
||||
{
|
||||
@@ -18,28 +19,20 @@ class CustomerHook
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
$master = $params['master'];
|
||||
|
||||
|
||||
$_user = [
|
||||
'role_id' => 2,
|
||||
'group_id' => 2,
|
||||
'username' => $master['code'],
|
||||
'name' => $master['name'],
|
||||
'username' => $master['code'],
|
||||
'password' => $master['password'],
|
||||
'department_id' => $master['department_id'],
|
||||
'phone' => $master['head_phone'],
|
||||
'status' => $master['status'],
|
||||
];
|
||||
|
||||
// 更新用户表
|
||||
$user = User::findOrNew($master['user_id']);
|
||||
// 密码处理
|
||||
if (empty($master['password'])) {
|
||||
unset($master['password']);
|
||||
} else {
|
||||
$user['password'] = bcrypt($master['password']);
|
||||
$master['password'] = $user['password'];
|
||||
}
|
||||
$user->fill($_user)->save();
|
||||
$user = UserService::updateData($master['user_id'], $_user);
|
||||
$master['user_id'] = $user->id;
|
||||
|
||||
$params['master'] = $master;
|
||||
|
||||
return $params;
|
||||
@@ -47,39 +40,29 @@ class CustomerHook
|
||||
|
||||
public function onAfterStore($params) {
|
||||
$master = $params['master'];
|
||||
if (empty($master['code'])) {
|
||||
// 自动设置客户编码
|
||||
$customer = Customer::find($master['id']);
|
||||
$customer->code = $customer['id'];
|
||||
$customer->save();
|
||||
|
||||
// 自动设置用户名
|
||||
$user = User::find($customer['user_id']);
|
||||
$user->username = $customer['id'];
|
||||
$user->save();
|
||||
|
||||
// 客户开票单位为空
|
||||
$count = CustomerTax::where('customer_id', $master['id'])->count();
|
||||
if ($count == 0) {
|
||||
// 自动新建开票单位
|
||||
CustomerTax::insert([
|
||||
'customer_id' => $customer->id,
|
||||
'class_id' => $customer->class_id,
|
||||
'department_id' => $customer->department_id,
|
||||
'code' => $customer->code,
|
||||
'name' => $customer->name,
|
||||
'code' => $master['code'],
|
||||
'name' => $master['name'],
|
||||
'customer_id' => $master['id'],
|
||||
'class_id' => $master['class_id'],
|
||||
'department_id' => $master['department_id'],
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
// 客户档案写入外部接口
|
||||
$department = DB::table('department')->where('id', $master['department_id'])->first();
|
||||
$class = DB::table('customer_class')->where('id', $customer['class_id'])->first();
|
||||
$customer['class_code'] = $class['code'];
|
||||
$customer['department_code'] = $department['code'];
|
||||
$customer['headCode'] = $customer->code;
|
||||
$ret = plugin_sync_api('CustomerSync', $customer);
|
||||
if ($ret['success'] == true) {
|
||||
return $params;
|
||||
}
|
||||
abort_error($ret['msg']);
|
||||
}
|
||||
|
||||
// 客户档案同步外部接口
|
||||
$department = DB::table('department')->where('id', $master['department_id'])->first();
|
||||
$class = DB::table('customer_class')->where('id', $master['class_id'])->first();
|
||||
$master['class_code'] = $class['code'];
|
||||
$master['department_code'] = $department['code'];
|
||||
$ret = plugin_sync_api('postCustomer', $master);
|
||||
if ($ret['error_code'] > 0) {
|
||||
abort_error($ret['msg']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,32 +22,16 @@ class TaxHook
|
||||
|
||||
public function onAfterStore($params) {
|
||||
$master = $params['master'];
|
||||
if (empty($master['code'])) {
|
||||
// 自动设置开票编码
|
||||
$customer = Customer::find($master['customer_id']);
|
||||
$code = $customer['code'];
|
||||
$max_id = (int)$customer['tax_max_id'] + 1;
|
||||
|
||||
// 更新开票单位code
|
||||
$tax = CustomerTax::find($master['id']);
|
||||
$tax->code = $code.$max_id;
|
||||
$tax->save();
|
||||
|
||||
$customer->tax_max_id = $max_id;
|
||||
$customer->save();
|
||||
|
||||
// 客户档案写入外部接口
|
||||
$department = DB::table('department')->where('id', $tax['department_id'])->first();
|
||||
$class = DB::table('customer_class')->where('id', $tax['class_id'])->first();
|
||||
$tax['class_code'] = $class['code'];
|
||||
$tax['department_code'] = $department['code'];
|
||||
$tax['headCode'] = $customer->code;
|
||||
$ret = plugin_sync_api('CustomerSync', $tax);
|
||||
if ($ret['success'] == true) {
|
||||
return $params;
|
||||
}
|
||||
// 开票单位同步外部接口
|
||||
$department = DB::table('department')->where('id', $master['department_id'])->first();
|
||||
$class = DB::table('customer_class')->where('id', $master['class_id'])->first();
|
||||
$master['class_code'] = $class['code'];
|
||||
$master['department_code'] = $department['code'];
|
||||
$ret = plugin_sync_api('postTax', $master);
|
||||
if ($ret['error_code'] > 0) {
|
||||
abort_error($ret['msg']);
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user