Files
liche/admin/libraries/HdyServer.php
T
2021-07-05 09:56:27 +08:00

209 lines
11 KiB
PHP

<?php
/**
* Notes:好店服务公众号操作
* Created on: 2020/6/22 10:00
* Created by: dengbw
*/
class HdyServer
{
static $app_id = 6;//小程序id
private $ci;
private $api_url = "http://api.haodian.cn";
public function __construct()
{
$this->ci = &get_instance();
if (false !== strpos($_SERVER['HTTP_HOST'], 'dev')) { //dev 测试
$this->api_url = 'http://hd-api-dev.xiaoyu.com';
} elseif (false !== strpos($_SERVER['HTTP_HOST'], 'test')) {//test 测试
$this->api_url = 'http://api.test.haodian.cn';
} else { // 正式
$this->api_url = 'http://api.haodian.cn';
}
}
/**
* Notes:获取二维码图片
* Created on: 2020/6/22 10:18
* Created by: dengbw
* @param $params
* @return array
*/
function get_qrurl($params)
{
$this->ci->load->model("/sys/sys_admin_model", 'mdSysAdmin');
$scene = $qrcode = $mobile = '';
if ($params['act_type'] == 1) {
$re = $this->ci->mdSysAdmin->get(array('id' => $params['uid']), 'mobile');
$mobile = $re['mobile'];
$re['mobile'] && $scene = 'mobile=' . $mobile;
}
$post_data = array("scene" => $scene, 'type' => $params['type']);
$result = http_post_com($this->api_url . '/wechat/haodianyun/get_qrurl', $post_data);
$qrcode = $result['data'] ? $result['data'] : '';
return array('mobile' => $mobile, 'qrcode' => $qrcode);
}
/**
* Notes:商家发送公众号通知
* Created on: 2020/6/22 17:45
* Created by: dengbw
* @param $params type 1订单加日志 2订单结算状态
*/
function biz_send_template($params)
{
$this->ci->load->model('user/user_biz_model', 'mdUserBiz');
$this->ci->load->model('user/user_model', 'mdUser');
$reUserBiz = array();
if ($params['biz_id']) {
$reUserBiz = $this->ci->mdUserBiz->select(array('biz_id' => $params['biz_id'], 'type' => 1)
, 'id ASC', 0, 0, 'uid');
} else if ($params['brand_id']) {
$reUserBiz = $this->ci->mdUserBiz->select(array('brand_id' => $params['brand_id'], 'type' => 0)
, 'id ASC', 0, 0, 'uid');
}
if ($reUserBiz) {//给商家发送公众号通知
$this->ci->load->model('app/App_model', 'mdApp');
$this->ci->load->model('app/App_wechat_model', 'mdWechat');
$appConfig = $this->ci->mdApp->appConfig()[self::$app_id];
foreach ($reUserBiz as $key => $value) {
$reUser = $this->ci->mdUser->get(array('uid' => $value['uid'], 'status' => 1), 'mobile');
if ($reUser['mobile']) {
$reWechat = $this->ci->mdWechat->get(array('app_id' => self::$app_id, 'mobile' => $reUser['mobile']), 'openid');
if ($reWechat['openid']) {
$temp_ary = array();
$pagepath = $params['id'] ? $appConfig['wx']['pages_order_detail'] . '?id=' . $params['id']
: $appConfig['wx']['pages_order'];
if ($params['type'] == 1) {
$temp_ary = array(
'touser' => $reWechat['openid'],
'template_id' => 'f9ZGhhddKg3ysYH8ZzE8onH_c_ho3hdRfj-B4l9r5Rg',
'miniprogram' => array(
'appid' => $appConfig['wx']['appid'],
'pagepath' => $pagepath
),
'data' => array(
'first' => array('value' => '商户经理' . $params['username'] . '新增一条小记'),
'keyword1' => array('value' => '新增小记'),
'keyword2' => array('value' => date('Y-m-d H:i:s')),
'remark' => array('value' => $params['log'])
)
);
} else if ($params['type'] == 2) {
$temp_ary = array(
'touser' => $reWechat['openid'],
'template_id' => 'f9ZGhhddKg3ysYH8ZzE8onH_c_ho3hdRfj-B4l9r5Rg',
'miniprogram' => array(
'appid' => $appConfig['wx']['appid'],
'pagepath' => $pagepath
),
'data' => array(
'first' => array('value' => '商户经理' . $params['username'] . '更新了订单结算状态'),
'keyword1' => array('value' => $params['status_name_up']),
'keyword2' => array('value' => date('Y-m-d H:i:s')),
'remark' => array('value' => $params['log'])
)
);
}
$temp_ary && http_post_com($this->api_url . '/wechat/haodianyun/send_template', $temp_ary);
}
}
}
}
}
/**
* Notes:派单给商家/商户经理发送公众号通知
* Created on: 2020/6/24 9:56
* Created by: dengbw
* @param $params
*/
function orders_send_template($params)
{
$this->ci->load->model('app/App_model', 'mdApp');
$this->ci->load->model('app/App_wechat_model', 'mdWechat');
$this->ci->load->model('app/jdb/receiver_model', 'mdReceiver');
$this->ci->load->model('sys/Sys_admin_model', 'mdSysAdmin');
$appConfig = $this->ci->mdApp->appConfig()[self::$app_id];
if ($params['biz']) {//商家
foreach ($params['biz'] as $key => $value) {
$reWechat = $this->ci->mdWechat->get(array('app_id' => self::$app_id, 'mobile' => $value['mobile']), 'openid');
if ($reWechat['openid']) {
$remark = '截止' . date('m-d H:i') . ',您本月总共收到' . $value['count'] . '条订单';
$pagepath = $value['order_id'] ? $appConfig['wx']['pages_order_detail'] . '?id=' . $value['order_id']
: $appConfig['wx']['pages_order'];
$temp_ary = array(
'touser' => $reWechat['openid'],
'template_id' => 'SPpgqoIexkTHubovh6-ZySbWLUFG52ixpa8a-BcJEJQ',
'miniprogram' => array(
'appid' => $appConfig['wx']['appid'],
'pagepath' => $pagepath
),
'data' => array(
'first' => array('value' => '您有一条新订单!请及时联系!'),
'tradeDateTime' => array('value' => date('Y-m-d H:i:s')),
'orderType' => array('value' => '新订单'),
'customerInfo' => array('value' => $value['rc_name']),
'orderItemName' => array('value' => '小区名称'),
'orderItemData' => array('value' => $value['rc_community']),
'remark' => array('value' => $remark)
),
);
http_post_com($this->api_url . '/wechat/haodianyun/send_template', $temp_ary);
}
}
}
if ($params['manager']) {//商户经理
$brands = array();
$reReceiver = $this->ci->mdReceiver->get(array('id' => $params['rid']), 'managers');
if ($reReceiver['managers']) {
$managers = json_decode($reReceiver['managers'], true);
foreach ($managers as $key => $value) {
foreach ($value['brands'] as $key2 => $value2) {
$brands[$value2['id']] = $value['admin_id'];
}
}
}
foreach ($params['manager'] as $key => $value) {
$admin_id = $brands[$value['brand_id']];
if ($admin_id) {
$reAdmin = $this->ci->mdSysAdmin->get(array('id' => $admin_id), 'mobile');
$reWechat = $this->ci->mdWechat->get(array('app_id' => self::$app_id, 'mobile' => $reAdmin['mobile']), 'openid');
if ($reWechat['openid']) {
$remark = '截止' . date('m-d H:i') . ',(' . $value['brand_name'] . ')本月总共收到' . $value['count'] . '条订单';
$temp_ary = array(
'touser' => $reWechat['openid'],
'template_id' => 'SPpgqoIexkTHubovh6-ZySbWLUFG52ixpa8a-BcJEJQ',
'data' => array(
'first' => array('value' => $value['brand_name'] . '有一条新订单!请及时跟进'),
'tradeDateTime' => array('value' => date('Y-m-d H:i:s')),
'orderType' => array('value' => '新订单'),
'customerInfo' => array('value' => $value['brand_name']),
'orderItemName' => array('value' => '商家状态'),
'orderItemData' => array('value' => '待处理'),
'remark' => array('value' => $remark)
),
);
http_post_com($this->api_url . '/wechat/haodianyun/send_template', $temp_ary);
if ($value['prompt']) { //到达预警值会给商户经理发送续费通知
$remark = date('Y-m-d H:i:s') . '您对接的商家' . $value['brand_name'] . $value['prompt'];
$temp_ary2 = array(
'touser' => $reWechat['openid'],
'template_id' => 'Bbh8oxPcr-WzHDze9fui2XT0WNstIx9dWYslX6nwNCU',
'data' => array(
'first' => array('value' => $value['brand_name'] . '到达预警值!请及时跟进'),
'keyword1' => array('value' => '到达预警值'),
'keyword2' => array('value' => '紧急'),
'remark' => array('value' => $remark)
),
);
http_post_com($this->api_url . '/wechat/haodianyun/send_template', $temp_ary2);
}
}
}
}
}
}
}