|
|
@@ -28,30 +28,34 @@ use App\Traits\ServiceAppAop;
|
|
|
class OwnerService implements UserFilter
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
- protected $modelClass=Owner::class;
|
|
|
+
|
|
|
+ protected $modelClass = Owner::class;
|
|
|
/** @var CacheService $cacheService */
|
|
|
private $cacheService;
|
|
|
- function __construct(){
|
|
|
- $this->instant($this->cacheService,'CacheService');
|
|
|
+
|
|
|
+ function __construct()
|
|
|
+ {
|
|
|
+ $this->instant($this->cacheService, 'CacheService');
|
|
|
}
|
|
|
+
|
|
|
/*
|
|
|
* array | string $column
|
|
|
* 默认一些select字段,可传递string 或 array来指定select字段
|
|
|
*/
|
|
|
public function getIntersectPermitting(array $column = ['id', 'name'])
|
|
|
{
|
|
|
- $ownerIds=app('OwnerService')->getIdArr();
|
|
|
- return $this->cacheService->getOrExecute('OwnersAll_IdName'.md5(json_encode($column).json_encode($ownerIds)),function()use($column,$ownerIds){
|
|
|
- if(empty($ownerIds))return new Collection();
|
|
|
+ $ownerIds = app('OwnerService')->getIdArr();
|
|
|
+ return $this->cacheService->getOrExecute('OwnersAll_IdName' . md5(json_encode($column) . json_encode($ownerIds)), function () use ($column, $ownerIds) {
|
|
|
+ if (empty($ownerIds)) return new Collection();
|
|
|
return Owner::query()->select($column)->whereIn('id', $ownerIds)->whereNull('deleted_at')->get();
|
|
|
- },config('cache.expirations.owners'));
|
|
|
+ }, config('cache.expirations.owners'));
|
|
|
}
|
|
|
|
|
|
public function getSelection($column = ['id'])
|
|
|
{
|
|
|
- return $this->cacheService->getOrExecute('OwnersAll_'.md5(json_encode($column)),function()use($column){
|
|
|
+ return $this->cacheService->getOrExecute('OwnersAll_' . md5(json_encode($column)), function () use ($column) {
|
|
|
return Owner::filterAuthorities()->select($column)->get();
|
|
|
- },config('cache.expirations.owners'));
|
|
|
+ }, config('cache.expirations.owners'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -69,7 +73,7 @@ class OwnerService implements UserFilter
|
|
|
if (count($basCustomers) == $ownerCount) return null;
|
|
|
foreach ($basCustomers as $basCustomer) {
|
|
|
$owner = Owner::query()->where('code', $basCustomer['customerid'])->first();
|
|
|
- if (!isset($owner)){
|
|
|
+ if (!isset($owner)) {
|
|
|
Owner::query()->create([
|
|
|
'code' => $basCustomer['customerid'],
|
|
|
'name' => $basCustomer['descr_c'],
|
|
|
@@ -77,7 +81,7 @@ class OwnerService implements UserFilter
|
|
|
]);
|
|
|
continue;
|
|
|
}
|
|
|
- if ($owner['name']!=$basCustomer['descr_c']){
|
|
|
+ if ($owner['name'] != $basCustomer['descr_c']) {
|
|
|
$owner->update([
|
|
|
'code' => $basCustomer['customerid'],
|
|
|
'name' => $basCustomer['descr_c'],
|
|
|
@@ -88,13 +92,14 @@ class OwnerService implements UserFilter
|
|
|
return $owners;
|
|
|
}
|
|
|
|
|
|
- public function first(array $params, array $rules =[]){
|
|
|
- return $this->cacheService->getOrExecute('OwnersFirst'.md5(json_encode($params),json_encode($rules)),function()use($params,$rules){
|
|
|
+ public function first(array $params, array $rules = [])
|
|
|
+ {
|
|
|
+ return $this->cacheService->getOrExecute('OwnersFirst' . md5(json_encode($params), json_encode($rules)), function () use ($params, $rules) {
|
|
|
$owner = Owner::query();
|
|
|
- foreach ($params as $column => $value){
|
|
|
- if (!isset($rules[$column]))$owner->where($column, $value);
|
|
|
- else{
|
|
|
- switch ($rules[$column]){
|
|
|
+ foreach ($params as $column => $value) {
|
|
|
+ if (!isset($rules[$column])) $owner->where($column, $value);
|
|
|
+ else {
|
|
|
+ switch ($rules[$column]) {
|
|
|
case "or":
|
|
|
$owner->orWhere($column, $value);
|
|
|
break;
|
|
|
@@ -102,7 +107,7 @@ class OwnerService implements UserFilter
|
|
|
}
|
|
|
}
|
|
|
return $owner->first();
|
|
|
- },config('cache.expirations.rarelyChange'));
|
|
|
+ }, config('cache.expirations.rarelyChange'));
|
|
|
}
|
|
|
|
|
|
public function find($id, $with = [])
|
|
|
@@ -112,46 +117,53 @@ class OwnerService implements UserFilter
|
|
|
|
|
|
public function update(Owner $owner, array $values, array $related = [])
|
|
|
{
|
|
|
- if ($related["ownerStoragePriceModels"] ?? false)$owner->ownerStoragePriceModels()->sync($related["ownerStoragePriceModels"]);
|
|
|
+ if ($related["ownerStoragePriceModels"] ?? false) $owner->ownerStoragePriceModels()->sync($related["ownerStoragePriceModels"]);
|
|
|
return $owner->update($values);
|
|
|
}
|
|
|
|
|
|
- public function create(array $params, array $related = []){
|
|
|
+ public function create(array $params, array $related = [])
|
|
|
+ {
|
|
|
/** @var Owner $owner */
|
|
|
$owner = Owner::query()->create($params);
|
|
|
- if ($related["ownerStoragePriceModels"] ?? false)$owner->ownerStoragePriceModels()->syncWithoutDetaching($related["ownerStoragePriceModels"]);
|
|
|
+ if ($related["ownerStoragePriceModels"] ?? false) $owner->ownerStoragePriceModels()->syncWithoutDetaching($related["ownerStoragePriceModels"]);
|
|
|
return $owner;
|
|
|
}
|
|
|
|
|
|
- public function firstOrCreate(array $params, array $values = null){
|
|
|
+ public function firstOrCreate(array $params, array $values = null)
|
|
|
+ {
|
|
|
if (!$values) return Owner::query()->whereNull("deleted_at")->firstOrCreate($params);
|
|
|
- return Owner::query()->whereNull("deleted_at")->firstOrCreate($params,$values);
|
|
|
+ return Owner::query()->whereNull("deleted_at")->firstOrCreate($params, $values);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function 获取订单跟踪的货主(){
|
|
|
- return Owner::query()->with('orderTrackingOwner')->whereHas('orderTrackingOwner',function($query){
|
|
|
- $query->where('status','启用');
|
|
|
+ public function 获取订单跟踪的货主()
|
|
|
+ {
|
|
|
+ return Owner::query()->with('orderTrackingOwner')->whereHas('orderTrackingOwner', function ($query) {
|
|
|
+ $query->where('status', '启用');
|
|
|
})->get();
|
|
|
}
|
|
|
|
|
|
- public function getByWmsOrders($orderHeaders){
|
|
|
- $customerIds = array_unique(data_get($orderHeaders,'*.customerid'));
|
|
|
- $customerIds = array_diff($customerIds,[null,'','*']);
|
|
|
- $owners = Owner::query()->whereIn('code',$customerIds)->get();
|
|
|
+ public function getByWmsOrders($orderHeaders)
|
|
|
+ {
|
|
|
+ $customerIds = array_unique(data_get($orderHeaders, '*.customerid'));
|
|
|
+ $customerIds = array_diff($customerIds, [null, '', '*']);
|
|
|
+ $owners = Owner::query()->whereIn('code', $customerIds)->get();
|
|
|
|
|
|
- if($owners->count() < count($customerIds)){
|
|
|
- $customerIds = array_diff($customerIds,data_get($owners,'*.code'));
|
|
|
+ if ($owners->count() < count($customerIds)) {
|
|
|
+ $customerIds = array_diff($customerIds, data_get($owners, '*.code'));
|
|
|
$owner_list = $this->createByWmsCustomerIds($customerIds);
|
|
|
- $owners=$owners->concat($owner_list);
|
|
|
+ $owners = $owners->concat($owner_list);
|
|
|
}
|
|
|
return $owners;
|
|
|
}
|
|
|
|
|
|
- public function createByWmsCustomerIds($codes){
|
|
|
- if(!$codes) {return [];}
|
|
|
+ public function createByWmsCustomerIds($codes)
|
|
|
+ {
|
|
|
+ if (!$codes) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
$basCustomer = OracleBasCustomer::query()
|
|
|
- ->where('Customer_Type','OW')
|
|
|
+ ->where('Customer_Type', 'OW')
|
|
|
->whereIn('CustomerID', $codes)
|
|
|
->get();
|
|
|
|
|
|
@@ -168,7 +180,7 @@ class OwnerService implements UserFilter
|
|
|
try {
|
|
|
if (count($insert_params) > 0) {
|
|
|
$this->insert($insert_params);
|
|
|
- app('LogService')->log(__METHOD__, __FUNCTION__, '批量创建 owner ' . count($insert_params) . json_encode($insert_params) );
|
|
|
+ app('LogService')->log(__METHOD__, __FUNCTION__, '批量创建 owner ' . count($insert_params) . json_encode($insert_params));
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
app('LogService')->log(__METHOD__, __FUNCTION__, '批量创建 owner error' . json_encode($insert_params) . '||' . $e->getMessage() . '||' . $e->getTraceAsString());
|
|
|
@@ -177,32 +189,34 @@ class OwnerService implements UserFilter
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function insert($fillables){
|
|
|
+ public function insert($fillables)
|
|
|
+ {
|
|
|
return Owner::query()->insert($fillables);
|
|
|
}
|
|
|
|
|
|
- public function getAuthorizedOwners(){
|
|
|
- return Owner::query()->whereIn('id',app("OwnerService")->getQuery())->get();
|
|
|
+ public function getAuthorizedOwners()
|
|
|
+ {
|
|
|
+ return Owner::query()->whereIn('id', app("OwnerService")->getQuery())->get();
|
|
|
}
|
|
|
|
|
|
public function get(array $params, array $withs = null, bool $authority = true, bool $notShowSoftDelete = false, $user = null)
|
|
|
{
|
|
|
return Cache::remember(
|
|
|
- 'owner_'.md5(json_encode($params).json_encode($withs).$authority.$notShowSoftDelete.json_encode($user))
|
|
|
- ,config('cache.expirations.rarelyChange')
|
|
|
- ,function()use($params,$withs,$authority,$notShowSoftDelete){
|
|
|
- $query = $this->query($this->getQueryConstructor($withs, $authority, $notShowSoftDelete),$params);
|
|
|
+ 'owner_' . md5(json_encode($params) . json_encode($withs) . $authority . $notShowSoftDelete . json_encode($user))
|
|
|
+ , config('cache.expirations.rarelyChange')
|
|
|
+ , function () use ($params, $withs, $authority, $notShowSoftDelete) {
|
|
|
+ $query = $this->query($this->getQueryConstructor($withs, $authority, $notShowSoftDelete), $params);
|
|
|
return $query->get();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private function getQueryConstructor(array $withs, bool $authority, bool $notShowSoftDelete) :Builder
|
|
|
+ private function getQueryConstructor(array $withs, bool $authority, bool $notShowSoftDelete): Builder
|
|
|
{
|
|
|
$query = Owner::query();
|
|
|
- if ($withs)$query->with($withs);
|
|
|
- if ($authority){
|
|
|
+ if ($withs) $query->with($withs);
|
|
|
+ if ($authority) {
|
|
|
$ids = $this->getIdArr();
|
|
|
- if (count($ids) > 0){
|
|
|
+ if (count($ids) > 0) {
|
|
|
$query->whereIn("id", $ids);
|
|
|
} else {
|
|
|
$query->where("id", 0);
|
|
|
@@ -211,98 +225,99 @@ class OwnerService implements UserFilter
|
|
|
if ($notShowSoftDelete) $query->whereNull('deleted_at');
|
|
|
return $query;
|
|
|
}
|
|
|
+
|
|
|
public function paginate(array $params, array $withs = null, bool $authority = true, bool $notShowSoftDelete = false)
|
|
|
{
|
|
|
- $query = $this->query($this->getQueryConstructor($withs, $authority, $notShowSoftDelete),$params)->
|
|
|
- orderByDesc("id");
|
|
|
+ $query = $this->query($this->getQueryConstructor($withs, $authority, $notShowSoftDelete), $params)->
|
|
|
+ orderByDesc("id");
|
|
|
return $query->paginate($params["paginate"] ?? 50);
|
|
|
}
|
|
|
|
|
|
private function query(Builder $builder, array $params)
|
|
|
{
|
|
|
- foreach ($params as $column => $param){
|
|
|
- if ($column == 'paginate' || $column == 'page' || !$param)continue;
|
|
|
- if ($param === true){
|
|
|
+ foreach ($params as $column => $param) {
|
|
|
+ if ($column == 'paginate' || $column == 'page' || !$param) continue;
|
|
|
+ if ($param === true) {
|
|
|
$builder->whereNotNull($column);
|
|
|
continue;
|
|
|
}
|
|
|
- if ($param === false){
|
|
|
+ if ($param === false) {
|
|
|
$builder->whereNull($column);
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'created_at_start'){
|
|
|
- $builder->where("created_at",">=",$param.":00");
|
|
|
+ if ($column == 'created_at_start') {
|
|
|
+ $builder->where("created_at", ">=", $param . ":00");
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'created_at_end'){
|
|
|
- $builder->where("created_at","<=",$param.":59");
|
|
|
+ if ($column == 'created_at_end') {
|
|
|
+ $builder->where("created_at", "<=", $param . ":59");
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'contract_number'){
|
|
|
- $builder->whereHas("contracts",function ($query)use($param){
|
|
|
+ if ($column == 'contract_number') {
|
|
|
+ $builder->whereHas("contracts", function ($query) use ($param) {
|
|
|
/** @var Builder $query */
|
|
|
- $query->where("contract_number","like",$param."%");
|
|
|
+ $query->where("contract_number", "like", $param . "%");
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'using_type'){
|
|
|
- $builder->whereHas("ownerStoragePriceModels",function ($query)use($param){
|
|
|
+ if ($column == 'using_type') {
|
|
|
+ $builder->whereHas("ownerStoragePriceModels", function ($query) use ($param) {
|
|
|
/** @var Builder $query */
|
|
|
- $query->where("using_type",$param);
|
|
|
+ $query->where("using_type", $param);
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'customers'){
|
|
|
- if (is_array($param))$builder->whereIn('customer_id',$param);
|
|
|
- else $builder->where('customer_id',$param);
|
|
|
+ if ($column == 'customers') {
|
|
|
+ if (is_array($param)) $builder->whereIn('customer_id', $param);
|
|
|
+ else $builder->where('customer_id', $param);
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'ids'){
|
|
|
- if (is_array($param))$builder->whereIn('id',$param);
|
|
|
- else $builder->where('id',$param);
|
|
|
+ if ($column == 'ids') {
|
|
|
+ if (is_array($param)) $builder->whereIn('id', $param);
|
|
|
+ else $builder->where('id', $param);
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'owners'){
|
|
|
- if (is_array($param))$builder->whereIn('owner_id',$param);
|
|
|
- else $builder->where('owner_id',$param);
|
|
|
+ if ($column == 'owners') {
|
|
|
+ if (is_array($param)) $builder->whereIn('owner_id', $param);
|
|
|
+ else $builder->where('owner_id', $param);
|
|
|
continue;
|
|
|
}
|
|
|
// if ($column == 'user_work_group'){
|
|
|
// $builder->where("user_workgroup_id",$param);
|
|
|
// continue;
|
|
|
// }
|
|
|
- if ($column == 'kcGroup'){
|
|
|
- $builder->whereHas("departmentObligationOwner",function($query)use($param){
|
|
|
- $query->where('obligation_code','kc')->where('department_id',$param);
|
|
|
+ if ($column == 'kcGroup') {
|
|
|
+ $builder->whereHas("departmentObligationOwner", function ($query) use ($param) {
|
|
|
+ $query->where('obligation_code', 'kc')->where('department_id', $param);
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'jgGroup'){
|
|
|
- $builder->whereHas("departmentObligationOwner",function($query)use($param){
|
|
|
- $query->where('obligation_code','jg')->where('department_id',$param);
|
|
|
+ if ($column == 'jgGroup') {
|
|
|
+ $builder->whereHas("departmentObligationOwner", function ($query) use ($param) {
|
|
|
+ $query->where('obligation_code', 'jg')->where('department_id', $param);
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'fhGroup'){
|
|
|
- $builder->whereHas("departmentObligationOwner",function($query)use($param){
|
|
|
- $query->where('obligation_code','fh')->where('department_id',$param);
|
|
|
+ if ($column == 'fhGroup') {
|
|
|
+ $builder->whereHas("departmentObligationOwner", function ($query) use ($param) {
|
|
|
+ $query->where('obligation_code', 'fh')->where('department_id', $param);
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'thGroup'){
|
|
|
- $builder->whereHas("departmentObligationOwner",function($query)use($param){
|
|
|
- $query->where('obligation_code','th')->where('department_id',$param);
|
|
|
+ if ($column == 'thGroup') {
|
|
|
+ $builder->whereHas("departmentObligationOwner", function ($query) use ($param) {
|
|
|
+ $query->where('obligation_code', 'th')->where('department_id', $param);
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if ($column == 'shGroup'){
|
|
|
- $builder->whereHas("departmentObligationOwner",function($query)use($param){
|
|
|
- $query->where('obligation_code','sh')->where('department_id',$param);
|
|
|
+ if ($column == 'shGroup') {
|
|
|
+ $builder->whereHas("departmentObligationOwner", function ($query) use ($param) {
|
|
|
+ $query->where('obligation_code', 'sh')->where('department_id', $param);
|
|
|
});
|
|
|
continue;
|
|
|
}
|
|
|
- if (is_array($param))$builder->whereIn($column,$param);
|
|
|
- else $builder->where($column,$param);
|
|
|
+ if (is_array($param)) $builder->whereIn($column, $param);
|
|
|
+ else $builder->where($column, $param);
|
|
|
}
|
|
|
return $builder;
|
|
|
}
|
|
|
@@ -310,30 +325,32 @@ class OwnerService implements UserFilter
|
|
|
public function getOwnerByCodes($codes)
|
|
|
{
|
|
|
$collect = collect();
|
|
|
- if(count($codes) == 0)return $collect;
|
|
|
+ if (count($codes) == 0) return $collect;
|
|
|
foreach ($codes as $code) {
|
|
|
$collect = $collect->push($this->getOwnerByCode($code));
|
|
|
}
|
|
|
return $collect;
|
|
|
}
|
|
|
|
|
|
- public function getOwnerByCode($code){
|
|
|
- return Cache::remember("getOwnerByCode_{$code}", config('cache.expirations.owners'), function ()use($code){
|
|
|
- $owner = Owner::query()->where('code',$code)->first();
|
|
|
- if($owner) return $owner;
|
|
|
- $basCustomer = app('OracleBasCustomerService')->first(['Customer_Type'=>'OW','CustomerID'=>$code]);
|
|
|
- if(!$basCustomer)return null;
|
|
|
- if($basCustomer && $basCustomer['active_flag']=='Y') return Owner::query()
|
|
|
- ->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid']]);
|
|
|
- $deleted_at=Carbon::now()->toDateTimeString();
|
|
|
- if($basCustomer && $basCustomer['active_flag']=='N') return Owner::query()
|
|
|
- ->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid'],'deleted_at'=>$deleted_at]);
|
|
|
+ public function getOwnerByCode($code)
|
|
|
+ {
|
|
|
+ return Cache::remember("getOwnerByCode_{$code}", config('cache.expirations.owners'), function () use ($code) {
|
|
|
+ $owner = Owner::query()->where('code', $code)->first();
|
|
|
+ if ($owner) return $owner;
|
|
|
+ $basCustomer = app('OracleBasCustomerService')->first(['Customer_Type' => 'OW', 'CustomerID' => $code]);
|
|
|
+ if (!$basCustomer) return null;
|
|
|
+ if ($basCustomer && $basCustomer['active_flag'] == 'Y') return Owner::query()
|
|
|
+ ->create(['name' => $basCustomer['descr_c'], 'code' => $basCustomer['customerid']]);
|
|
|
+ $deleted_at = Carbon::now()->toDateTimeString();
|
|
|
+ if ($basCustomer && $basCustomer['active_flag'] == 'N') return Owner::query()
|
|
|
+ ->create(['name' => $basCustomer['descr_c'], 'code' => $basCustomer['customerid'], 'deleted_at' => $deleted_at]);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
public function codeGetOwner($code)
|
|
|
{
|
|
|
- return app(CacheService::class)->getOrExecute("owner_".$code,function ()use($code){
|
|
|
- return Owner::query()->firstOrCreate(["code"=>$code],["code"=>$code,"name"=>$code]);
|
|
|
+ return app(CacheService::class)->getOrExecute("owner_" . $code, function () use ($code) {
|
|
|
+ return Owner::query()->firstOrCreate(["code" => $code], ["code" => $code, "name" => $code]);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -345,25 +362,25 @@ class OwnerService implements UserFilter
|
|
|
*/
|
|
|
public function syncPush($owner)
|
|
|
{
|
|
|
- if (is_array($owner)){
|
|
|
+ if (is_array($owner)) {
|
|
|
$owner = new Owner();
|
|
|
- foreach ($owner as $column=>$value){
|
|
|
+ foreach ($owner as $column => $value) {
|
|
|
$owner[$column] = $value;
|
|
|
}
|
|
|
}
|
|
|
- if (is_numeric($owner)){
|
|
|
+ if (is_numeric($owner)) {
|
|
|
$owner = Owner::query()->find($owner);
|
|
|
- if (!$owner)return false;
|
|
|
+ if (!$owner) return false;
|
|
|
}
|
|
|
- $wms = DB::connection("oracle")->selectOne(DB::raw("SELECT CUSTOMERID FROM BAS_CUSTOMER WHERE CUSTOMER_TYPE = ? AND CUSTOMERID = ?"),["OW",$owner->code]);
|
|
|
- if (!$wms && $owner->code){
|
|
|
+ $wms = DB::connection("oracle")->selectOne(DB::raw("SELECT CUSTOMERID FROM BAS_CUSTOMER WHERE CUSTOMER_TYPE = ? AND CUSTOMERID = ?"), ["OW", $owner->code]);
|
|
|
+ if (!$wms && $owner->code) {
|
|
|
$query = DB::raw(<<<sql
|
|
|
INSERT INTO BAS_CUSTOMER(CUSTOMERID,CUSTOMER_TYPE,DESCR_C,ADDTIME,EDITTIME,ADDWHO)
|
|
|
VALUES(?,?,?,TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),?)
|
|
|
sql
|
|
|
);
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
- DB::connection("oracle")->insert($query,[$owner->code,'OW',$owner->name,$date,$date,'WAS-'.(Auth::user() ? Auth::user()['name'] : 'SYSTEM')]);
|
|
|
+ DB::connection("oracle")->insert($query, [$owner->code, 'OW', $owner->name, $date, $date, 'WAS-' . (Auth::user() ? Auth::user()['name'] : 'SYSTEM')]);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -371,26 +388,26 @@ sql
|
|
|
|
|
|
public function syncUpdate($owner)
|
|
|
{
|
|
|
- if (is_array($owner)){
|
|
|
+ if (is_array($owner)) {
|
|
|
$owner = new Owner();
|
|
|
- foreach ($owner as $column=>$value){
|
|
|
+ foreach ($owner as $column => $value) {
|
|
|
$owner[$column] = $value;
|
|
|
}
|
|
|
}
|
|
|
- if (is_numeric($owner)){
|
|
|
+ if (is_numeric($owner)) {
|
|
|
$owner = Owner::query()->find($owner);
|
|
|
- if (!$owner)return false;
|
|
|
+ if (!$owner) return false;
|
|
|
}
|
|
|
$sql = DB::raw(<<<sql
|
|
|
update BAS_CUSTOMER set ACTIVE_FLAG = ?,EDITTIME = TO_DATE(?,'yyyy-mm-dd hh24:mi:ss'),EDITWHO = ? where CUSTOMERID = ? and CUSTOMER_TYPE = ?
|
|
|
sql
|
|
|
);
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
- if ($owner && $owner->deleted_at){
|
|
|
- DB::connection("oracle")->update($sql,['N',$date,'WAS-'.(Auth::user() ? Auth::user()['name'] : 'SYSTEM'),$owner->code,'OW']);
|
|
|
+ if ($owner && $owner->deleted_at) {
|
|
|
+ DB::connection("oracle")->update($sql, ['N', $date, 'WAS-' . (Auth::user() ? Auth::user()['name'] : 'SYSTEM'), $owner->code, 'OW']);
|
|
|
}
|
|
|
- if ($owner && $owner->deleted_at==null) {
|
|
|
- DB::connection("oracle")->update($sql,['Y',$date,'WAS-'.(Auth::user() ? Auth::user()['name'] : 'SYSTEM'),$owner->code,'OW']);
|
|
|
+ if ($owner && $owner->deleted_at == null) {
|
|
|
+ DB::connection("oracle")->update($sql, ['Y', $date, 'WAS-' . (Auth::user() ? Auth::user()['name'] : 'SYSTEM'), $owner->code, 'OW']);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -416,11 +433,11 @@ sql
|
|
|
*/
|
|
|
public function deleteAuthority($owner)
|
|
|
{
|
|
|
- $authorities = Authority::query()->where('name',"_{$owner['id']}")
|
|
|
- ->where("alias_name","like","(货主%")
|
|
|
+ $authorities = Authority::query()->where('name', "_{$owner['id']}")
|
|
|
+ ->where("alias_name", "like", "(货主%")
|
|
|
->get(["id"]);
|
|
|
- $ids = array_column($authorities->toArray(),"id");
|
|
|
- DB::table("authority_role")->whereIn("id_authority",$ids)->delete();
|
|
|
+ $ids = array_column($authorities->toArray(), "id");
|
|
|
+ DB::table("authority_role")->whereIn("id_authority", $ids)->delete();
|
|
|
Authority::destroy($ids);
|
|
|
}
|
|
|
|
|
|
@@ -439,41 +456,41 @@ LEFT JOIN owner_storage_price_model_owner b ON a.id = b.owner_storage_price_mod
|
|
|
LEFT JOIN owners c ON b.owner_id = c.id
|
|
|
WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
|
|
|
sql;
|
|
|
- if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 0;
|
|
|
+ if (DB::selectOne(DB::raw($sql), [$ownerId])) $relevance[] = 0;
|
|
|
$sql = <<<sql
|
|
|
SELECT 1 FROM owner_price_operations a
|
|
|
LEFT JOIN owner_price_operation_owner b ON a.id = b.owner_price_operation_id
|
|
|
LEFT JOIN owners c ON b.owner_id = c.id
|
|
|
WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
|
|
|
sql;
|
|
|
- if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 1;
|
|
|
+ if (DB::selectOne(DB::raw($sql), [$ownerId])) $relevance[] = 1;
|
|
|
$sql = <<<sql
|
|
|
SELECT 1 FROM owner_price_expresses a
|
|
|
LEFT JOIN owner_price_express_owner b ON a.id = b.owner_price_express_id
|
|
|
LEFT JOIN owners c ON b.owner_id = c.id
|
|
|
WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
|
|
|
sql;
|
|
|
- if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 2;
|
|
|
+ if (DB::selectOne(DB::raw($sql), [$ownerId])) $relevance[] = 2;
|
|
|
$sql = <<<sql
|
|
|
SELECT 1 FROM owner_price_logistics a
|
|
|
LEFT JOIN owner_price_logistic_owner b ON a.id = b.owner_price_logistic_id
|
|
|
LEFT JOIN owners c ON b.owner_id = c.id
|
|
|
WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
|
|
|
sql;
|
|
|
- if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 3;
|
|
|
+ if (DB::selectOne(DB::raw($sql), [$ownerId])) $relevance[] = 3;
|
|
|
$sql = <<<sql
|
|
|
SELECT 1 FROM owner_price_direct_logistics a
|
|
|
LEFT JOIN owner_price_direct_logistic_owner b ON a.id = b.owner_price_direct_logistic_id
|
|
|
LEFT JOIN owners c ON b.owner_id = c.id
|
|
|
WHERE (a.operation IS NULL OR a.operation = '') AND c.id = ? LIMIT 1
|
|
|
sql;
|
|
|
- if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 4;
|
|
|
+ if (DB::selectOne(DB::raw($sql), [$ownerId])) $relevance[] = 4;
|
|
|
$sql = <<<sql
|
|
|
SELECT 1 FROM owner_price_systems a LEFT JOIN owners b ON a.owner_id = b.id
|
|
|
WHERE b.id = ? LIMIT 1
|
|
|
sql;
|
|
|
- if (DB::selectOne(DB::raw($sql),[$ownerId]))$relevance[] = 5;
|
|
|
- Owner::query()->where("id",$ownerId)->update(["relevance"=>$relevance]);
|
|
|
+ if (DB::selectOne(DB::raw($sql), [$ownerId])) $relevance[] = 5;
|
|
|
+ Owner::query()->where("id", $ownerId)->update(["relevance" => $relevance]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -483,23 +500,23 @@ sql;
|
|
|
*/
|
|
|
public function attachTaxRate(Owner $owner)
|
|
|
{
|
|
|
- OwnerStoragePriceModel::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->whereNull("tax_rate_id")->update(["tax_rate_id"=>$owner->tax_rate_id]);
|
|
|
- OwnerPriceOperation::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->whereNull("tax_rate_id")->update(["tax_rate_id"=>$owner->tax_rate_id]);
|
|
|
- OwnerPriceExpress::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->whereNull("tax_rate_id")->update(["tax_rate_id"=>$owner->tax_rate_id]);
|
|
|
- OwnerPriceLogistic::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->whereNull("tax_rate_id")->update(["tax_rate_id"=>$owner->tax_rate_id]);
|
|
|
- OwnerPriceDirectLogistic::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->whereNull("tax_rate_id")->update(["tax_rate_id"=>$owner->tax_rate_id]);
|
|
|
- OwnerPriceSystem::query()->where("owner_id",$owner->id)->whereNull("tax_rate_id")
|
|
|
- ->update(["tax_rate_id"=>$owner->tax_rate_id]);
|
|
|
+ OwnerStoragePriceModel::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->whereNull("tax_rate_id")->update(["tax_rate_id" => $owner->tax_rate_id]);
|
|
|
+ OwnerPriceOperation::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->whereNull("tax_rate_id")->update(["tax_rate_id" => $owner->tax_rate_id]);
|
|
|
+ OwnerPriceExpress::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->whereNull("tax_rate_id")->update(["tax_rate_id" => $owner->tax_rate_id]);
|
|
|
+ OwnerPriceLogistic::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->whereNull("tax_rate_id")->update(["tax_rate_id" => $owner->tax_rate_id]);
|
|
|
+ OwnerPriceDirectLogistic::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->whereNull("tax_rate_id")->update(["tax_rate_id" => $owner->tax_rate_id]);
|
|
|
+ OwnerPriceSystem::query()->where("owner_id", $owner->id)->whereNull("tax_rate_id")
|
|
|
+ ->update(["tax_rate_id" => $owner->tax_rate_id]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -509,23 +526,23 @@ sql;
|
|
|
*/
|
|
|
public function removeTaxRate(Owner $owner)
|
|
|
{
|
|
|
- OwnerStoragePriceModel::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->update(["tax_rate_id"=>null]);
|
|
|
- OwnerPriceOperation::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->update(["tax_rate_id"=>null]);
|
|
|
- OwnerPriceExpress::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->update(["tax_rate_id"=>null]);
|
|
|
- OwnerPriceLogistic::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->update(["tax_rate_id"=>null]);
|
|
|
- OwnerPriceDirectLogistic::query()->whereHas("owners",function (Builder $query)use($owner){
|
|
|
- $query->where("id",$owner->id);
|
|
|
- })->update(["tax_rate_id"=>null]);
|
|
|
- OwnerPriceSystem::query()->where("owner_id",$owner->id)
|
|
|
- ->update(["tax_rate_id"=>null]);
|
|
|
+ OwnerStoragePriceModel::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->update(["tax_rate_id" => null]);
|
|
|
+ OwnerPriceOperation::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->update(["tax_rate_id" => null]);
|
|
|
+ OwnerPriceExpress::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->update(["tax_rate_id" => null]);
|
|
|
+ OwnerPriceLogistic::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->update(["tax_rate_id" => null]);
|
|
|
+ OwnerPriceDirectLogistic::query()->whereHas("owners", function (Builder $query) use ($owner) {
|
|
|
+ $query->where("id", $owner->id);
|
|
|
+ })->update(["tax_rate_id" => null]);
|
|
|
+ OwnerPriceSystem::query()->where("owner_id", $owner->id)
|
|
|
+ ->update(["tax_rate_id" => null]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -537,63 +554,66 @@ sql;
|
|
|
*
|
|
|
* @return float|null
|
|
|
*/
|
|
|
- public function getTaxRateFee(Model $model, int $ownerId, ?float $money = null):?float
|
|
|
+ public function getTaxRateFee(Model $model, int $ownerId, ?float $money = null): ?float
|
|
|
{
|
|
|
$taxRate = null;
|
|
|
- if ($model->tax_rate_id){
|
|
|
+ if ($model->tax_rate_id) {
|
|
|
$model->loadMissing("taxRate");
|
|
|
$taxRate = $model->taxRate;
|
|
|
}
|
|
|
- if (!$taxRate){
|
|
|
+ if (!$taxRate) {
|
|
|
/** @var Model|\stdClass $owner */
|
|
|
$owner = new Owner();
|
|
|
$owner->id = $ownerId;
|
|
|
$owner->load("taxRate");
|
|
|
$taxRate = $owner->taxRate;
|
|
|
}
|
|
|
- if (!$taxRate)return null;
|
|
|
- if ($money===null)return $taxRate->value;
|
|
|
- return $money*($taxRate->value/100);
|
|
|
+ if (!$taxRate) return null;
|
|
|
+ if ($money === null) return $taxRate->value;
|
|
|
+ return $money * ($taxRate->value / 100);
|
|
|
}
|
|
|
|
|
|
- public function changeManualBackStatus($id,$isManual)
|
|
|
+ public function changeManualBackStatus($id, $isManual)
|
|
|
{
|
|
|
- $owner=Owner::query()->find($id);
|
|
|
- if ($isManual==0)$owner->update(['is_manual_back'=>1]);
|
|
|
- else $owner->update(['is_manual_back'=>0]);
|
|
|
+ $owner = Owner::query()->find($id);
|
|
|
+ if ($isManual == 0) $owner->update(['is_manual_back' => 1]);
|
|
|
+ else $owner->update(['is_manual_back' => 0]);
|
|
|
return $owner;
|
|
|
}
|
|
|
- public function changeIntervalTime($id,$intervalTime)
|
|
|
+
|
|
|
+ public function changeIntervalTime($id, $intervalTime)
|
|
|
{
|
|
|
- $owner=Owner::query()->find($id);
|
|
|
- $owner->update(['interval_time'=>$intervalTime]);
|
|
|
+ $owner = Owner::query()->find($id);
|
|
|
+ $owner->update(['interval_time' => $intervalTime]);
|
|
|
return $owner;
|
|
|
}
|
|
|
|
|
|
function getIdArr(?int $userId = null): array
|
|
|
{
|
|
|
- if (!$userId)$userId = Auth::id();
|
|
|
- return $this->cacheService->getOrExecute("USER.{$userId}.OWNER.ID",function()use($userId){
|
|
|
- return array_column($this->getQuery($userId)->get()->toArray(),"id");
|
|
|
+ if (!$userId) $userId = Auth::id();
|
|
|
+ return $this->cacheService->getOrExecute("USER.{$userId}.OWNER.ID", function () use ($userId) {
|
|
|
+ return array_column($this->getQuery($userId)->get()->toArray(), "id");
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
function getCodeArr(?int $userId): array
|
|
|
{
|
|
|
$column = "code";
|
|
|
- if (!$userId)$userId = Auth::id();
|
|
|
- return $this->cacheService->getOrExecute("USER.{$userId}.OWNER.CODE",function()use($userId, $column){
|
|
|
- return array_column($this->getQuery($userId, $column)->get()->toArray(),$column);
|
|
|
+ if (!$userId) $userId = Auth::id();
|
|
|
+ return $this->cacheService->getOrExecute("USER.{$userId}.OWNER.CODE", function () use ($userId, $column) {
|
|
|
+ return array_column($this->getQuery($userId, $column)->get()->toArray(), $column);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
function getQuery(?int $userId = null, $column = "id"): Builder
|
|
|
{
|
|
|
- if (!$userId)$userId = Auth::id();
|
|
|
- $query = Owner::query()->select("owners.".$column);
|
|
|
- if (!app("UserService")->checkAdminIdentity($userId) && !app("AuthorityService")->checkAllOwner($userId)){
|
|
|
+ if (!$userId) $userId = Auth::id();
|
|
|
+ $query = Owner::query()->select("owners." . $column);
|
|
|
+ if (!app("UserService")->checkAdminIdentity($userId) && !app("AuthorityService")->checkAllOwner($userId)) {
|
|
|
//$query->whereHas("roles",function ($query)use($userId){
|
|
|
- $query->whereHas("users",function ($query)use($userId){
|
|
|
- $query->where("users.id",$userId);
|
|
|
- });
|
|
|
+ $query->whereHas("users", function ($query) use ($userId) {
|
|
|
+ $query->where("users.id", $userId);
|
|
|
+ });
|
|
|
//});
|
|
|
}
|
|
|
return $query->whereNull("deleted_at");
|
|
|
@@ -601,33 +621,38 @@ sql;
|
|
|
|
|
|
public function combineOwners($owners)
|
|
|
{
|
|
|
- foreach ($owners as $owner){
|
|
|
- $departmentObligationOwner=$owner->departmentObligationOwner??false;
|
|
|
- if (!$departmentObligationOwner)continue;
|
|
|
- foreach ($departmentObligationOwner as $item){
|
|
|
- if ($item->obligation_code=='kc'){
|
|
|
- $owner->kc=$item->department_id;$owner->kcGroup=$item->department?$item->department->name:'';
|
|
|
+ foreach ($owners as $owner) {
|
|
|
+ $departmentObligationOwner = $owner->departmentObligationOwner ?? false;
|
|
|
+ if (!$departmentObligationOwner) continue;
|
|
|
+ foreach ($departmentObligationOwner as $item) {
|
|
|
+ if ($item->obligation_code == 'kc') {
|
|
|
+ $owner->kc = $item->department_id;
|
|
|
+ $owner->kcGroup = $item->department ? $item->department->name : '';
|
|
|
}
|
|
|
- if ($item->obligation_code=='jg'){
|
|
|
- $owner->jg=$item->department_id;$owner->jgGroup=$item->department?$item->department->name:'';
|
|
|
+ if ($item->obligation_code == 'jg') {
|
|
|
+ $owner->jg = $item->department_id;
|
|
|
+ $owner->jgGroup = $item->department ? $item->department->name : '';
|
|
|
}
|
|
|
- if ($item->obligation_code=='th'){
|
|
|
- $owner->th=$item->department_id;$owner->thGroup=$item->department?$item->department->name:'';
|
|
|
+ if ($item->obligation_code == 'th') {
|
|
|
+ $owner->th = $item->department_id;
|
|
|
+ $owner->thGroup = $item->department ? $item->department->name : '';
|
|
|
}
|
|
|
- if ($item->obligation_code=='sh'){
|
|
|
- $owner->sh=$item->department_id;$owner->shGroup=$item->department?$item->department->name:'';
|
|
|
+ if ($item->obligation_code == 'sh') {
|
|
|
+ $owner->sh = $item->department_id;
|
|
|
+ $owner->shGroup = $item->department ? $item->department->name : '';
|
|
|
}
|
|
|
- if ($item->obligation_code=='fh'){
|
|
|
- $owner->fh=$item->department_id;$owner->fhGroup=$item->department?$item->department->name:'';
|
|
|
+ if ($item->obligation_code == 'fh') {
|
|
|
+ $owner->fh = $item->department_id;
|
|
|
+ $owner->fhGroup = $item->department ? $item->department->name : '';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return $owners;
|
|
|
}
|
|
|
|
|
|
- public function getOwnerGroupUnderOwner($ids):array
|
|
|
+ public function getOwnerGroupUnderOwner($ids): array
|
|
|
{
|
|
|
- return Owner::query()->select("id")->whereIn("user_owner_group_id",$ids)
|
|
|
+ return Owner::query()->select("id")->whereIn("user_owner_group_id", $ids)
|
|
|
->pluck("id")->toArray();
|
|
|
}
|
|
|
}
|