创建版本
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use Validator;
|
||||
use DB;
|
||||
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\Contact;
|
||||
|
||||
class ContactHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
$master = $params['master'];
|
||||
|
||||
$_user = [
|
||||
'role_id' => 95,
|
||||
'group_id' => 3,
|
||||
'username' => $master['code'],
|
||||
'name' => $master['name'],
|
||||
'phone' => $master['phone'],
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
$v = Validator::make($_user, [
|
||||
'username' => 'unique:user,username,'.$master['user_id']
|
||||
], [], ['username' => '编码']);
|
||||
if ($v->fails()) {
|
||||
abort_error($v->errors()->first('username'));
|
||||
}
|
||||
|
||||
// 更新用户表
|
||||
$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();
|
||||
$master['user_id'] = $user->id;
|
||||
$params['master'] = $master;
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterStore($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
$ids = $params['ids'];
|
||||
$userIds = Contact::whereIn('id', $ids)->pluck('user_id');
|
||||
User::whereIn('id', $userIds)->delete();
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\CustomerApply;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\CustomerTax;
|
||||
|
||||
class CustomerApplyHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterStore($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeAudit($params) {
|
||||
$id = $params['id'];
|
||||
$apply = DB::table('customer_apply')->where('id', $id)
|
||||
->selectRaw('
|
||||
type_id,
|
||||
department_id,
|
||||
remark,
|
||||
region_id,
|
||||
class_id,
|
||||
class2_id,
|
||||
province_id,
|
||||
city_id,
|
||||
county_id,
|
||||
address,
|
||||
name,
|
||||
warehouse_address,
|
||||
warehouse_contact,
|
||||
warehouse_phone,
|
||||
warehouse_tel,
|
||||
warehouse_size,
|
||||
head_name,
|
||||
head_phone,
|
||||
manage_name,
|
||||
manage_phone,
|
||||
manage_weixin,
|
||||
finance_name,
|
||||
finance_phone,
|
||||
cost_name,
|
||||
cost_phone,
|
||||
tax_number,
|
||||
bank_name,
|
||||
bank_account,
|
||||
bank_address
|
||||
')->first();
|
||||
|
||||
// 自动处理区域
|
||||
if ($apply['region_id']) {
|
||||
$regions = DB::table('customer_region')->get()->keyBy('id');
|
||||
$region1 = $regions[$apply['region_id']];
|
||||
$region2 = $regions[$region1['parent_id']];
|
||||
$region3 = $regions[$region2['parent_id']];
|
||||
$apply['region2_id'] = $region2['id'];
|
||||
$apply['region3_id'] = $region3['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([
|
||||
'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'],
|
||||
'bank_address' => $apply['bank_address'],
|
||||
'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('CustomerSync', $customer);
|
||||
if ($ret['success'] == true) {
|
||||
return $params;
|
||||
}
|
||||
abort_error($ret['msg']);
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\CustomerTax;
|
||||
|
||||
class CustomerHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
$master = $params['master'];
|
||||
|
||||
$_user = [
|
||||
'role_id' => 2,
|
||||
'group_id' => 2,
|
||||
'username' => $master['code'],
|
||||
'name' => $master['name'],
|
||||
'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();
|
||||
$master['user_id'] = $user->id;
|
||||
|
||||
// 自动处理区域
|
||||
if ($master['region_id']) {
|
||||
$regions = DB::table('customer_region')->get()->keyBy('id');
|
||||
$region1 = $regions[$master['region_id']];
|
||||
$region2 = $regions[$region1['parent_id']];
|
||||
$region3 = $regions[$region2['parent_id']];
|
||||
$master['region2_id'] = $region2['id'];
|
||||
$master['region3_id'] = $region3['id'];
|
||||
}
|
||||
$params['master'] = $master;
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// 自动新建开票单位
|
||||
CustomerTax::insert([
|
||||
'customer_id' => $customer->id,
|
||||
'class_id' => $customer->class_id,
|
||||
'department_id' => $customer->department_id,
|
||||
'code' => $customer->code,
|
||||
'name' => $customer->name,
|
||||
'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']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
$ids = $params['ids'];
|
||||
$userIds = Customer::whereIn('id', $ids)->pluck('user_id');
|
||||
User::whereIn('id', $userIds)->delete();
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeImport($params)
|
||||
{
|
||||
$row = $params['row'];
|
||||
$ret = $params['ret'];
|
||||
abort_error('客户档案暂时无法导入');
|
||||
// $row['password']
|
||||
if ($ret['id']) {
|
||||
//DB::table($table)->where('id', $ret['id'])->update($row);
|
||||
} else {
|
||||
//$row['id'] = DB::table($table)->insertGetId($row);
|
||||
}
|
||||
//print_r($row);
|
||||
// exit;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
class CustomerTaskDataHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onQueryForm($params) {
|
||||
$q = $params['q'];
|
||||
$q->orderByRaw('cast(customer_task_data.code as int) asc');
|
||||
|
||||
$params['q'] = $q;
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($arguments) {
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\DeliveryAddress;
|
||||
|
||||
class DeliveryAddressHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterStore($params) {
|
||||
$master = $params['master'];
|
||||
if ($master['is_default'] == 1) {
|
||||
$customer = Customer::find($master['customer_id']);
|
||||
if ($customer) {
|
||||
$customer->warehouse_contact = $master['name'];
|
||||
$customer->warehouse_tel = $master['tel'];
|
||||
$customer->warehouse_phone = $master['phone'];
|
||||
$customer->warehouse_address = $master['address'];
|
||||
$customer->save();
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\CustomerPrice;
|
||||
|
||||
class PriceHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
$gets = $params['gets'];
|
||||
$_price = $gets['customer_price'];
|
||||
$data = $gets['customer_price_data'];
|
||||
|
||||
$id = 0;
|
||||
|
||||
// 新增或者修改
|
||||
foreach((array)$data['rows'] as $row) {
|
||||
$row['customer_id'] = $_price['customer_id'];
|
||||
$price = CustomerPrice::findOrNew($row['id']);
|
||||
$price->fill($row)->save();
|
||||
$id = $price->id;
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
foreach((array)$data['deleteds'] as $row) {
|
||||
if ($row['id'] > 0) {
|
||||
CustomerPrice::where('id', $row['id'])->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$master['id'] = $id;
|
||||
$params['master'] = $master;
|
||||
|
||||
// 终止执行的进程后
|
||||
$params['terminate'] = false;
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterStore($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\Customer\Models\CustomerRegion;
|
||||
|
||||
class RegionHook
|
||||
{
|
||||
static $linkOptions = [];
|
||||
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params) {
|
||||
$master = $params['master'];
|
||||
$master['parent_id'] = (int)$master['parent_id'];
|
||||
$params['master'] = $master;
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterStore($params) {
|
||||
CustomerRegion::treeRebuild();
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php namespace Gdoo\Customer\Hooks;
|
||||
|
||||
use DB;
|
||||
use Gdoo\User\Models\User;
|
||||
use Gdoo\Customer\Models\Customer;
|
||||
use Gdoo\Customer\Models\CustomerTax;
|
||||
|
||||
class TaxHook
|
||||
{
|
||||
public function onBeforeForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onAfterForm($params) {
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeStore($params)
|
||||
{
|
||||
return $params;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
abort_error($ret['msg']);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function onBeforeDelete($params) {
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user