|
|
@ -11,10 +11,13 @@ |
|
|
|
|
|
|
|
|
namespace app\service\api\apiService; |
|
|
namespace app\service\api\apiService; |
|
|
|
|
|
|
|
|
|
|
|
use app\model\campus_person_role\CampusPersonRole; |
|
|
|
|
|
use app\model\customer_resource_changes\CustomerResourceChanges; |
|
|
use app\model\customer_resources\CustomerResources; |
|
|
use app\model\customer_resources\CustomerResources; |
|
|
use app\model\personnel\Personnel; |
|
|
use app\model\personnel\Personnel; |
|
|
use app\model\resource_sharing\ResourceSharing; |
|
|
use app\model\resource_sharing\ResourceSharing; |
|
|
use app\model\six_speed\SixSpeed; |
|
|
use app\model\six_speed\SixSpeed; |
|
|
|
|
|
use app\model\six_speed_modification_log\SixSpeedModificationLog; |
|
|
use core\base\BaseApiService; |
|
|
use core\base\BaseApiService; |
|
|
use think\facade\Db; |
|
|
use think\facade\Db; |
|
|
|
|
|
|
|
|
@ -85,4 +88,123 @@ class CustomerResourcesService extends BaseApiService |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//客户资源-编辑 |
|
|
|
|
|
public function editData(array $where, array $customer_resources_data, array $six_speed_data) |
|
|
|
|
|
{ |
|
|
|
|
|
$operator_id = $this->member_id;//当前登录用户的id(日志操作人的id) |
|
|
|
|
|
$campus_id = 0;//日志操作人校区的id |
|
|
|
|
|
$campus_id_arr = CampusPersonRole::where('person_id', $operator_id)->column('campus_id'); |
|
|
|
|
|
if (count($campus_id_arr)) { |
|
|
|
|
|
if (count($campus_id_arr) > 1) { |
|
|
|
|
|
$campus_id = 0; |
|
|
|
|
|
} else { |
|
|
|
|
|
$campus_id = $campus_id_arr[0]; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$res = [ |
|
|
|
|
|
'code' => 0, |
|
|
|
|
|
'msg' => '操作失败', |
|
|
|
|
|
'data' => [] |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
if (!$where) { |
|
|
|
|
|
$res['msg'] = '查询条件不能为空'; |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$date = date('Y-m-d H:i:s'); |
|
|
|
|
|
$customer_resources_data['updated_at'] = $date; |
|
|
|
|
|
$six_speed_data['updated_at'] = $date; |
|
|
|
|
|
|
|
|
|
|
|
//开启事物 |
|
|
|
|
|
Db::startTrans(); |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
$customer_resources = CustomerResources::where('id', $where['id'])->find(); |
|
|
|
|
|
if ($customer_resources) { |
|
|
|
|
|
$customer_resources = $customer_resources->toArray(); |
|
|
|
|
|
} |
|
|
|
|
|
$update_1 = CustomerResources::where('id', $where['id'])->update($customer_resources_data);//客户资源表 |
|
|
|
|
|
if (!$update_1) { |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更近客户资源日志表 |
|
|
|
|
|
$compareData = (new CommonService)->compareData($customer_resources, $customer_resources_data); |
|
|
|
|
|
if ($compareData['changed_fields']) { |
|
|
|
|
|
$data = [ |
|
|
|
|
|
"customer_resource_id" => $where['id'],//客户资源的ID |
|
|
|
|
|
"operator_id" => $operator_id,//操作人的ID |
|
|
|
|
|
"campus_id" => $campus_id,//操作人校区的ID|如果这人有2校区就填0 |
|
|
|
|
|
"modified_fields" => $compareData['changed_fields_json'],//修改的哪些字段 |
|
|
|
|
|
"old_values" => $compareData['old_values_json'],//修改前的值 |
|
|
|
|
|
"new_values" => $compareData['new_values_json'],//修改后的值 |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$id = CustomerResourceChanges::insertGetId($data); |
|
|
|
|
|
if (!$id) { |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$six_speed_data['resource_id'] = $where['id']; |
|
|
|
|
|
|
|
|
|
|
|
//查六要素是否存在 |
|
|
|
|
|
$six_speed = SixSpeed::where('resource_id', $where['id'])->find(); |
|
|
|
|
|
if ($six_speed) { |
|
|
|
|
|
$six_speed = $six_speed->toArray(); |
|
|
|
|
|
//更新六要素 |
|
|
|
|
|
$sixSpeedUpdate = SixSpeed::where('id', $six_speed['id'])->update($six_speed_data); |
|
|
|
|
|
if (!$sixSpeedUpdate) { |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//更近六要素日志表 |
|
|
|
|
|
$compareData = (new CommonService)->compareData($six_speed, $six_speed_data); |
|
|
|
|
|
if ($compareData['changed_fields']) { |
|
|
|
|
|
$data = [ |
|
|
|
|
|
"operator_id" => $operator_id,//操作人的ID |
|
|
|
|
|
"campus_id" => $campus_id,//操作人校区的ID|如果这人有2校区就填0 |
|
|
|
|
|
"customer_resource_id" => $where['id'],//客户资源的ID |
|
|
|
|
|
"modified_field" => $compareData['changed_fields_json'],//修改的哪些字段 |
|
|
|
|
|
"old_value" => $compareData['old_values_json'],//修改前的值 |
|
|
|
|
|
"new_value" => $compareData['new_values_json'],//修改后的值 |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
$id = SixSpeedModificationLog::insertGetId($data); |
|
|
|
|
|
if (!$id) { |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
//创建六要素 |
|
|
|
|
|
$sixSpeedUpdate = SixSpeed::create($six_speed_data); |
|
|
|
|
|
if (!$sixSpeedUpdate) { |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Db::commit(); |
|
|
|
|
|
$res = [ |
|
|
|
|
|
'code' => 1, |
|
|
|
|
|
'msg' => '操作成功' |
|
|
|
|
|
]; |
|
|
|
|
|
return $res; |
|
|
|
|
|
} catch (\Exception $exception) { |
|
|
|
|
|
Db::rollback(); |
|
|
|
|
|
return $res; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|