Commit 9263102a authored by hujun's avatar hujun

商铺同步修改

parent e104e033
...@@ -557,6 +557,7 @@ class Finance extends Basic ...@@ -557,6 +557,7 @@ class Finance extends Basic
//通过实收日期,更新业绩统计和实收统计。 //通过实收日期,更新业绩统计和实收统计。
if (isset($update_total)) { if (isset($update_total)) {
$create_time = $this->m_bargain->getFieldValue('create_time', ['id'=>$this->params['id']]);
foreach ($update_total as $v) { foreach ($update_total as $v) {
if (empty($v['income_time'])) { if (empty($v['income_time'])) {
continue; continue;
...@@ -564,7 +565,7 @@ class Finance extends Basic ...@@ -564,7 +565,7 @@ class Finance extends Basic
$real_where['a.id'] = $v['fee_id']; $real_where['a.id'] = $v['fee_id'];
$real_data = $m_real->getIncomePartialList('b.agent_id,c.store_id,c.district_id', $real_where); $real_data = $m_real->getIncomePartialList('b.agent_id,c.store_id,c.district_id', $real_where);
foreach ($real_data as $key) { foreach ($real_data as $key) {
$this->totalOfficialReceipts($key['agent_id'], $key['district_id'], $key['store_id'], $v['income_time']); $this->totalOfficialReceiptsV2($key['agent_id'], $key['district_id'], $key['store_id'], $create_time, $v['income_time']);
} }
} }
} }
...@@ -1646,7 +1647,7 @@ class Finance extends Basic ...@@ -1646,7 +1647,7 @@ class Finance extends Basic
//todo 收佣日期统计 //todo 收佣日期统计
$income_time = $m_real->getFieldValue('income_time', ['id'=> $v3['real_income_id']]); $income_time = $m_real->getFieldValue('income_time', ['id'=> $v3['real_income_id']]);
// $this->updatePerformanceData($v3['agent_id'], $income_time, $v3['store_id'], $v3['district_id']); // $this->updatePerformanceData($v3['agent_id'], $income_time, $v3['store_id'], $v3['district_id']);
$this->totalOfficialReceipts($v3['agent_id'], $v3['district_id'], $v3['store_id'], $income_time); $this->totalOfficialReceiptsV2($v3['agent_id'], $v3['district_id'], $v3['store_id'], '',$income_time);
} }
} }
// $data = $m_partial->addCommission($this->params, $this->userId); // $data = $m_partial->addCommission($this->params, $this->userId);
...@@ -2605,7 +2606,7 @@ class Finance extends Basic ...@@ -2605,7 +2606,7 @@ class Finance extends Basic
if (empty($this->params['bargain_id'])) { if (empty($this->params['bargain_id'])) {
return $this->response(101, '成交报告id为空'); return $this->response(101, '成交报告id为空');
} }
$field = 'a.id,a.scale,a.agent_id,a.role,a.scale_fee,b.scale as new_scale,b.should_commission,a.create_time,a.father_id,a.create_time'; $field = 'a.id,a.scale,a.agent_id,a.role,a.scale_fee,b.scale as new_scale,b.should_commission,a.father_id,a.create_time,c.income_time';
if ($this->request->isGet()) { if ($this->request->isGet()) {
$data = $this->m_bargain->getBargainPartialDetail($field, [ 'id' => $this->params['bargain_id'] ]); $data = $this->m_bargain->getBargainPartialDetail($field, [ 'id' => $this->params['bargain_id'] ]);
return $this->response(200, '', $data); return $this->response(200, '', $data);
...@@ -2655,12 +2656,12 @@ class Finance extends Basic ...@@ -2655,12 +2656,12 @@ class Finance extends Basic
foreach ($agent_data as $v) { foreach ($agent_data as $v) {
if ($v['id'] == $data_arr['agent_id']) { if ($v['id'] == $data_arr['agent_id']) {
$this->totalOfficialReceipts($v['id'], $v['district_id'], $v['store_id'], $data_arr['create_time']); $this->totalOfficialReceiptsV2($v['id'], $v['district_id'], $v['store_id'], $data['create_time'], $data['income_time']);
$content .= '【分佣方:' . $v['name'] . '-' . $v['phone'].'】'; $content .= '【分佣方:' . $v['name'] . '-' . $v['phone'].'】';
} }
if ($v['id'] == $this->params['agent_id']) { if ($v['id'] == $this->params['agent_id']) {
$this->totalOfficialReceipts($v['id'], $v['district_id'], $v['store_id'], $data_arr['create_time']); $this->totalOfficialReceiptsV2($v['id'], $v['district_id'], $v['store_id'], $data['create_time'], $data['income_time']);
$content .= '【修改为:' . $v['name'] . '-' . $v['phone'] . '】'; $content .= '【修改为:' . $v['name'] . '-' . $v['phone'] . '】';
} }
} }
...@@ -2790,10 +2791,11 @@ class Finance extends Basic ...@@ -2790,10 +2791,11 @@ class Finance extends Basic
if (!empty($where)) { if (!empty($where)) {
//获取被修改人信息 //获取被修改人信息
$m_agent = new AAgents(); $m_agent = new AAgents();
$agent_data = $m_agent->agentBargainAll('a.id,a.store_id,a.district_id,d.income_time', $where); $agent_data = $m_agent->agentBargainOfficeAll('a.id,a.store_id,a.district_id,d.income_time,b.create_time', $where);
foreach ($agent_data as $k=>$v) { foreach ($agent_data as $k=>$v) {
$create_time = date('Y-m-d', strtotime($v['income_time'])); $income_time = date('Y-m-d', strtotime($v['income_time']));
$this->totalOfficialReceipts($v['id'], $v['district_id'], $v['store_id'], $create_time); $create_time = date('Y-m-d', strtotime($v['create_time']));
$this->totalOfficialReceiptsV2($v['id'], $v['district_id'], $v['store_id'], $create_time, $income_time);
} }
$data['status'] = 'successful'; $data['status'] = 'successful';
} }
...@@ -2899,6 +2901,138 @@ class Finance extends Basic ...@@ -2899,6 +2901,138 @@ class Finance extends Basic
return ; return ;
} }
/**
* (临时处理)业绩统计-实收统计
*
*
* @param $agent_id
* @param $district_id
* @param $store_id
* @param string $create_time
* @param string $income_time
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function totalOfficialReceiptsV2($agent_id, $district_id, $store_id, $create_time = '', $income_time = '') {
//获取被修改人信息
$m_agent_total = new TAgentTotalModel();
$where_bargain['agent_id'] = $agent_id;
if (!empty($create_time) && $income_time == $create_time) { //处理同一天
$date = date('Y-m-d', strtotime($create_time));
$where_bargain['create_time'] = ['BETWEEN', [$date.' 00:00:00', $date.' 23:59:59']];
//实收
$receivedSum = $this->m_bargain->getReceivedGroupTimeNew($where_bargain); //1表示业绩 2表示实收
$received_sum = empty($receivedSum[0]["num"]) ? '0.00' : $receivedSum[0]["num"];
//业绩
$performanceSum = $this->m_bargain->getAddBargainNumGroupTimeNew($where_bargain, 1);//1表示业绩 2表示实收
$performance_sum = empty($performanceSum[0]["num"])? '0.00':$performanceSum[0]["num"];
$id = $m_agent_total->getTotalEndTimeByAgentId('id', ['total_time'=>$date, 'agent_id'=>$where_bargain['agent_id']]);
//成交报告
$bargainSum = $this->m_bargain->getAddBargainNumGroupTimeNew($where_bargain, 3);//表示统计
$bargain_sum = empty($bargainSum[0]["num"])? '0.00':$bargainSum[0]['num'];
if (empty($id[0]['id'])) {
if ($received_sum != '0.00' || $performance_sum != '0.00' || $bargain_sum != '0.00') {
$insert_data[] = [
'store_id' => $store_id,
'district_id' => $district_id,
'agent_id' => $agent_id,
'official_receipts' => $received_sum,
'performance' => $performance_sum,
'total_time' => $date,
'bargain_sum' => $bargain_sum,
'create_time' => date('Y-m-d H:i:s')
];
}
} else {
$update_data[] = [
'official_receipts' => $received_sum,
'performance' => $performance_sum,
'bargain_sum' => $bargain_sum,
'id' => $id[0]['id'],
'update_time' => date('Y-m-d H:i:s')
];
}
} else {
//处理时间不一致
if ($create_time) {
$date = date('Y-m-d', strtotime($create_time));
$where_bargain['create_time'] = ['BETWEEN', [$date.' 00:00:00', $date.' 23:59:59']];
//业绩
$performanceSum = $this->m_bargain->getAddBargainNumGroupTimeNew($where_bargain, 1);//1表示业绩 2表示实收
$performance_sum = empty($performanceSum[0]["num"])? 0.00:$performanceSum[0]["num"];
$id = $m_agent_total->getTotalEndTimeByAgentId('id', ['total_time'=>$date, 'agent_id'=>$where_bargain['agent_id']]);
//成交报告
$bargainSum = $this->m_bargain->getAddBargainNumGroupTimeNew($where_bargain, 3);//表示统计
$bargain_sum = empty($bargainSum[0]["num"])? '0.00':$bargainSum[0]['num'];
if (empty($id[0]['id'])) {
if ($performance_sum != '0.00' || $bargain_sum != '0.00') {
$insert_data[] = [
'store_id' => $store_id,
'district_id' => $district_id,
'agent_id' => $agent_id,
'official_receipts'=> 0,
'performance' => $performance_sum,
'total_time' => $date,
'bargain_sum' => $bargain_sum,
'create_time' => date('Y-m-d H:i:s')
];
}
} else {
$update_data[] = [
'performance' => $performance_sum,
'bargain_sum' => $bargain_sum,
'id' => $id[0]['id'],
'update_time' => date('Y-m-d H:i:s')
];
}
}
//实收
if ($income_time) {
$date = date('Y-m-d', strtotime($income_time));
$where_bargain['create_time'] = ['BETWEEN', [$date.' 00:00:00', $date.' 23:59:59']];
$receivedSum = $this->m_bargain->getReceivedGroupTimeNew($where_bargain);
$received_sum = empty($receivedSum[0]["num"]) ? '0.00' : $receivedSum[0]["num"];
$id = $m_agent_total->getTotalEndTimeByAgentId('id', ['total_time'=>$date, 'agent_id'=>$where_bargain['agent_id']]);
if (empty($id[0]['id'])) {
if ($received_sum != '0.00') {
$insert_data[] = [
'store_id' => $store_id,
'district_id' => $district_id,
'agent_id' => $agent_id,
'official_receipts' => $received_sum,
'performance' => 0,
'total_time' => $date,
'bargain_sum' => 0,
'create_time' => date('Y-m-d H:i:s')
];
}
} else {
$update_data[] = [
'official_receipts' => $received_sum,
'id' => $id[0]['id'],
'update_time' => date('Y-m-d H:i:s')
];
}
}
}
if (isset($insert_data)) {
$m_agent_total->addTotal($insert_data);
}
if (isset($update_data)) {
$m_agent_total->saveTotal($update_data);
}
return ;
}
/** /**
* 收款记录 * 收款记录
* *
...@@ -4800,7 +4934,7 @@ class Finance extends Basic ...@@ -4800,7 +4934,7 @@ class Finance extends Basic
$msg = ''; $msg = '';
$where['a.status'] = ['in', '20,21']; $where['a.status'] = ['in', '20,21'];
$where[] = ['EXP', 'a.id ='.$this->params['id'].' OR a.father_id='.$this->params['id']]; $where[] = ['EXP', 'a.id ='.$this->params['id'].' OR a.father_id='.$this->params['id']];
$agent_arr = $this->m_bargain->agentBargainAll('a.create_time,a.agent_id,b.store_id,b.district_id', $where); $agent_arr = $this->m_bargain->agentBargainIncome('a.agent_id,b.store_id,b.district_id,a.create_time,d.income_time', $where);
if (empty($agent_arr)) { if (empty($agent_arr)) {
return $this->response($code, '没有该记录'); return $this->response($code, '没有该记录');
...@@ -4814,7 +4948,7 @@ class Finance extends Basic ...@@ -4814,7 +4948,7 @@ class Finance extends Basic
if ($is_ok) { if ($is_ok) {
foreach ($agent_arr as $k=>$v) { foreach ($agent_arr as $k=>$v) {
try { try {
$this->totalOfficialReceipts($v['agent_id'], $v['district_id'], $v['store_id'], $v['create_time']); $this->totalOfficialReceiptsV2($v['agent_id'], $v['district_id'], $v['store_id'], $v['create_time'], $v['income_time']);
$code = 200; $code = 200;
} catch (\Exception $e) { } catch (\Exception $e) {
$msg = '恢复失败:'.$e->getMessage(); $msg = '恢复失败:'.$e->getMessage();
......
...@@ -778,7 +778,6 @@ class OfficeBargain extends Basic ...@@ -778,7 +778,6 @@ class OfficeBargain extends Basic
} }
if (!empty($content)) { if (!empty($content)) {
dump($father_id);die;
$this->editRecordLog($father_id, '【编号:' . $father_id . '】'.$content); $this->editRecordLog($father_id, '【编号:' . $father_id . '】'.$content);
} }
/*记录日志 end*/ /*记录日志 end*/
......
...@@ -1367,6 +1367,7 @@ class OBargainModel extends Model ...@@ -1367,6 +1367,7 @@ class OBargainModel extends Model
->field($filed) ->field($filed)
->alias("a") ->alias("a")
->join("o_partial_commission b", "a.id = b.bargain_id", "left") ->join("o_partial_commission b", "a.id = b.bargain_id", "left")
->join("o_real_income c", "b.real_income_id = c.id", "left")
->where($where_) ->where($where_)
->whereOr($whereOr_) ->whereOr($whereOr_)
->order("a.id asc") ->order("a.id asc")
...@@ -1631,6 +1632,24 @@ class OBargainModel extends Model ...@@ -1631,6 +1632,24 @@ class OBargainModel extends Model
->select(); ->select();
} }
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentBargainIncome($field, $where) {
return $this->db_->alias('a')
->field($field)
->join('a_agents b', 'a.agent_id = b.id', 'left')
->join('office_o_partial_commission c', 'a.id = c.bargain_id', 'left')
->join('office_o_real_income d', 'c.real_income_id = d.id', 'left')
->where($where)
->select();
}
/** /**
* @param $field * @param $field
* @param $where * @param $where
......
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