ci = & get_instance();
if($_SERVER['CI_ENV'] == 'development' || $params['test']){ //测试环境
$this->key = '0b644923-4e5c-46be-9a87-6dfcb023d09c';
}
}
/**
* 支付定金推送消息
* @param $oid (lc_receiver_orders表)订单id
*/
public function deposit_notify($oid){
$this->ci->load->model('receiver/order/receiver_orders_model');
$this->ci->load->model("biz/biz_model");
$this->ci->load->model('area_model');
$this->ci->load->model('auto/auto_brand_model');
$this->ci->load->model('auto/auto_series_model');
$this->ci->load->model('auto/auto_attr_model');
$this->ci->load->model('app/liche/app_liche_orders_model');
$this->ci->load->model('app/liche/app_liche_orders_model');
$this->ci->load->model('app/licheb/app_licheb_users_model');
$this->ci->load->model('app/licheb/app_licheb_channel_biz_model');
$order_row = $this->ci->receiver_orders_model->get(['id'=>$oid]);
if(!$order_row){
return false;
}
$biz_row = $this->ci->biz_model->get(['id'=>$order_row['biz_id']]);
if($biz_row['type']==3){
$channel_users = $this->ci->app_licheb_channel_biz_model->select(['biz_id'=>$biz_row['id']],'','','','uid');
$user_ids = array_column($channel_users,'uid');
$user_ids_str = implode(',',$user_ids);
if($user_ids_str && $user_ids){
$where = [
'group_id' => 4,
'status' => 1,
"id in ($user_ids_str)" => null
];
$users = $this->ci->app_licheb_users_model->select($where,'id desc',1,10,'uname,biz_id'); //渠道经理
$user_info = '';
if($users){
$user_info = implode(' ',array_column($users,'uname'));
}else{ //获取城市
$city_row = $this->ci->area_model->get(['city_id'=>$biz_row['city_id']]);
$user_info = $city_row['city_name'];
}
}
$biz_info = "{$user_info}渠道 {$biz_row['biz_name']}";
}else{
$user = $this->ci->app_licheb_users_model->get(['id'=>$order_row['admin_id']],'uname'); //获取销售员
$biz_info = "{$biz_row['biz_name']} {$user['uname']}";
}
$brand_row = $this->ci->auto_brand_model->get(['id'=>$order_row['brand_id']],'name');
$series_row = $this->ci->auto_series_model->get(['id'=>$order_row['s_id']],'name');
$attr_arr = [$order_row['v_id'], $order_row['cor_id']];
$attr = $this->ci->auto_attr_model->get_map_by_ids($attr_arr, 'id,title');
$v_name = isset($attr[$order_row['v_id']]) ? $attr[$order_row['v_id']][0]['title'] : '';
$cor_name = isset($attr[$order_row['cor_id']]) ? $attr[$order_row['cor_id']][0]['title'] : '';
$car_info = "{$brand_row['name']} {$series_row['name']} {$v_name} {$cor_name}";
$where = [
'type' => 1,
'status' => 1,
'pay_price>=' => 100
];
$where["pay_time>="] = date('Y-m-d 00:00:00');
$today_count = $this->ci->app_liche_orders_model->count($where);//今日成交订单数
$where['pay_time>='] = date('Y-m-01 00:00:00');
$month_count = $this->ci->app_liche_orders_model->count($where);//本月成交订单数
//意向金等于定金的支付订单
$sql = "select count(*) as total from lc_app_liche_orders as a left join lc_receiver_orders as b on a.o_id=b.id where a.total_price=b.deposit and a.type=4 and a.status=1 and a.pay_price>=50 and a.pay_time>='".date('Y-m-d 00:00:00')."'";
$today_query = $this->ci->db->query($sql)->row_array();
$sql = "select count(*) as total from lc_app_liche_orders as a left join lc_receiver_orders as b on a.o_id=b.id where a.total_price=b.deposit and a.type=4 and a.status=1 and a.pay_price>=50 and a.pay_time>='".date('Y-m-01 00:00:00')."'";
$month_query = $this->ci->db->query($sql)->row_array();
$today_query['total'] && $today_count += $today_query['total'];
$month_query['total'] && $month_count += $month_query['total'];
$url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$this->key;
$this->ci->load->library('mycurl');
$data = [
'msgtype' => 'markdown',
'markdown' => [
'content' => "🎉🎉🎉 **喜讯** 🎉🎉🎉 \n
恭喜 {$biz_info} 成交 {$car_info} 一台。\n
>本日累计成交: {$today_count} 单
>本月累计成交: {$month_count} 单\n
### 狸车加油,冲冲冲!💪🏻💪🏻💪🏻"
]
];
$res = $this->ci->mycurl->httpPost($url,$data,'is_json');
$result = json_decode($res,true);
return $result;
}
/**
* 支付后推送消息
* @param $oid
* @return mixed
*/
public function deposit_notify_v2($oid){
$this->ci->load->model('receiver/order/receiver_orders_v2_model');
$this->ci->load->model("biz/biz_model");
$this->ci->load->model('area_model');
$this->ci->load->model('auto/auto_brand_model');
$this->ci->load->model('auto/auto_series_model');
$this->ci->load->model('auto/auto_attr_model');
$this->ci->load->model('app/liche/app_liche_orders_model');
$this->ci->load->model('app/liche/app_liche_orders_model');
$this->ci->load->model('app/licheb/app_licheb_users_model');
$this->ci->load->model('app/licheb/app_licheb_channel_biz_model');
$order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]);
if(!$order_row){
return false;
}
$biz_row = $this->ci->biz_model->get(['id'=>$order_row['biz_id']]);
if($biz_row['type']==3){
$channel_users = $this->ci->app_licheb_channel_biz_model->select(['biz_id'=>$biz_row['id']],'','','','uid');
$user_ids = array_column($channel_users,'uid');
$user_ids_str = implode(',',$user_ids);
$user_info = '';
if($user_ids_str && $user_ids){
$where = [
'group_id' => 4,
'status' => 1,
"id in ($user_ids_str)" => null
];
$users = $this->ci->app_licheb_users_model->select($where,'id desc',1,10,'uname,biz_id'); //渠道经理
if($users){
$user_info = implode(' ',array_column($users,'uname'));
}else{ //获取城市
$city_row = $this->ci->area_model->get(['city_id'=>$biz_row['city_id']]);
$user_info = $city_row['city_name'];
}
}
$biz_info = "{$user_info}渠道 {$biz_row['biz_name']}";
}else{
$user = $this->ci->app_licheb_users_model->get(['id'=>$order_row['admin_id']],'uname'); //获取销售员
$biz_info = "{$biz_row['biz_name']} {$user['uname']}";
}
$brand_row = $this->ci->auto_brand_model->get(['id'=>$order_row['brand_id']],'name');
$series_row = $this->ci->auto_series_model->get(['id'=>$order_row['s_id']],'name');
$attr_arr = [$order_row['v_id'], $order_row['cor_id']];
$attr = $this->ci->auto_attr_model->get_map_by_ids($attr_arr, 'id,title');
$v_name = isset($attr[$order_row['v_id']]) ? $attr[$order_row['v_id']][0]['title'] : '';
$cor_name = isset($attr[$order_row['cor_id']]) ? $attr[$order_row['cor_id']][0]['title'] : '';
$car_info = "{$brand_row['name']} {$series_row['name']} {$v_name} {$cor_name}";
$min_price = 100;
$today_s_time = date('Y-m-d 00:00:00');
$sql = "select count(*) as total from (select min(pay_time) as pay_time,min(pay_price) as pay_price from lc_app_liche_orders
where o_id>=10000 and status=1 and pid!=0 and pay_time!='0000-00-00 00:00:00' group by o_id order by o_id desc)a
where pay_price>{$min_price} and pay_time>='{$today_s_time}'";
$today_query = $this->ci->db->query($sql)->row_array();
$month_s_time = date('Y-m-01 00:00:00');
$sql = "select count(*) as total from (select min(pay_time) as pay_time,min(pay_price) as pay_price from lc_app_liche_orders
where o_id>=10000 and status=1 and pid!=0 and pay_time!='0000-00-00 00:00:00' group by o_id order by o_id desc)a
where pay_price>{$min_price} and pay_time>='{$month_s_time}'";
$month_query = $this->ci->db->query($sql)->row_array();
$today_count = $today_query['total'];
$month_count = $month_query['total'];
$url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$this->key;
$this->ci->load->library('mycurl');
$data = [
'msgtype' => 'markdown',
'markdown' => [
'content' => "🎉🎉🎉 **喜讯** 🎉🎉🎉 \n
恭喜 {$biz_info} 成交 {$car_info} 一台。\n
>本日累计成交: {$today_count} 单
>本月累计成交: {$month_count} 单\n
### 狸车加油,冲冲冲!💪🏻💪🏻💪🏻"
]
];
$res = $this->ci->mycurl->httpPost($url,$data,'is_json');
$result = json_decode($res,true);
return $result;
}
}