You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.5 KiB
116 lines
3.5 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\customer_resource_changes;
|
|
|
|
use app\model\customer_resource_changes\CustomerResourceChanges;
|
|
|
|
use app\model\customer_resources\CustomerResources;
|
|
use app\model\six_speed\SixSpeed;
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 客户资源表变更记录服务层
|
|
* Class CustomerResourceChangesService
|
|
* @package app\service\admin\customer_resource_changes
|
|
*/
|
|
class CustomerResourceChangesService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->model = new CustomerResourceChanges();
|
|
}
|
|
|
|
/**
|
|
* 获取客户资源表变更记录列表
|
|
* @param array $where
|
|
* @return array
|
|
*/
|
|
public function getPage(array $where = [])
|
|
{
|
|
$field = 'id,customer_resource_id,operator_id,campus_id,modified_fields,old_values,new_values,modification_time,created_at,deleted_at,is_rolled_back,rollback_time';
|
|
$order = 'id desc';
|
|
|
|
$search_model = $this->model->withSearch(["id","customer_resource_id","operator_id","campus_id","modified_fields","old_values","new_values"], $where)->with(['personnel'])->field($field)->order($order);
|
|
|
|
$list = $this->pageQuery($search_model, function ($item) {
|
|
$customer = new CustomerResources();
|
|
$json = json_decode($item['modified_fields'],true);
|
|
$item['count'] = count($json);
|
|
$item['name'] = $customer->where(['id' => $item['customer_resource_id']])->value('name');
|
|
});
|
|
return $list;
|
|
}
|
|
|
|
/**
|
|
* 获取客户资源表变更记录信息
|
|
* @param int $id
|
|
* @return array
|
|
*/
|
|
public function getInfo(int $id)
|
|
{
|
|
$field = 'id,customer_resource_id,operator_id,campus_id,modified_fields,old_values,new_values,modification_time,created_at,deleted_at,is_rolled_back,rollback_time';
|
|
|
|
$info = $this->model->field($field)->where([['id', "=", $id]])->findOrEmpty()->toArray();
|
|
return $info;
|
|
}
|
|
|
|
/**
|
|
* 添加客户资源表变更记录
|
|
* @param array $data
|
|
* @return mixed
|
|
*/
|
|
public function add(array $data)
|
|
{
|
|
$res = $this->model->create($data);
|
|
return $res->id;
|
|
|
|
}
|
|
|
|
/**
|
|
* 客户资源表变更记录编辑
|
|
* @param int $id
|
|
* @param array $data
|
|
* @return bool
|
|
*/
|
|
public function edit(int $id, array $data)
|
|
{
|
|
|
|
$this->model->where([['id', '=', $id]])->update($data);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 删除客户资源表变更记录
|
|
* @param int $id
|
|
* @return bool
|
|
*/
|
|
public function del(int $id)
|
|
{
|
|
$customerResources = new CustomerResources();
|
|
|
|
$data = $this->model->where([['id', '=', $id]])->find();
|
|
|
|
$save = json_decode($data['old_values'],true);
|
|
|
|
$customerResources->where(['id' => $data['customer_resource_id']])->update($save);
|
|
|
|
$this->model->where([['id', '=', $id]])->update([
|
|
'rollback_time' => date("Y-m-d H:i:s", time()),
|
|
'is_rolled_back' => 1
|
|
]);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|