diff --git a/agent/admin/controllers/pingan/cmmssn/Cmmssn.php b/agent/admin/controllers/pingan/cmmssn/Cmmssn.php new file mode 100644 index 00000000..9a631bc8 --- /dev/null +++ b/agent/admin/controllers/pingan/cmmssn/Cmmssn.php @@ -0,0 +1,141 @@ +load->model('agent/pingan/pingan_users_model', 'pinganUsers'); + + $this->load->model('agent/pingan/pingan_users_cmmssn_model', 'cmmssn_model'); + $this->load->model('receiver/receiver_clues_model'); + $this->load->model('receiver/receiver_customers_model'); + $this->load->model('receiver/order/receiver_orders_model'); + $this->load->model('biz/biz_model'); + $this->receiver_clues_model->set_db('ssdb'); + $this->receiver_customers_model->set_db('ssdb'); + $this->receiver_orders_model->set_db('ssdb'); + $this->biz_model->set_db('ssdb'); + } + + public function index_get() + { + $params = $this->input_param(); + $data = $this->cmmssnList($params); + $this->return_response($data); + } + + public function export_get() + { + $this->inputs['page'] = 1; + $this->inputs['limit'] = 20000; + $data = $this->cmmssnList($this->inputs); + $this->return_response_list($data); + } + + public function index_put() + { + $params = $this->input_param(); + $row = $this->cmmssn_model->get(['id' => $params['id']]); + if (!$row) { + $this->return_json('参数错误'); + } + if ($row['ifSend']) { + $this->return_json('已设置发放'); + } + $updateData = [ + 'ifSend' => Pingan_users_cmmssn_model::IF_SEND_YES, + 'sendTime' => date('Y-m-d H:i:s') + ]; + $res = $this->cmmssn_model->update($updateData, ['id' => $row['id']]); + if (!$res) { + $this->return_json('保存失败'); + } + $this->return_response(); + } + + private function cmmssnList($params) + { + $list = []; + $page = $params['page'] ?: 1; + $limit = $params['limit'] ?: 10; + $where = []; + if ($params['type']) { + if ($params['type'] == 1) { //线索 + $cfType = Pingan_users_cmmssn_model::CF_TYPE_CLUES_OWN . ',' . Pingan_users_cmmssn_model::CF_TYPE_CLUES_TEAM; + } else { //订单 + $cfType = Pingan_users_cmmssn_model::CF_TYPE_ORDER_OWN . ',' . Pingan_users_cmmssn_model::CF_TYPE_ORDER_TEAM; + } + $where["cfType in ({$cfType})"] = null; + } + if ($params['username']) { + $where["pinganUserId in (select id from lc_pingan_users where username like '%{$params['username']}%')"] = null; + } + if (strlen($params['ifSend'])) { + $where["ifSend"] = intval($params['ifSend']); + } + $count = $this->cmmssn_model->count($where); + if ($count) { + $rows = $this->cmmssn_model->select($where, 'id desc', $page, $limit); + $bizIdArray = array_unique(array_column($rows, 'bizId')); + $bizIdIds = $bizIdArray ? implode(',', $bizIdArray) : 0; + $where = ["id in ({$bizIdIds})" => null]; + $bizMap = $this->biz_model->map('id', 'biz_name', $where, '', '', '', 'id,biz_name'); + //获取坐席 + $userIdArray = array_unique(array_column($rows, 'pinganUserId')); + $userIds = $userIdArray ? implode(',', $userIdArray) : 0; + $where = ["id in ({$userIds})" => null]; + $userMap = $this->pinganUsers->map('id', '', $where, '', '', 'id,centerNumber,username,userCode,orgName'); + foreach ($rows as $item) { + $customer = []; + $order = []; + $user = $userMap[$item['pinganUserId']] ? $userMap[$item['pinganUserId']][0] : []; + if (in_array($item['cfType'], [Pingan_users_cmmssn_model::CF_TYPE_CLUES_OWN, Pingan_users_cmmssn_model::CF_TYPE_CLUES_TEAM])) { //线索 + $customer = $this->receiver_customers_model->get(['rid' => $item['cfId'], 'un_lock' => Receiver_customers_model::LOCK_STATUS]); + $order = $this->receiver_orders_model->get(['clue_id' => $item['cfId']]); + } + if (in_array($item['cfType'], [Pingan_users_cmmssn_model::CF_TYPE_ORDER_OWN, Pingan_users_cmmssn_model::CF_TYPE_ORDER_TEAM])) { //订单 + $order = $this->receiver_orders_model->get(['id' => $item['cfId']]); + $order['customer_id'] && $customer = $this->receiver_customers_model->get(['id' => $order['customer_id']]); + } + if ($limit >= 10000) { + $list[] = [ + 'mobile' => $customer['mobile'] ?: '', + 'bizName' => $bizMap[$item['bizId']] ?: '', + 'centerName' => Pingan_users_model::TYPE_CENTER[$user['centerNumber']] ?: '', + 'orgName' => $user['orgName'] ?: '', + 'userName' => $user['username'] ?: '', + 'userCode' => $user['userCode'] ?: '', + 'unlockTime' => strtotime($customer['unlock_time']) > 0 ? $customer['unlock_time'] : '', + 'orderTime' => $order['order_time'] ?: '', + 'money' => $item['money'] + ]; + } else { + $list[] = [ + 'id' => $item['id'], + 'mobile' => $customer['mobile'] ?: '', + 'bizName' => $bizMap[$item['bizId']] ?: '', + 'centerName' => Pingan_users_model::TYPE_CENTER[$user['centerNumber']] ?: '', + 'userName' => $user['username'] ?: '', + 'userCode' => $user['userCode'] ?: '', + 'orgName' => $user['orgName'] ?: '', + 'unlockTime' => strtotime($customer['unlock_time']) > 0 ? $customer['unlock_time'] : '', + 'orderTime' => $order['order_time'] ?: '', + 'typeCn' => Pingan_users_cmmssn_model::CF_TYPE_CN[$item['cfType']] ?: '', + 'money' => $item['money'], + 'sendCn' => Pingan_users_cmmssn_model::IF_SEND_CN[$item['ifSend']] ?: '', + 'ifSend' => $item['ifSend'], + ]; + } + } + } + $columns = []; + if ($limit >= 10000) { + $columns = ['线索', '解锁门店', '中心', '机构', '坐席', '坐席工号', '解锁时间', '订单时间', '佣金']; + } + return ['list' => $list, 'count' => $count, 'columns' => $columns]; + } +} \ No newline at end of file diff --git a/common/models/agent/pingan/Pingan_users_cmmssn_model.php b/common/models/agent/pingan/Pingan_users_cmmssn_model.php index 8d02fce2..ea374256 100644 --- a/common/models/agent/pingan/Pingan_users_cmmssn_model.php +++ b/common/models/agent/pingan/Pingan_users_cmmssn_model.php @@ -16,6 +16,13 @@ class Pingan_users_cmmssn_model extends HD_Model self::CF_TYPE_CLUES_OWN => '线索', //自有线索 self::CF_TYPE_CLUES_TEAM => '线索' //团队线索 ]; + //是否发放 + const IF_SEND_NO = 0; //否 + const IF_SEND_YES = 1; //是 + const IF_SEND_CN = [ + self::IF_SEND_NO => '否', + self::IF_SEND_YES => '是' + ]; public function __construct() {