jh-admin/addon/weapp/model/WxFuwuNotify.php

187 lines
6.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* SAAS应用系统 --- 十年开发经验汇集巨献!
* ==========================================================
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
* ----------------------------------------------------------
* 官方网址: https://www.zoomtk.com
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
* ==========================================================
*/
namespace addon\weapp\model;
use app\model\system\Site;
use app\model\store\Store;
use think\facade\Db;
use think\facade\Log;
class WxFuwuNotify
{
public function Notify($param = [])
{
Log::write('微信服务市场回调通知:' . json_encode($param, JSON_UNESCAPED_UNICODE));
$param['AesContentArray'] = $this->decrypt($param['AesContent']);
if (!empty($param['AesContentArray'])) {
switch ($param['type']) {
case 6: //服务订单通知
$this->servicemarketOrderNotify($param);
break;
}
}
}
/***
* 用户小程序订购
*/
public function servicemarketOrderNotify($param)
{
$user_id = $param['AesContentArray']['ContentArray']['openId'];
$data = [
'ag_site_id' => 1,
'cloud_goods_id' => $param['AesContentArray']['ContentArray']['serviceId'],
'spec' => $param['AesContentArray']['ContentArray']['specId'],
'order_id' => $param['AesContentArray']['ContentArray']['orderId'],
'third_order_id' => $param['AesContentArray']['ContentArray']['orderId'],
'original_id' => $user_id,
'type' => 'wxcloud',
'pay_status' => $param['AesContentArray']['ContentArray']['event'],
'money' => $param['AesContentArray']['ContentArray']['amount'],
'contact_name' => $param['AesContentArray']['ContentArray']['appName'],
'mobile' => $param['AesContentArray']['ContentArray']['phone'],
'raw_data' => json_encode($param),
'update_time' => time(),
'apps_id' => $param['AesContentArray']['ContentArray']['appId'],
];
$shopInfo = $this->createShop($data); //创建店铺
if ($shopInfo['data']['code'] == 0) {
$data['site_id'] = $shopInfo['data']['data'];
} else {
$data['site_id'] = Db::name('site')->where(['username' => $data['mobile']])->value('site_id');
}
// 创建门店
$storeInfo = $this->createStore($data);
$where = [
'original_id' => $user_id,
'third_order_id' => $data['third_order_id'],
];
$info = Db::name('cloud_order')->where($where)->find();
if ($info) {
Db::name('cloud_order')->where($where)->update($data);
} else {
$data['create_time'] = time();
Db::name('cloud_order')->insert($data);
}
echo '{"errcode": 0, "errmsg" :"成功"}';
}
/***
* 云订单
* @param $data
* @return array
*/
public function createShop($data)
{
//店铺信息
$shop_data = [
'site_name' => $data['contact_name'], //店铺名称
'contacts_name' => $data['contact_name'], //联系人
'contacts_mobile' => $data['mobile'], //联系电话
'agent_id' => $data['ag_site_id'], //所属代理
'group_id' => 1,
'expire_time' => 0,
'is_try' => 0, //是否体验用户
];
$username = $data['mobile'] ?? $data['original_id'];
$user_info = [
'username' => $username,
'password' => data_md5('888888'),
];
$site_model = new Site();
$result = $site_model->addSite($shop_data, $user_info, false);
if ($result['code'] == 0) {
$log = array(
"uid" => 0,
"username" => $username,
"site_id" => $data['ag_site_id'],
"url" => '',
"ip" => request()->ip(),
"data" => json_encode($shop_data),
"action_name" => '云市场自动注册店铺',
"create_time" => time(),
);
model("user_log")->add($log);
}
return success('0', '注册成功', $result);
}
/**
* 创建门店
* @return array
*/
public function createStore($data){
$storeInfo = model('store')->getInfo([['site_id', '=', $data['site_id']]]);
if(!empty($storeInfo)){
return error(-1,'已有门店');
}
$is_store = addon_is_exit('store');
$store_data = array (
"store_name" => $data['contact_name'],
"telphone" => $data['mobile'],
"store_image" => '',
"status" => 1,
"province_id" => 510000,
"city_id" => 510100,
"district_id" => 510105,
"community_id" => 0,
"address" => '西御街',
"full_address" => '四川省,成都市,青羊区',
"longitude" => '104.064278',
"latitude" => '30.65649',
'is_pickup' => 0,
"open_date" => '上午9:00-12:00下午2:00-6:00',
"site_id" => $data['site_id'],
'start_time' => 0,
'end_time' => 0,
'time_type' => 0,
'time_week' => '',
'stock_type' => 'all',
'time_interval' => 30,
'delivery_time' => '',
'advance_day' => 0,
'most_day' => 7
);
//判断是否开启多门店
if ($is_store == 1) {
$user_data = [
'username' => $data['mobile'],
'password' => data_md5('888888'),
];
} else {
$user_data = [];
}
$storeModel = new Store();
return $storeModel->addStore($store_data, $user_data, $is_store);
}
public function decrypt($AesContent)
{
// Encoding-AESKey前16位在服务平台主页——基础设置——消息推送设置——通用消息推送处设置
$encryption_key = substr(config('wechat.wxFuwu.encoding_aes_key'),0,16);
$iv = $encryption_key;
$decrypted = openssl_decrypt($AesContent, 'aes-128-cbc', $encryption_key, 0, $iv);
$decryptedArray = json_decode($decrypted, true);
$decryptedArray['ContentArray'] = json_decode($decryptedArray['Content'], true);
return $decryptedArray;
}
}