Commit 11699609 authored by hujun's avatar hujun

根据bargain_id统计

parent 1884bd6d
......@@ -626,6 +626,7 @@ Route::group('task', [
'updateCouponExpired' => ['task/UpdateCouponTask/updateCouponExpired', ['method' => 'get']],//超过有效期的券改过期
'killOutTimeSql' => ['task/KillOutTimeSql/killOutTimeSql', ['method' => 'get']],//超过有效期的券改过期
'delHouseVideo' => ['task/JobTask/delHouseVideo', ['method' => 'get']],//删除无效视频
'updateBargainPerformance' => ['task/ResultsSummaryNewTask/updateBargainPerformance', ['method' => 'get']],//根据bargain_id统计
]);
Route::group('broker', [
......
......@@ -15,6 +15,7 @@ use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary;
use app\model\Users;
use Think\Log;
use think\Request;
/**
* Created by PhpStorm.
......@@ -333,4 +334,89 @@ class ResultsSummaryNewTask
unset($result_arr);
return $params;
}
/**
* 根据bargain_id统计
*
* @param Request $request
* @return false|string
*/
public function updateBargainPerformance(Request $request) {
try {
$bargain_id = $request->get('bargain_id');
if (empty($bargain_id)) {
return json_encode([ 'code' => 101, 'msg' => 'params is error' ]);
}
$data['msg'] = '';
$where = $update_data = [];
if ($bargain_id) {
$where['b.id'] = $bargain_id;
}
if (!empty($where)) {
//获取被修改人信息
$agent_data = $this->agentsModel->agentBargainAll('a.id,a.store_id,a.district_id,b.create_time', $where);
foreach ($agent_data as $k=>$v) {
$create_time = date('Y-m-d', strtotime($v['create_time']));
$this->totalOfficialReceipts($v['id'], $v['district_id'], $v['store_id'], $create_time);
}
}
$data['code'] = 200;
} catch (\Exception $e) {
$data['code'] = 101;
$data['msg'] = '内部错误:'.$e->getMessage();
}
return json_encode([ 'code' => $data['code'], 'msg' => $data['msg']]);
}
/**
* (临时处理)业绩统计-实收统计
*
* @param $agent_id
* @param $district_id
* @param $store_id
* @param $date
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function totalOfficialReceipts($agent_id, $district_id, $store_id, $date) {
//获取被修改人信息
$date = date('Y-m-d', strtotime($date));
$update_data = [];
$where_bargain['agent_id'] = $agent_id;
$where_bargain['create_time'] = ['BETWEEN', [$date.' 00:00:00', $date.' 23:59:59']];
//实收
$receivedSum = $this->bargainModel->getAddBargainNumGroupTimeNew($where_bargain, 2); //1表示业绩 2表示实收
$received_sum = empty($receivedSum[0]["num"]) ? 0 : $receivedSum[0]["num"];
//业绩
$performanceSum = $this->bargainModel->getAddBargainNumGroupTimeNew($where_bargain, 1);//1表示业绩 2表示实收
$performance_sum = empty($performanceSum[0]["num"])? 0:$performanceSum[0]["num"];
$id = $this->tAgentTotalModel->getTotalEndTimeByAgentId('id', ['total_time'=>$date, 'agent_id'=>$where_bargain['agent_id']]);
if (empty($id[0]['id'])) {
$insert_data[] = [
'store_id' => $store_id,
'district_id' => $district_id,
'agent_id' => $agent_id,
'official_receipts' => $received_sum,
'performance' => $performance_sum,
'total_time' => $date,
'create_time' => date('Y-m-d H:i:s')
];
$this->tAgentTotalModel->addTotal($insert_data);
} else {
$update_data[] = [
'official_receipts' => $received_sum,
'performance' => $performance_sum,
'id' => $id[0]['id'],
'update_time' => date('Y-m-d H:i:s')
];
$this->tAgentTotalModel->saveTotal($update_data);
}
return ;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment