Files
liche/common/libraries/Qyrobot.php
T
2021-10-09 14:43:46 +08:00

96 lines
3.8 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(){
$this->ci = & get_instance();
if($_SERVER['CI_ENV'] == 'development'){ //测试环境
$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('auto/auto_brand_model');
$this->ci->load->model('auto/auto_series_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');
$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){
$where = [
'group_id' => 4,
'status' => 1,
"biz_id like '%{$biz_row['id']}%'" => null
];
$users = $this->ci->app_licheb_users_model->select($where,'id desc',1,10,'uname,biz_id'); //渠道经理
$user_info = '';
if($users){
foreach($users as $key=>$val){
$biz_id_arr = explode(',',$val['biz_id']);
if(!in_array($biz_row['id'],$biz_id_arr)){
unset($users[$key]);
}
}
$user_info = implode(' ',array_column($users,'uname'));
}
$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');
$car_info = "{$brand_row['name']} {$series_row['name']}";
$where = [
'o_id' => $order_row['id'],
'type' => 1,
'status' => 1,
'pay_price>=' => 100
];
$where['c_time>='] = strtotime(date('Y-m-d 00:00:00'));
$where['c_time<='] = time();
$today_count = $this->ci->app_liche_orders_model->count($where);//今日成交订单数
$where['c_time>='] = strtotime(date('Y-m-01 00:00:00'));
$month_count = $this->ci->app_liche_orders_model->count($where);//本月成交订单数
$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;
}
}