111 lines
5.3 KiB
PHP
111 lines
5.3 KiB
PHP
<?php
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Desc: 企业微信机器人
|
|
* Date: 2021/10/09
|
|
* Time: 11:01
|
|
*/
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Qyrobot{
|
|
|
|
private $key = 'dfed1a38-c4e0-4904-94eb-306e9755be04'; //正式
|
|
private $ci;
|
|
public function __construct($params=[]){
|
|
$this->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
|
|
恭喜 <font color=\"warning\">{$biz_info}</font> 成交 <font color=\"warning\">{$car_info}</font> 一台。\n
|
|
>本日累计成交: <font color=\"warning\">{$today_count}</font> 单
|
|
>本月累计成交: <font color=\"warning\">{$month_count}</font> 单\n
|
|
### 狸车加油,冲冲冲!💪🏻💪🏻💪🏻"
|
|
]
|
|
];
|
|
$res = $this->ci->mycurl->httpPost($url,$data,'is_json');
|
|
$result = json_decode($res,true);
|
|
return $result;
|
|
}
|
|
}
|