1283 lines
56 KiB
PHP
1283 lines
56 KiB
PHP
![]() |
<?php
|
|||
|
|
|||
|
namespace app\controllers\channel;
|
|||
|
|
|||
|
use app\models\common\WeChatPay;
|
|||
|
use Illuminate\Support\Facades\DB;
|
|||
|
use Yii;
|
|||
|
use app\models\common\Config;
|
|||
|
use app\models\common\Store;
|
|||
|
use app\models\common\WeChat;
|
|||
|
use app\models\common\Power;
|
|||
|
use app\models\common\Ali;
|
|||
|
use EasyWeChat\Factory;
|
|||
|
use OSS\OssClient;
|
|||
|
use app\models\common\Delivery;
|
|||
|
use app\models\common\ZiJie;
|
|||
|
|
|||
|
class ConfigController extends CommonController
|
|||
|
{
|
|||
|
public $enableCsrfValidation = false;
|
|||
|
private $shop_id;
|
|||
|
|
|||
|
function init()
|
|||
|
{
|
|||
|
parent::init();
|
|||
|
$this->shop_id = $this->storeId ?: Store::getMainStore($this->wqData['uniacid'])['id'];
|
|||
|
$this->shop_id = $this->shop_id ?: 0;
|
|||
|
}
|
|||
|
|
|||
|
//设置
|
|||
|
public function actionConfig()
|
|||
|
{
|
|||
|
$request = Yii::$app->request;
|
|||
|
$result = axios_request();
|
|||
|
if (!$result['ident'] || !$this->wqData['uniacid']) {
|
|||
|
return $this->result(2, '数据异常');
|
|||
|
}
|
|||
|
if ($result['ident'] == "sysTopImage") {
|
|||
|
$this->wqData['uniacid'] = $result['uniacid'] ?: $this->wqData['uniacid'];
|
|||
|
}
|
|||
|
if ($result['ident'] == "superPower") {
|
|||
|
$this->wqData['uniacid'] = 0;
|
|||
|
}
|
|||
|
if ($request->isGet) {
|
|||
|
$res = Config::getSystemSet($result['ident'], $this->wqData['uniacid']);
|
|||
|
if ($result['ident'] == "delivery") {
|
|||
|
$res['makeName'] = Power::getPower($this->wqData['uniacid'], 'makeName')['makeName'] ?: '码科';
|
|||
|
$res['makeIcon'] = Power::getPower($this->wqData['uniacid'], 'makeName')['makeIcon'];
|
|||
|
$res['yunbeiName'] = Power::getPower($this->wqData['uniacid'], 'yunbeiName')['yunbeiName'] ?: '云贝';
|
|||
|
$res['yunbeiIcon'] = Power::getPower($this->wqData['uniacid'], 'yunbeiName')['yunbeiIcon'];
|
|||
|
}
|
|||
|
if ($result['ident'] == "miniConfig" || $result['ident'] == "wechatConfig" || $result['ident'] == "aliSet" || $result['ident'] == "toutiao") {
|
|||
|
$res['uniacid'] = $this->wqData['uniacid'];
|
|||
|
}
|
|||
|
if ($result['ident'] == "superPower") {//超级权限
|
|||
|
//获取项目的应用列表
|
|||
|
$config = Config::getSystemSet('superPower', 0);
|
|||
|
$res['channel_arr'] = $config['channel_arr'] ?: [];
|
|||
|
$res['plug_str'] = $config['plug_str'] ?: [];
|
|||
|
$res['instore'] = $config['instore'] ?: 2;
|
|||
|
$res['use_str'] = $config['use_str'] ?: [];
|
|||
|
$res['channel_list'] = Config::channelConfig();
|
|||
|
$res['plug_list'] = Config::plugConfig();
|
|||
|
$res['use_list'] = Config::menuConfig();
|
|||
|
$res['service_list'] = Config::serviceConfig();
|
|||
|
$res['makeName'] = Config::getSystemSet('superPower', 0)['makeName'];
|
|||
|
$res['service_str'] = getSysInfo()['authData']['service'] ?: [];
|
|||
|
}
|
|||
|
if ($result['ident'] == "sysTopImage") {//应用权限
|
|||
|
if (!$res) {
|
|||
|
$res = Config::getSystemSet('superPower', 0);
|
|||
|
}
|
|||
|
$plug = getSysInfo();
|
|||
|
//var_dump($plug);die;
|
|||
|
$channeArr = [];
|
|||
|
$channelConfig = Config::channelConfig();
|
|||
|
$plugConfig = Config::plugConfig();
|
|||
|
|
|||
|
$res['channel_list'] = Config::channelConfig();
|
|||
|
$config = Config::getSystemSet('sysTopImage', $this->wqData['uniacid']);
|
|||
|
$res['plug_list'] = $plugConfig;
|
|||
|
|
|||
|
$res['use_list'] = Config::menuConfig();
|
|||
|
$res['service_list'] = Config::serviceConfig();
|
|||
|
$res['makeName'] = Config::getSystemSet('sysTopImage', $this->wqData['uniacid'])['makeName'];
|
|||
|
$res['channel_arr'] = $config['channel_arr'] ?: [];
|
|||
|
$res['plug_str'] = $config['plug_str'] ?: [];
|
|||
|
$res['use_str'] = $config['use_str'] ?: [];
|
|||
|
$res['instore'] = $config['instore'] ?: 2;
|
|||
|
$res['service_str'] = getSysInfo()['authData']['service'] ?: [];
|
|||
|
//dd($res);die;
|
|||
|
}
|
|||
|
if ($result['ident'] == "system") {//应用权限
|
|||
|
$res['portrait'] = Yii::$app->session->get('userInfo')['portrait'];
|
|||
|
$eleInfo = Config::getSystemSet('eleSet', $this->wqData['uniacid']);
|
|||
|
if ($eleInfo['open'] == 1) {
|
|||
|
$res['eleOpen'] = 1;
|
|||
|
} else {
|
|||
|
$res['eleOpen'] = 2;
|
|||
|
}
|
|||
|
$meituanInfo = Config::getSystemSet('meituanSet', $this->wqData['uniacid']);
|
|||
|
if ($meituanInfo['open'] == 1) {
|
|||
|
$res['meituanOpen'] = 1;
|
|||
|
} else {
|
|||
|
$res['meituanOpen'] = 2;
|
|||
|
}
|
|||
|
//判断平台设置店内是否开启
|
|||
|
$instore = Power::getPower($this->wqData['uniacid'], 'instore')['instore'];
|
|||
|
$takeout = Power::getPower($this->wqData['uniacid'], 'takeout')['takeout'];
|
|||
|
$res['instorePower'] = $instore ?: 1;
|
|||
|
$res['takeoutPower'] = $takeout ?: 1;
|
|||
|
$res['uniacid'] = $this->wqData['uniacid'];
|
|||
|
$res['storeId'] = $this->shop_id ?: $result['storeId'];
|
|||
|
}
|
|||
|
if ($result['ident'] == 'miniConfig') {
|
|||
|
if (!$res AND Yii::$app->params['isDev'] == true) {
|
|||
|
$reminder = (new \yii\db\Query())
|
|||
|
->from('ims_account_wxapp')
|
|||
|
->where('uniacid=:uniacid', [':uniacid' => $this->wqData['uniacid']])->one();
|
|||
|
$res['appId'] = $reminder['key'];
|
|||
|
$res['appSecret'] = $reminder['secret'];
|
|||
|
$res['originalAppId'] = $reminder['original'];
|
|||
|
$res['name'] = $reminder['name'];
|
|||
|
$res['uniacid'] = $this->wqData['uniacid'];
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'instoreSet') {
|
|||
|
$res['payMode'] = $res['payMode'] ?: ['1', '2'];
|
|||
|
$res['orderMode'] = $res['orderMode'] ?: ['1', '2'];
|
|||
|
}
|
|||
|
if ($result['ident'] == 'payConfig') {
|
|||
|
$res['isCertfile'] = 2;
|
|||
|
$res['iskeyfile'] = 2;
|
|||
|
$res['isServiceCertfile'] = 2;
|
|||
|
$res['isServiceKeyfile'] = 2;
|
|||
|
$certfile = Yii::$app->basePath . "/payment/" . 'apiclient_cert_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
if (file_get_contents($certfile)) {
|
|||
|
$res['isCertfile'] = 1;
|
|||
|
}
|
|||
|
$keyfile = Yii::$app->basePath . "/payment/" . 'apiclient_key_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
if (file_get_contents($keyfile)) {
|
|||
|
$res['iskeyfile'] = 1;
|
|||
|
}
|
|||
|
$serviceCertfile = Yii::$app->basePath . "/payment/" . 'service_apiclient_cert_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
if (file_get_contents($serviceCertfile)) {
|
|||
|
$res['isServiceCertfile'] = 1;
|
|||
|
}
|
|||
|
$serviceKeyfile = Yii::$app->basePath . "/payment/" . 'service_apiclient_key_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
if (file_get_contents($serviceKeyfile)) {
|
|||
|
$res['isServiceKeyfile'] = 1;
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'currency') {
|
|||
|
//判断平台设置店内是否开启
|
|||
|
$instore = Power::getPower($this->wqData['uniacid'], 'instore')['instore'];
|
|||
|
$takeout = Power::getPower($this->wqData['uniacid'], 'takeout')['takeout'];
|
|||
|
$res['instorePower'] = $instore ?: 1;
|
|||
|
$res['takeoutPower'] = $takeout ?: 1;
|
|||
|
}
|
|||
|
if ($result['ident'] == 'aliSet') {
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
$res['downloadPage'] = Yii::$app->request->hostInfo . "/addons/yb_wm/web/ali.zip";
|
|||
|
} else {
|
|||
|
$res['downloadPage'] = Yii::$app->request->hostInfo . "/web/ali.zip";
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'toutiaoSet') {
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
$res['downloadPage'] = Yii::$app->request->hostInfo . "/addons/yb_wm/web/toutiao.zip";
|
|||
|
} else {
|
|||
|
$res['downloadPage'] = Yii::$app->request->hostInfo . "/web/toutiao.zip";
|
|||
|
}
|
|||
|
}
|
|||
|
//返回公众号地址及二维码
|
|||
|
if ($result['ident'] == 'wechatConfig') {
|
|||
|
$uniacid = $this->wqData['uniacid'];
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
$res['url'] = Yii::$app->request->hostInfo . '/addons/yb_wm/views/mobile/index.html?uniacid=' . $uniacid;
|
|||
|
} else {
|
|||
|
$res['url'] = Yii::$app->request->hostInfo . '/views/mobile/index.html?uniacid=' . $uniacid;
|
|||
|
}
|
|||
|
|
|||
|
if (Yii::$app->request->hostInfo == 'https://bkycms.com') {
|
|||
|
$res['url'] = 'https://v2.bkycms.com/views/mobile/index.html?uniacid=' . $uniacid;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
$loginType = Yii::$app->session->get('userInfo')['loginType'];
|
|||
|
echo json_encode(['code' => 1, 'msg' => '成功', 'data' => $res, 'loginType' => $loginType]);
|
|||
|
die;
|
|||
|
}
|
|||
|
if ($result['ident'] == 'system') {
|
|||
|
if (!$result['name']) {
|
|||
|
return $this->result(2, '平台名称不能为空');
|
|||
|
}
|
|||
|
if (!$result['icon']) {
|
|||
|
return $this->result(2, '平台LOGO不能为空');
|
|||
|
}
|
|||
|
if (!$result['introduction']) {
|
|||
|
return $this->result(2, '平台简介不能为空');
|
|||
|
}
|
|||
|
if (!$result['txKey']) {
|
|||
|
return $this->result(2, '腾讯key不能为空');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'sms') {
|
|||
|
if ($result['open'] == 1 AND !$result['access_key_id']) {
|
|||
|
return $this->result(2, 'access_key_id不能为空');
|
|||
|
}
|
|||
|
if ($result['open'] == 1 AND !$result['access_key_secret']) {
|
|||
|
return $this->result(2, 'access_key_secret不能为空');
|
|||
|
}
|
|||
|
if ($result['open'] == 1 AND !$result['sign']) {
|
|||
|
return $this->result(2, 'sign不能为空');
|
|||
|
}
|
|||
|
if ($result['open'] == 1 AND !$result['tel']) {
|
|||
|
return $this->result(2, 'tel不能为空');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'payConfig') {
|
|||
|
if ($result['payOpen'] == 2 AND $result['servicePayOpen'] == 2 AND $result['balancePayOpen'] == 2) {
|
|||
|
return $this->result(2, '必须开启一种支付');
|
|||
|
}
|
|||
|
if ($result['wxPayType'] == 1) {
|
|||
|
if ($result['payOpen'] == 1 AND (!$result['mchId'] || !$result['key'])) {
|
|||
|
return $this->result(2, '微信支付配置不能为空');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['wxPayType'] == 2) {
|
|||
|
if ($result['servicePayOpen'] == 1 AND (!$result['serviceAppId'] || !$result['serviceMchId'] || !$result['serviceKey'])) {
|
|||
|
return $this->result(2, '服务商支付配置不能为空');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['apiclient_cert'] AND $result['apiclient_key']) {
|
|||
|
$certfile = Yii::$app->basePath . "/payment/" . 'apiclient_cert_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
$keyfile = Yii::$app->basePath . "/payment/" . 'apiclient_key_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
chmod(Yii::$app->basePath . "/payment/", 0777);
|
|||
|
if (!file_put_contents($certfile, $result['apiclient_cert'])) {
|
|||
|
return $this->result(2, 'cret文件写入失败');
|
|||
|
}
|
|||
|
if (!file_put_contents($keyfile, $result['apiclient_key'])) {
|
|||
|
return $this->result(2, 'key文件写入失败');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['service_apiclient_cert'] AND $result['service_apiclient_key']) {
|
|||
|
$certfile = Yii::$app->basePath . "/payment/" . 'service_apiclient_cert_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
$keyfile = Yii::$app->basePath . "/payment/" . 'service_apiclient_key_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
chmod(Yii::$app->basePath . "/payment/", 0777);
|
|||
|
if (!file_put_contents($certfile, $result['service_apiclient_cert'])) {
|
|||
|
return $this->result(2, '服务商cret文件写入失败');
|
|||
|
}
|
|||
|
if (!file_put_contents($keyfile, $result['service_apiclient_key'])) {
|
|||
|
return $this->result(2, '服务商key文件写入失败');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['servicePayOpen'] == 1 AND $result['smOpen'] == 1 AND $result['servicePayNo']) {
|
|||
|
if (!$result['servicePayNo']) {
|
|||
|
return $this->result(2, '服务商证书序号不能为空');
|
|||
|
}
|
|||
|
if (!$result['serviceV3Key']) {
|
|||
|
return $this->result(2, '服务商apiV3密钥不能为空');
|
|||
|
}
|
|||
|
$opts['mchid'] = $result['serviceMchId'];
|
|||
|
$opts['serialno'] = $result['servicePayNo'];
|
|||
|
$opts['privatekey'] = Yii::$app->basePath . "/payment/" . 'service_apiclient_key_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
$opts['key'] = $result['serviceV3Key'];
|
|||
|
$opts['uniacid'] = $this->wqData['uniacid'];
|
|||
|
$opts['output'] = Yii::$app->basePath . '/payment/';
|
|||
|
$weChatPaySerialNo = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_core_system}}')
|
|||
|
->where(['ident' => 'weChatServicePaySerialNo', 'uniacid' => $this->wqData['uniacid']])
|
|||
|
->one();
|
|||
|
if ($weChatPaySerialNo) {
|
|||
|
//$opts['wechatpay-cert']=Yii::$app->basePath."/payment/" . 'wechatpay_'.$weChatPaySerialNo['data'].'.pem';
|
|||
|
//$opts['wechatpay-cert']=Yii::$app->basePath."/payment/" . 'service_apiclient_cert_' . $this->wqData['uniacid'] . '.pem';
|
|||
|
}
|
|||
|
|
|||
|
$weRes = WeChatPay::downloadCert($opts);
|
|||
|
if ($weRes !== true) {
|
|||
|
return $this->result(2, $weRes);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'miniConfig') {
|
|||
|
$conf = [
|
|||
|
'app_id' => $result['appId'],
|
|||
|
'secret' => $result['appSecret'],
|
|||
|
'response_type' => 'array',
|
|||
|
'log' => [
|
|||
|
'level' => 'debug',
|
|||
|
'file' => __DIR__ . '/wechat.log',
|
|||
|
],
|
|||
|
];
|
|||
|
$app = Factory::miniProgram($conf);
|
|||
|
try {
|
|||
|
$app->access_token->getToken();
|
|||
|
} catch (\Exception $e) {
|
|||
|
return $this->result(2, '配置错误,请检查小程序id和小程序密钥是否填写正确');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'currency') {
|
|||
|
//添加取消订单,拒绝单,确认收货 定时任务
|
|||
|
$crondData = array(
|
|||
|
'crontab_str' => '* * * * *',
|
|||
|
'status' => 0,
|
|||
|
);
|
|||
|
if ($result['autoClose'] && $result['closeTime']) {
|
|||
|
$crondData['name'] = '自动取消订单';
|
|||
|
$crondData['route'] = 'tasks/common/order-cancel';
|
|||
|
if ($result['autoClose'] == 1) {
|
|||
|
$crondData['switch'] = 1;
|
|||
|
} else {
|
|||
|
$crondData['switch'] = 0;
|
|||
|
}
|
|||
|
$crondInfo = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_crontab}}')
|
|||
|
->where(['name' => $crondData['name']])
|
|||
|
->one();
|
|||
|
if ($crondInfo) {
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_crontab}}', $crondData, ['name' => $crondData['name']])->execute();
|
|||
|
} else {
|
|||
|
Yii::$app->db->createCommand()->insert('{{%ybwm_crontab}}', $crondData)->execute();
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['autoRefuse'] && $result['refuseTime']) {
|
|||
|
$crondData['name'] = '自动拒绝单';
|
|||
|
$crondData['route'] = 'tasks/common/rejection';
|
|||
|
if ($result['autoRefuse'] == 1) {
|
|||
|
$crondData['switch'] = 1;
|
|||
|
} else {
|
|||
|
$crondData['switch'] = 0;
|
|||
|
}
|
|||
|
$crondInfo = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_crontab}}')
|
|||
|
->where(['name' => $crondData['name']])
|
|||
|
->one();
|
|||
|
if ($crondInfo) {
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_crontab}}', $crondData, ['name' => $crondData['name']])->execute();
|
|||
|
} else {
|
|||
|
Yii::$app->db->createCommand()->insert('{{%ybwm_crontab}}', $crondData)->execute();
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['autoComplete'] && $result['completeTime']) {
|
|||
|
if ($result['autoComplete'] == 1) {
|
|||
|
$crondData['switch'] = 1;
|
|||
|
} else {
|
|||
|
$crondData['switch'] = 0;
|
|||
|
}
|
|||
|
$crondData['name'] = '自动确认收货';
|
|||
|
$crondData['route'] = 'tasks/common/receiving';
|
|||
|
$crondInfo = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_crontab}}')
|
|||
|
->where(['name' => $crondData['name']])
|
|||
|
->one();
|
|||
|
if ($crondInfo) {
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_crontab}}', $crondData, ['name' => $crondData['name']])->execute();
|
|||
|
} else {
|
|||
|
Yii::$app->db->createCommand()->insert('{{%ybwm_crontab}}', $crondData)->execute();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
$re = Config::saveSystemSet($result, $result['ident'], $this->wqData['uniacid'], $result['identName'] ?: '');
|
|||
|
if ($re) {
|
|||
|
if ($result['ident'] == "vipSet" AND $result['wechatCard'] == 1) {
|
|||
|
WeChat::weChatCard($this->wqData['uniacid']);
|
|||
|
}
|
|||
|
return $this->result(1, '成功');
|
|||
|
} else {
|
|||
|
if ($result['ident'] == "storage") {
|
|||
|
return $this->result(2, '参数配置有误!!!');
|
|||
|
}
|
|||
|
return $this->result(2, '网络异常,请稍后再试');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//商家设置
|
|||
|
public function actionStoreConfig()
|
|||
|
{
|
|||
|
$request = Yii::$app->request;
|
|||
|
$result = axios_request();
|
|||
|
$module = $this->wqData['module'];
|
|||
|
$result['storeId'] = $result['storeId'] ?: $this->shop_id;
|
|||
|
if ($request->isGet) {
|
|||
|
$res = Config::getStoreSet($result['ident'], $result['storeId']);
|
|||
|
if ($result['ident'] == 'delivery') {
|
|||
|
$shopInfo = (new \yii\db\Query())
|
|||
|
->select(['address', 'lat', 'lng'])
|
|||
|
->from('{{%ybwm_store}}')
|
|||
|
->where('id=:storeId', [':storeId' => $result['storeId']])->one();
|
|||
|
$res['address'] = $shopInfo['address'];
|
|||
|
$res['lat'] = $shopInfo['lat'];
|
|||
|
$res['lng'] = $shopInfo['lng'];
|
|||
|
}
|
|||
|
if ($result['ident'] == 'deliveryMode') {
|
|||
|
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
$sfCallBack = Yii::$app->request->hostInfo . '/addons/' . $module . '/index.php/channelApi/delivery-notice/shunfeng-notice';
|
|||
|
$ssCallBack = Yii::$app->request->hostInfo . '/addons/' . $module . '/index.php/channelApi/delivery-notice/sansong-notice';
|
|||
|
$dianCallBack = Yii::$app->request->hostInfo . '/addons/' . $module . '/index.php/channelApi/delivery-notice/dianwoda-notice';
|
|||
|
} else {
|
|||
|
$sfCallBack = Yii::$app->request->hostInfo . '/index.php/channelApi/delivery-notice/shunfeng-notice';
|
|||
|
$ssCallBack = Yii::$app->request->hostInfo . '/index.php/channelApi/delivery-notice/sansong-notice';
|
|||
|
$dianCallBack = Yii::$app->request->hostInfo . '/index.php/channelApi/delivery-notice/dianwoda-notice';
|
|||
|
}
|
|||
|
$res['sscallBack'] = $ssCallBack;
|
|||
|
$res['sfcallBack'] = $sfCallBack;
|
|||
|
$res['dianCallBack'] = $dianCallBack;
|
|||
|
$res['makeName'] = Power::getPower($this->wqData['uniacid'], 'makeName')['makeName'] ?: '码科';
|
|||
|
$res['makeIcon'] = Power::getPower($this->wqData['uniacid'], 'makeName')['makeIcon'];
|
|||
|
$res['yunbeiName'] = Power::getPower($this->wqData['uniacid'], 'yunbeiName')['yunbeiName'] ?: '云贝';
|
|||
|
$res['yunbeiIcon'] = Power::getPower($this->wqData['uniacid'], 'yunbeiName')['yunbeiIcon'];
|
|||
|
|
|||
|
}
|
|||
|
if ($result['ident'] == 'takeOutSet') {
|
|||
|
if (!$res['address']) {
|
|||
|
$shopInfo = (new \yii\db\Query())
|
|||
|
->select(['address', 'lat', 'lng'])
|
|||
|
->from('{{%ybwm_store}}')
|
|||
|
->where('id=:storeId', [':storeId' => $result['storeId']])->one();
|
|||
|
$res['address'] = $shopInfo['address'];
|
|||
|
$res['lat'] = $shopInfo['lat'];
|
|||
|
$res['lng'] = $shopInfo['lng'];
|
|||
|
}
|
|||
|
$res['orderMedia'] = $res['orderMedia'] ?: [];
|
|||
|
$res['distributionSupport'] = $res['distributionSupport'] ?: ['1', '2'];
|
|||
|
$res['diningType'] = $res['diningType'] ?: ['1', '2'];
|
|||
|
$res['orderNotice'] = $res['orderNotice'] ?: '商家暂无公告';
|
|||
|
$res['notice'] = $res['notice'] ?: '商家暂无公告';
|
|||
|
$res['timeType'] = $res['timeType'] ?: '1';
|
|||
|
$res['boxType'] = $res['boxType'] ?: '2';
|
|||
|
$res['printType'] = $res['printType'] ?: '1';
|
|||
|
|
|||
|
}
|
|||
|
if ($result['ident'] == 'instoreSet') {
|
|||
|
$result['payMode'] = $result['payMode'] ?: 1;
|
|||
|
$result['orderMode'] = $result['orderMode'] ?: 1;
|
|||
|
}
|
|||
|
|
|||
|
return $this->result(1, '成功', $res);
|
|||
|
}
|
|||
|
if (!$result['ident']) {
|
|||
|
return $this->result(2, '配置名不能为空');
|
|||
|
}
|
|||
|
if (!$result['storeId']) {
|
|||
|
return $this->result(2, '请先添加门店信息');
|
|||
|
}
|
|||
|
if ($result['ident'] == 'takeOutSet') {
|
|||
|
if ($result['timeType'] == 2 AND !$result['timeArr']) {
|
|||
|
return $this->result(2, '营业时间不能为空');
|
|||
|
}
|
|||
|
if ($result['timeType'] == 2 AND !$result['distributionSupport']) {
|
|||
|
return $this->result(2, '配送支持不能为空');
|
|||
|
}
|
|||
|
if ($result['timeType'] == 2 AND !$result['diningType'] AND in_array(2, $result['distributionSupport'])) {
|
|||
|
return $this->result(2, '就餐方式不能为空');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'fastSet') {
|
|||
|
if ($result['autoComplete'] == 1 AND !$result['completeTime']) {
|
|||
|
return $this->result(2, '时间不能为空');
|
|||
|
}
|
|||
|
if ($result['autoComplete'] == 1 AND $result['completeTime'] < 0) {
|
|||
|
return $this->result(2, '时间必须大于零');
|
|||
|
}
|
|||
|
if ($result['autoComplete'] && $result['completeTime']) {
|
|||
|
if ($result['autoComplete'] == 1) {
|
|||
|
$crondData['switch'] = 1;
|
|||
|
} else {
|
|||
|
$crondData['switch'] = 0;
|
|||
|
}
|
|||
|
$crondData['crontab_str'] = '* * * * *';
|
|||
|
$crondData['name'] = '快餐自动确认收货';
|
|||
|
$crondData['route'] = 'tasks/common/fast-receiving';
|
|||
|
$crondInfo = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_crontab}}')
|
|||
|
->where(['name' => $crondData['name']])
|
|||
|
->one();
|
|||
|
if ($crondInfo) {
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_crontab}}', $crondData, ['name' => $crondData['name']])->execute();
|
|||
|
} else {
|
|||
|
Yii::$app->db->createCommand()->insert('{{%ybwm_crontab}}', $crondData)->execute();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'takeOutSet') {
|
|||
|
if ($result['timeArr']) {
|
|||
|
for ($i = 0; $i < count($result['timeArr']); $i++) {
|
|||
|
if ($result['timeArr'][$i]['startTime'] == $result['timeArr'][$i]['endTime']) {
|
|||
|
$result['timeType'] = "1";
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (!$result['distributionSupport']) {
|
|||
|
return $this->result(2, '配送支持不能为空');
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'serviceCharge') {
|
|||
|
if ($result['sonService'] == 1 AND $result['profit_sharing'] == "Y") {
|
|||
|
$res = WeChat::AddProfitSharing($this->wqData['uniacid'], $result['giveMchid'], $result['giveName'], $result['subMchId']);
|
|||
|
if (!$res) {
|
|||
|
return $this->result(2, '添加分账接收方失败');
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if ($result['ident'] == 'deliveryMode' and $result['yunbeiOpen'] == 1 and $result['yunbeiUrl']) {
|
|||
|
$url = Yii::$app->params['domain_url'] . "/cloud/auth/checkDomain";
|
|||
|
$data['auth_type'] = 2;
|
|||
|
$data['domain_url'] = $result['yunbeiUrl'];
|
|||
|
$res = httpRequest($url, $data);
|
|||
|
$resArr = json_decode($res, true);
|
|||
|
if ($resArr['code'] == 1) {
|
|||
|
$result['yunbeiedition'] = $resArr['isDev'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '域名未授权,请确认!');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
$re = Config::saveStoreSet($result, $result['ident'], $result['storeId'], $result['identName'] ?: '');
|
|||
|
if ($re) {
|
|||
|
return $this->result(1, '操作成功');
|
|||
|
} else {
|
|||
|
return $this->result(2, '网络异常,请稍后再试');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//页面路径
|
|||
|
public function actionGetPage()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
if ($result['page'] == 'miniPage') {
|
|||
|
$res = array(
|
|||
|
array(
|
|||
|
'name' => '首页',
|
|||
|
'page' => 'yb_wm/index/index',
|
|||
|
'ident' => 'index'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '点单页',
|
|||
|
'page' => 'yb_wm/index/goods',
|
|||
|
'ident' => 'goods'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '订单列表',
|
|||
|
'page' => 'yb_wm/index/order-index',
|
|||
|
'ident' => 'orderIndex'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '个人中心',
|
|||
|
'page' => 'yb_wm/index/my-index',
|
|||
|
'ident' => 'myIndex'
|
|||
|
),
|
|||
|
);
|
|||
|
}
|
|||
|
if ($result['page'] == 'weChatPage') {
|
|||
|
$uniacid = $this->wqData['uniacid'];
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
$domain = Yii::$app->request->hostInfo . '/addons/yb_wm';
|
|||
|
} else {
|
|||
|
$domain = Yii::$app->request->hostInfo;
|
|||
|
}
|
|||
|
$res = array(
|
|||
|
array(
|
|||
|
'name' => '首页',
|
|||
|
'page' => $domain . '/views/mobile/index.html?uniacid=16'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '点单页',
|
|||
|
'page' => $domain . '/views/mobile/index.html?uniacid=16#/yb_wm/index/order-index'
|
|||
|
)
|
|||
|
);
|
|||
|
}
|
|||
|
if ($result['page'] == 'toutiaoPage') {
|
|||
|
$res = array(
|
|||
|
array(
|
|||
|
'name' => '首页',
|
|||
|
'page' => 'yb_wm/index/index',
|
|||
|
'ident' => 'index'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '点单页',
|
|||
|
'page' => 'yb_wm/index/goods',
|
|||
|
'ident' => 'goods'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '订单列表',
|
|||
|
'page' => 'yb_wm/index/order-index',
|
|||
|
'ident' => 'orderIndex'
|
|||
|
),
|
|||
|
array(
|
|||
|
'name' => '个人中心',
|
|||
|
'page' => 'yb_wm/index/my-index',
|
|||
|
'ident' => 'myIndex'
|
|||
|
),
|
|||
|
);
|
|||
|
}
|
|||
|
return $this->result(1, '成功', $res);
|
|||
|
}
|
|||
|
|
|||
|
public function actionGetCode()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
$pageType = $result['pageType'];
|
|||
|
$scene = 0;
|
|||
|
if ($result['ident'] == 'goods' || $result['ident'] == 'dmf' || $result['ident'] == 'fastOrder') {
|
|||
|
$scene = $result['storeId'] ?: $this->shop_id;
|
|||
|
}
|
|||
|
if ($result['ident'] == 'table') {
|
|||
|
$scene = $result['tableId'];
|
|||
|
}
|
|||
|
if ($result['ident'] == 'shop') {
|
|||
|
// $scene = $this->wqData['uniacid'] .'id&shopId='. ($result['storeId'] ?: $this->shop_id);
|
|||
|
$scene = $this->wqData['uniacid'] .'&'. ($result['storeId'] ?: (isset($this->wqData['shopId']) ? $this->wqData['shopId'] :$this->shop_id));
|
|||
|
}
|
|||
|
try {
|
|||
|
if ($pageType == 'toutiao') {
|
|||
|
$page = ZiJie::createCode($this->wqData['uniacid'], $this->wqData['module'], $result['page'], $result['ident']);
|
|||
|
} elseif ($pageType == 'ali') {
|
|||
|
$page = Ali::qrcode($this->wqData['uniacid'], $result['page'], $scene);
|
|||
|
} else {
|
|||
|
$page = WeChat::getQrCode($this->wqData['uniacid'], $this->wqData['module'], $result['page'], $result['ident'], $scene);
|
|||
|
}
|
|||
|
} catch (\Exception $e) {
|
|||
|
return $this->result(1, '成功', []);
|
|||
|
}
|
|||
|
return $this->result(1, '成功', $page);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//一键获取模板消息
|
|||
|
public function actionGetMiniTemplates()
|
|||
|
{
|
|||
|
$request = Yii::$app->request;
|
|||
|
if ($request->isGet) {
|
|||
|
return $this->result(2, '请求异常');
|
|||
|
}
|
|||
|
$res = Config::getSystemSet('miniTemplates', $this->wqData['uniacid']);
|
|||
|
if (!$res['payOkTid']) {
|
|||
|
//下单成功
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 1461, ['订单类型', '下单时间', '商品名称', '订单编号', '已付金额'], '支付成功提醒');
|
|||
|
$res['payOkTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['refuseTid']) {
|
|||
|
//商家拒单
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 1130, ['拒单原因', '门店名称', '商品名称', '订单编号', '下单时间'], '商家拒单提醒');
|
|||
|
$res['refuseTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['acceptTid']) {
|
|||
|
//商家接单
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 1129, ['订单编号', '门店名称', '订单类型', '商品名称', '备注'], '商家接单提醒');
|
|||
|
$res['acceptTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['refundResultTid']) {
|
|||
|
//退款结果通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 1451, ['退款状态', '退款商品', '退款金额', '订单编号', '退款说明'], '退款结果通知');
|
|||
|
$res['refundResultTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['takeTid']) {
|
|||
|
//取餐通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 1093, ['提货单号', '自提门店', '门店地址', '订单金额', '备注'], '订单自提通知');
|
|||
|
$res['takeTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['deliveryTid']) {
|
|||
|
//配送通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 1128, ['门店名称', '订单编号', '姓名', '地址', '温馨提示'], '订单配送通知');
|
|||
|
$res['deliveryTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['cashierTid']) {
|
|||
|
//当面付支付通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 3578, ['订单编号', '支付金额', '支付时间', '订单状态', '商家名称'], '支付成功通知');
|
|||
|
$res['cashierTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['fastTakeTid']) {
|
|||
|
//快餐取餐通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 9525, ['取餐号', '取餐方式', '取餐门店', '商品', '温馨提示'], '取餐提醒');
|
|||
|
$res['fastTakeTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['inOrderTid']) {
|
|||
|
//堂食订单确认通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 3646, ['订单号', '下单时间', '商品名称', '支付状态', '备注'], '订单确认通知');
|
|||
|
$res['inOrderTid'] = $tid;
|
|||
|
}
|
|||
|
if (!$res['queuingTid']) {
|
|||
|
//排队通知
|
|||
|
$tid = WeChat::getMiniTemplates($this->wqData['uniacid'], 4692, ['商家名称', '排队号码', '还剩等位', '排队状态', '更新时间'], '排队到号提醒');
|
|||
|
$res['queuingTid'] = $tid;
|
|||
|
}
|
|||
|
$rst = Config::saveSystemSet($res, 'miniTemplates', $this->wqData['uniacid'], '订阅消息');
|
|||
|
if ($rst) {
|
|||
|
return $this->result(1, '操作成功');
|
|||
|
} else {
|
|||
|
return $this->result(2, '网络异常,请稍后再试');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//一键获取模板消息(商家订单提醒)
|
|||
|
public function actionGetStoreTemplates()
|
|||
|
{
|
|||
|
$request = Yii::$app->request;
|
|||
|
if ($request->isGet) {
|
|||
|
return $this->result(2, '请求异常');
|
|||
|
}
|
|||
|
$res = Config::getSystemSet('storeTemplates', $this->wqData['uniacid']);
|
|||
|
if (!$res['appId'] || !$res['appSecret']) {
|
|||
|
return $this->result(2, '公众号配置信息不能为空');
|
|||
|
}
|
|||
|
$config = [
|
|||
|
'app_id' => $res['appId'],
|
|||
|
'secret' => $res['appSecret'],
|
|||
|
'response_type' => 'array',
|
|||
|
];
|
|||
|
$app = Factory::officialAccount($config);
|
|||
|
if (!$res['payOkTid']) {
|
|||
|
//下单成功
|
|||
|
$tid = $app->template_message->addTemplate("OPENTM201785396");
|
|||
|
if ($tid['errcode'] == 0) {
|
|||
|
$res['payOkTid'] = $tid['template_id'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '获取失败,请检查配置信息');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
if (!$res['refundTid']) {
|
|||
|
//退款成功
|
|||
|
$tid = $app->template_message->addTemplate("OPENTM410195709");
|
|||
|
if ($tid['errcode'] == 0) {
|
|||
|
$res['refundTid'] = $tid['template_id'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '获取失败,请检查配置信息');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
if (!$res['inStoreTid']) {
|
|||
|
//堂食下订单
|
|||
|
$tid = $app->template_message->addTemplate("OPENTM207294721");
|
|||
|
if ($tid['errcode'] == 0) {
|
|||
|
$res['inStoreTid'] = $tid['template_id'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '获取失败,请检查配置信息');
|
|||
|
}
|
|||
|
}
|
|||
|
if (!$res['cashierTid']) {
|
|||
|
//收银提醒
|
|||
|
$tid = $app->template_message->addTemplate("OPENTM410348284");
|
|||
|
if ($tid['errcode'] == 0) {
|
|||
|
$res['cashierTid'] = $tid['template_id'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '获取失败,请检查配置信息');
|
|||
|
}
|
|||
|
}
|
|||
|
if (!$res['reminderTid']) {
|
|||
|
//催单提醒
|
|||
|
$tid = $app->template_message->addTemplate("OPENTM406645351");
|
|||
|
if ($tid['errcode'] == 0) {
|
|||
|
$res['reminderTid'] = $tid['template_id'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '获取失败,请检查配置信息');
|
|||
|
}
|
|||
|
}
|
|||
|
if (!$res['fastTid']) {
|
|||
|
//快餐新订单提醒
|
|||
|
$tid = $app->template_message->addTemplate("OPENTM406199469");
|
|||
|
if ($tid['errcode'] == 0) {
|
|||
|
$res['fastTid'] = $tid['template_id'];
|
|||
|
} else {
|
|||
|
return $this->result(2, '获取失败,请检查配置信息');
|
|||
|
}
|
|||
|
}
|
|||
|
$rst = Config::saveSystemSet($res, 'storeTemplates', $this->wqData['uniacid'], '订单提醒消息');
|
|||
|
if ($rst) {
|
|||
|
return $this->result(1, '成功');
|
|||
|
} else {
|
|||
|
return $this->result(2, '网络异常,请稍后再试');
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
//发送测试
|
|||
|
public function actionSendStoreTemplates()
|
|||
|
{
|
|||
|
$request = Yii::$app->request;
|
|||
|
if ($request->isGet) {
|
|||
|
return $this->result(2, '请求异常');
|
|||
|
}
|
|||
|
$result = axios_request();
|
|||
|
$res = Config::getSystemSet('storeTemplates', $this->wqData['uniacid']);
|
|||
|
if (!$res['appId'] || !$res['appSecret'] || !$res[$result['type']]) {
|
|||
|
return $this->result(2, '公众号配置信息不能为空');
|
|||
|
}
|
|||
|
$config = [
|
|||
|
'app_id' => $res['appId'],
|
|||
|
'secret' => $res['appSecret'],
|
|||
|
'response_type' => 'array',
|
|||
|
];
|
|||
|
$app = Factory::officialAccount($config);
|
|||
|
$data = [];
|
|||
|
if ($result['type'] == 'payOkTid') {
|
|||
|
$data = [
|
|||
|
'first' => ["亲 您有新的商品订单,请及时处理!", "#FF0000"],
|
|||
|
'keyword1' => ["123456789", "#173177"],
|
|||
|
'keyword2' => ["测试订单", "#173177"],
|
|||
|
'keyword3' => ["10元", "#173177"],
|
|||
|
'keyword4' => ["2020-10-01 10:10:10", "#173177"],
|
|||
|
'keyword5' => ["王先生(15337777777) 北京市朝阳区xxxx 今天10:00", "#173177"],
|
|||
|
'remark' => ["取餐号为 #01", "#FF0000"],
|
|||
|
];
|
|||
|
}
|
|||
|
if ($result['type'] == 'refundTid') {
|
|||
|
$data = [
|
|||
|
'first' => ["亲 您有新的售后订单,请及时处理!", "#FF0000"],
|
|||
|
'keyword1' => ["123456789", "#173177"],
|
|||
|
'keyword2' => ["申请退款", "#173177"],
|
|||
|
'keyword3' => ["2020-10-01 10:10:10", "#173177"],
|
|||
|
'remark' => ["请前往后台处理!", "#FF0000"],
|
|||
|
];
|
|||
|
}
|
|||
|
if ($result['type'] == 'inStoreTid') {
|
|||
|
$data = [
|
|||
|
'first' => ["收到一个餐座开台提醒", "#FF0000"],
|
|||
|
'keyword1' => ["大厅-小桌 A001", "#173177"],
|
|||
|
'keyword2' => ["88.00元(未支付)", "#173177"],
|
|||
|
'keyword3' => ["2020-10-01 10:10:10", "#173177"],
|
|||
|
'keyword4' => ["202121521423366", "#173177"],
|
|||
|
'keyword5' => ["堂食(收银台下单)", "#173177"],
|
|||
|
'remark' => ["请及时处理您的订单", "#FF0000"],
|
|||
|
];
|
|||
|
}
|
|||
|
if ($result['type'] == 'cashierTid') {
|
|||
|
$data = [
|
|||
|
'first' => ["你有一笔收款信息", "#FF0000"],
|
|||
|
'keyword1' => ["云贝科技", "#173177"],
|
|||
|
'keyword2' => ["余额支付", "#173177"],
|
|||
|
'keyword3' => ["8888元", "#173177"],
|
|||
|
'keyword4' => ["无", "#173177"],
|
|||
|
'keyword5' => ["2020-10-01 10:10:10", "#173177"],
|
|||
|
'remark' => ["请尽快核实订单哦!", "#FF0000"],
|
|||
|
];
|
|||
|
}
|
|||
|
if ($result['type'] == 'reminderTid') {
|
|||
|
$data = [
|
|||
|
'first' => ["您收到了一条催单提醒", "#FF0000"],
|
|||
|
'keyword1' => ["201608180001(#1)", "#173177"],
|
|||
|
'keyword2' => ["已接单", "#173177"],
|
|||
|
'keyword3' => ["20元", "#173177"],
|
|||
|
'remark' => ["请您尽快处理该订单哦!", "#FF0000"],
|
|||
|
];
|
|||
|
}
|
|||
|
if ($result['type'] == 'fastTid') {
|
|||
|
$data = [
|
|||
|
'first' => ["有新的快餐订单提醒", "#FF0000"],
|
|||
|
'keyword1' => ["2016072112345(A003)", "#173177"],
|
|||
|
'keyword2' => ["绝情池水", "#173177"],
|
|||
|
'keyword3' => ["250元", "#173177"],
|
|||
|
'keyword4' => ["已付款", "#173177"],
|
|||
|
'keyword5' => ["2020-10-01 10:10:10", "#173177"],
|
|||
|
'remark' => ["请尽快处理此订单哦!", "#FF0000"],
|
|||
|
];
|
|||
|
}
|
|||
|
try {
|
|||
|
$res = $app->template_message->send([
|
|||
|
'touser' => $res['openId'],
|
|||
|
'template_id' => $res[$result['type']],
|
|||
|
'data' => $data,
|
|||
|
]);
|
|||
|
} catch (\Exception $exception) {
|
|||
|
return $this->result(2, $exception);
|
|||
|
}
|
|||
|
|
|||
|
if ($res['errcode'] == 0) {
|
|||
|
return $this->result(1, '成功');
|
|||
|
} else {
|
|||
|
return $this->result(2, '发送失败,请检查配置信息');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public function actionGetBucket()
|
|||
|
{
|
|||
|
$request = Yii::$app->request;
|
|||
|
if ($request->isPost) {
|
|||
|
$result = axios_request();
|
|||
|
$accessKeyId = $result['aliyuncs_accesskey'];
|
|||
|
$accessKeySecret = $result['aliyuncs_secret'];
|
|||
|
$endpoint = $result['endpoint'];
|
|||
|
try {
|
|||
|
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
|
|||
|
$bucketListInfo = $ossClient->listBuckets();
|
|||
|
$bucketList = $bucketListInfo->getBucketList();
|
|||
|
$bucket_arr = [];
|
|||
|
foreach ($bucketList as $key => $v) {
|
|||
|
$bucket_arr[] = array(
|
|||
|
'value' => $key,
|
|||
|
'label' => array_values(object_array($v))[1]
|
|||
|
);
|
|||
|
}
|
|||
|
return $this->result(1, '操作成功', $bucket_arr);
|
|||
|
} catch (OssException $e) {
|
|||
|
return $this->result(2, '参数不正确', $e);
|
|||
|
}
|
|||
|
}
|
|||
|
return $this->result(2, '请求异常');
|
|||
|
}
|
|||
|
//
|
|||
|
// public function actionDeliverySet(){
|
|||
|
// $request = Yii::$app->request;
|
|||
|
// if ($request->isPost){
|
|||
|
//
|
|||
|
// }
|
|||
|
// }
|
|||
|
public function actionGetUrl()
|
|||
|
{
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
//微擎
|
|||
|
$data['returnSystem'] = Yii::$app->request->hostInfo . "/web/index.php?c=miniapp&a=version&do=home&version_id=" . $this->wqData['version_id'] . "&uniacid=" . $this->wqData['uniacid'];
|
|||
|
$data['outSystem'] = Yii::$app->request->hostInfo;
|
|||
|
} else {
|
|||
|
$data['returnSystem'] = Yii::$app->request->hostInfo . "/index.php/admin/index/index";
|
|||
|
$data['outSystem'] = Yii::$app->request->hostInfo . "/index.php/admin/login/index";
|
|||
|
}
|
|||
|
return $this->result(1, '成功', $data);
|
|||
|
}
|
|||
|
|
|||
|
public function actionSignOut()
|
|||
|
{
|
|||
|
$session = Yii::$app->session;
|
|||
|
$session->destroy();
|
|||
|
return $this->result(1, '成功');
|
|||
|
}
|
|||
|
|
|||
|
public function actionCacheSet()
|
|||
|
{
|
|||
|
error_reporting("E_ALL");
|
|||
|
ini_set("display_errors", 1);
|
|||
|
$request = Yii::$app->request;
|
|||
|
if ($request->isGet) {
|
|||
|
if (!extension_loaded('swoole')) {
|
|||
|
return $this->result(2, '请安装php swoole扩展');
|
|||
|
}
|
|||
|
if (!extension_loaded('redis')) {
|
|||
|
return $this->result(2, '请安装php redis扩展');
|
|||
|
}
|
|||
|
error_reporting("E_ALL");
|
|||
|
ini_set("display_errors", 1);
|
|||
|
$info = file_get_contents('./web/cacheSet.log');
|
|||
|
if ($info) {
|
|||
|
$data = array(
|
|||
|
'redis' => json_decode($info, true)['redis'],
|
|||
|
'redispx' => json_decode($info, true)['redispx'] ?: 6379,
|
|||
|
'swoole' => json_decode($info, true)['swoole'],
|
|||
|
'ssl_certificate' => json_decode($info, true)['ssl_certificate'],
|
|||
|
'ssl_certificate_key' => json_decode($info, true)['ssl_certificate_key'],
|
|||
|
|
|||
|
);
|
|||
|
}
|
|||
|
return $this->result(1, '成功', $data);
|
|||
|
}
|
|||
|
if ($request->isPost) {
|
|||
|
if (!extension_loaded('swoole')) {
|
|||
|
return $this->result(2, '请安装php swoole扩展');
|
|||
|
}
|
|||
|
if (!extension_loaded('redis')) {
|
|||
|
return $this->result(2, '请安装php redis扩展');
|
|||
|
}
|
|||
|
$result = axios_request();
|
|||
|
if ($result['type'] == 1) {
|
|||
|
$disabled = explode(',', ini_get('disable_functions'));
|
|||
|
if (in_array('shell_exec', $disabled)) {
|
|||
|
return $this->result(2, 'shell_exec函数被禁用');
|
|||
|
}
|
|||
|
Yii::$app->redis->set('swoole_test', '999');
|
|||
|
$source = Yii::$app->redis->get('swoole_test');
|
|||
|
Yii::$app->redis->del('swoole_test');
|
|||
|
if (!$source) {
|
|||
|
return $this->result(2, 'redis配置参数有误');
|
|||
|
}
|
|||
|
$port = Yii::$app->params['swoolePort'];
|
|||
|
$shell = "netstat -anp 2>/dev/null | grep " . $port . " | grep LISTEN | wc -l";
|
|||
|
$result = shell_exec($shell);
|
|||
|
if ($result <> 1) {
|
|||
|
return $this->result(2, '请检查配置');
|
|||
|
} else {
|
|||
|
return $this->result(1, '服务端已启动');
|
|||
|
}
|
|||
|
}
|
|||
|
$array = array(
|
|||
|
'redis' => trim($result['redis']) ?: null,
|
|||
|
'redispx' => trim($result['redispx']) ?: 6379,
|
|||
|
'swoole' => 9875,
|
|||
|
'ssl_certificate' => trim($result['ssl_certificate']),
|
|||
|
'ssl_certificate_key' => trim($result['ssl_certificate_key']),
|
|||
|
);
|
|||
|
file_put_contents('./web/cacheSet.log', json_encode($array));
|
|||
|
return $this->result(1, '操作成功');
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//小程序列表
|
|||
|
public function actionWxappList()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
$page = $result['page'] ?: 1;
|
|||
|
$num = ($page - 1) * 10;
|
|||
|
$limit = 10;
|
|||
|
$module = $this->wqData['module'] ?: 'yb_wm';
|
|||
|
$query = (new \yii\db\Query())
|
|||
|
->select('a.uniacid,a.name')
|
|||
|
->from('{{%account_wxapp}} as a')
|
|||
|
->join('LEFT JOIN', '{{%wxapp_versions}} as b', 'b.uniacid = a.uniacid')
|
|||
|
->where(['like', 'b.modules', $module]);
|
|||
|
if ($result['keywords']) {
|
|||
|
$query->andWhere(['like', 'a.name', $result['keywords']]);
|
|||
|
}
|
|||
|
$count = $query->count();
|
|||
|
$list = $query->offset($num)->limit($limit)->all();
|
|||
|
foreach ($list as $key => $v) {
|
|||
|
$info = (new \yii\db\Query())
|
|||
|
->from('{{%account}}')
|
|||
|
->where('acid=:acid', [':acid' => $v['uniacid']])->one();
|
|||
|
if ($info['endtime']) {
|
|||
|
$endTime = date('Y-m-d H:i:s', $info['endtime']);
|
|||
|
} else {
|
|||
|
$endTime = '永久';
|
|||
|
}
|
|||
|
$list[$key]['endTime'] = $endTime;
|
|||
|
$res = Config::getSystemSet('sysTopImage', $v['uniacid']);
|
|||
|
if ($res) {
|
|||
|
$channel_arr = $res['channel_arr'];
|
|||
|
} else {
|
|||
|
$channel_arr = Config::getSystemSet('superPower', 0)['channel_arr'];
|
|||
|
}
|
|||
|
$list[$key]['shopModel'] = Config::getSystemSet('sysTopImage', $v['uniacid'])['shopModel'];
|
|||
|
$list[$key]['shopNum'] = Config::getSystemSet('sysTopImage', $v['uniacid'])['shopNum'];
|
|||
|
if (!$list[$key]['shopModel']) {
|
|||
|
$list[$key]['shopModel'] = Config::getSystemSet('superPower', 0)['shopModel'];
|
|||
|
$list[$key]['shopNum'] = Config::getSystemSet('superPower', 0)['shopNum'];
|
|||
|
}
|
|||
|
$list[$key]['shopModel'] = $list[$key]['shopModel'] ?: 2;
|
|||
|
$list[$key]['shopNum'] = $list[$key]['shopNum'] ?: 50;
|
|||
|
if ($list[$key]['shopModel'] == 1) {
|
|||
|
$list[$key]['shopModel'] = '单门店';
|
|||
|
} else {
|
|||
|
$list[$key]['shopModel'] = '多门店';
|
|||
|
}
|
|||
|
$list[$key]['channel_arr'] = $channel_arr;
|
|||
|
}
|
|||
|
return $this->result(1, '成功', $list, $count);
|
|||
|
}
|
|||
|
|
|||
|
//获取应用的渠道和插件列表
|
|||
|
public function actionGetSuperPower()
|
|||
|
{
|
|||
|
$uniacid = $this->wqData['uniacid'];
|
|||
|
$data = Config::getSystemSet('sysTopImage', $uniacid);
|
|||
|
|
|||
|
if (!$data) {
|
|||
|
$data = Config::getSystemSet('superPower', 0);
|
|||
|
}
|
|||
|
|
|||
|
// 获取超级权限和证书的合集------渠道
|
|||
|
$new_channel = [];
|
|||
|
$channel_ids = $data['channel_arr'];
|
|||
|
$plugConfig = $data['plug_str'];
|
|||
|
$new_ids = $data['use_str'];
|
|||
|
$sysInfo = getSysInfo();
|
|||
|
$serviceData = $sysInfo['authData']['service'];
|
|||
|
$service_ids = $serviceData;
|
|||
|
$plugList = Config::plugConfig();
|
|||
|
$plug_ids = [];
|
|||
|
foreach ($plugList as $v) {
|
|||
|
if (in_array($v['name'], $plugConfig)) {
|
|||
|
$plug_ids[] = $v['name'];
|
|||
|
}
|
|||
|
}
|
|||
|
$row = array(
|
|||
|
'channel_ids' => $channel_ids ?: ['mini'],
|
|||
|
'plug_ids' => $plug_ids ?: [],
|
|||
|
'service_ids' => $service_ids ?: [],
|
|||
|
'new_ids' => $new_ids ?: [],
|
|||
|
);
|
|||
|
return $this->result(1, '成功', $row);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public function actionGetPower()
|
|||
|
{
|
|||
|
$power['content'] = Power::getPower($this->wqData['uniacid'], 'content')['content'];
|
|||
|
$power['icon'] = Power::getPower($this->wqData['uniacid'], 'icon')['icon'];
|
|||
|
$power['deliveryMode'] = Power::getPower($this->wqData['uniacid'], 'deliveryMode')['deliveryMode'] ?: ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|||
|
return $this->result(1, '成功', $power);
|
|||
|
}
|
|||
|
|
|||
|
//查询配送余额
|
|||
|
public function actionDeliveryBalance()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
/* $res=Delivery:: cancelOrder(40);
|
|||
|
var_dump($res);die;*/
|
|||
|
$storeId = $result['storeId'] ?: $this->shop_id;
|
|||
|
$type = $result['type'];
|
|||
|
$balance = '0.00';
|
|||
|
switch ($type) {
|
|||
|
case 2:
|
|||
|
$balance = Delivery::dadaUserAccount($storeId, $this->wqData['uniacid']);
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
$balance = Delivery::sanUserAccount($storeId, $this->wqData['uniacid']);
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
$balance = Delivery::DianwodaUserAccount($storeId, $this->wqData['uniacid']);
|
|||
|
break;
|
|||
|
case 8:
|
|||
|
$balance = Delivery::UuptUserAccount($storeId, $this->wqData['uniacid']);
|
|||
|
break;
|
|||
|
}
|
|||
|
return $this->result(1, '成功', $balance);
|
|||
|
}
|
|||
|
|
|||
|
public function actionTest()
|
|||
|
{
|
|||
|
$card = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_user_card}}')
|
|||
|
->where(['level' => 1, 'condition' => 10, 'uniacid' => 39])
|
|||
|
->orderBy('level desc')
|
|||
|
->one();
|
|||
|
print_R($card);
|
|||
|
die;
|
|||
|
}
|
|||
|
|
|||
|
public function actionAliSaveStore()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
$set = Config::getSystemSet('aliSet', $this->wqData['uniacid']);
|
|||
|
$request = Yii::$app->request;
|
|||
|
$storeId = $result['storeId'] ?: $this->shop_id;
|
|||
|
$info = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_ali_store}}')
|
|||
|
->where('storeId=:storeId', [':storeId' => $storeId])->one();
|
|||
|
if ($request->isGet) {
|
|||
|
if (Yii::$app->params['isDev'] == true) {
|
|||
|
$info['url'] = Yii::$app->request->hostInfo . '/addons/yb_wm/index.php/channelApi/pay-notice/ali-application-notice';
|
|||
|
} else {
|
|||
|
$info['url'] = Yii::$app->request->hostInfo . '/index.php/channelApi/pay-notice/ali-application-notice';
|
|||
|
}
|
|||
|
$info['cityData'] = [$info['province_code'], $info['city_code'], $info['district_code']];
|
|||
|
$info['categoryData'] = [$info['shop_category_pid'], $info['shop_category']];
|
|||
|
return $this->result(1, '成功', $info);
|
|||
|
}
|
|||
|
if (!$result['categoryData']) {
|
|||
|
return $this->result(2, '请选择经营类目');
|
|||
|
}
|
|||
|
if (!$result['cityData']) {
|
|||
|
return $this->result(2, '请选择门店区域');
|
|||
|
}
|
|||
|
$data['shop_name'] = $result['shop_name'];
|
|||
|
$data['province_code'] = $result['cityData'][0];
|
|||
|
$data['city_code'] = $result['cityData'][1];
|
|||
|
$data['district_code'] = $result['cityData'][2];
|
|||
|
$data['address'] = $result['address'];
|
|||
|
$data['shop_category_pid'] = $result['categoryData'][0];
|
|||
|
$data['shop_category'] = $result['categoryData'][1];
|
|||
|
$data['store_no'] = $result['store_no'];
|
|||
|
$data['contact_mobile'] = $result['contact_mobile'];
|
|||
|
$data['ip_role_id'] = $result['ip_role_id'] ?: $set['rebate_pid'];
|
|||
|
$data['uniacid'] = $this->wqData['uniacid'];
|
|||
|
$data['storeId'] = $storeId;
|
|||
|
if ($info) {
|
|||
|
if ($info['shop_id']) {
|
|||
|
$res = Ali::modifyStore($this->wqData['uniacid'], $info, $storeId);
|
|||
|
if ($res['code'] == 1) {
|
|||
|
$data['order_id'] = $res['data']['ant_merchant_expand_shop_modify_response']['order_id'];
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_ali_store}}', $data, ['id' => $info['id']])->execute();
|
|||
|
} else {
|
|||
|
return $this->result(2, $res['msg']);
|
|||
|
}
|
|||
|
} else {
|
|||
|
return $this->result(2, '门店审核中无法修改');
|
|||
|
}
|
|||
|
|
|||
|
} else {
|
|||
|
$res = Ali::saveStore($this->wqData['uniacid'], $data, $storeId);
|
|||
|
if ($res['code'] == 1) {
|
|||
|
$data['order_id'] = $res['data']['ant_merchant_expand_shop_create_response']['order_id'];
|
|||
|
Yii::$app->db->createCommand()->insert('{{%ybwm_ali_store}}', $data)->execute();
|
|||
|
} else {
|
|||
|
return $this->result(2, $res['msg']);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
return $this->result(1, '成功');
|
|||
|
}
|
|||
|
|
|||
|
//授权
|
|||
|
public function actionSendAuth()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
$uniacid = $this->wqData['uniacid'];
|
|||
|
$storeId = $result['storeId'] ?: $this->shop_id;
|
|||
|
$info = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_ali_auth}}')
|
|||
|
->where('storeId=:storeId', [':storeId' => $storeId])->one();
|
|||
|
$res = Ali::authorization($uniacid, $result['account']);
|
|||
|
if ($res['code'] == 1) {
|
|||
|
if ($info) {
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_ali_auth}}', ['account' => $result['account'],
|
|||
|
'batch_no' => $res['data'], 'changeAt' => time(), 'state' => 1], ['id' => $info['id']])->execute();
|
|||
|
} else {
|
|||
|
$data['storeId'] = $storeId;
|
|||
|
$data['uniacid'] = $uniacid;
|
|||
|
$data['account'] = $result['account'];
|
|||
|
$data['state'] = 1;
|
|||
|
$data['createdAt'] = time();
|
|||
|
$data['batch_no'] = $res['data'];
|
|||
|
Yii::$app->db->createCommand()->insert('{{%ybwm_ali_auth}}', $data)->execute();
|
|||
|
}
|
|||
|
return $this->result(1, '成功');
|
|||
|
} else {
|
|||
|
return $this->result(2, $res['msg']);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//查询授权结果
|
|||
|
public function actionAuthInfo()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
$uniacid = $this->wqData['uniacid'];
|
|||
|
$storeId = $result['storeId'] ?: $this->shop_id;
|
|||
|
$info = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_ali_auth}}')
|
|||
|
->where('storeId=:storeId', [':storeId' => $storeId])->one();
|
|||
|
if (!$info['batch_no']) {
|
|||
|
$info['state'] = 0;
|
|||
|
return $this->result(1, '成功', $info);
|
|||
|
}
|
|||
|
$res = Ali::getAuthorization($uniacid, $info['batch_no']);
|
|||
|
if ($res['code'] == 1) {
|
|||
|
$state = 1;
|
|||
|
if ($res['data']['handle_status'] == 'SUCCESS') {
|
|||
|
$state = 2;
|
|||
|
}
|
|||
|
Yii::$app->db->createCommand()->update('{{%ybwm_ali_auth}}', ['merchant_no' => $res['data']['merchant_no'], 'changeAt' => time(), 'state' => $state], ['id' => $info['id']])->execute();
|
|||
|
}
|
|||
|
$list = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_ali_auth}}')
|
|||
|
->where('storeId=:storeId', [':storeId' => $storeId])->one();
|
|||
|
return $this->result(1, '成功', $list);
|
|||
|
}
|
|||
|
|
|||
|
//获取公众号模板
|
|||
|
public function actionGetMessageList()
|
|||
|
{
|
|||
|
$app = WeChat::getWechatConfig($this->wqData['uniacid']);
|
|||
|
$data = $app->template_message->getPrivateTemplates()['template_list'];
|
|||
|
return $this->result(1, '成功', $data);
|
|||
|
}
|
|||
|
|
|||
|
//生成自定义链接二维码
|
|||
|
public function actionCreateUrl()
|
|||
|
{
|
|||
|
$result = axios_request();
|
|||
|
$uniacid = $this->wqData['uniacid'];
|
|||
|
$request = Yii::$app->request;
|
|||
|
if ($request->isGet) {
|
|||
|
$data = (new \yii\db\Query())
|
|||
|
->from('{{%ybwm_wxapp_link}}')
|
|||
|
->where(['uniacid' => $uniacid])
|
|||
|
->orderBy(['id' => 'asc'])
|
|||
|
->all();
|
|||
|
return $this->result(1, '成功', $data);
|
|||
|
}
|
|||
|
$storeId = $result['storeId'] ?: $this->shop_id;
|
|||
|
$path = $result['path'];
|
|||
|
$scene = $result['scene'];
|
|||
|
$is_expire = $result['is_expire'];
|
|||
|
$title = $result['title'];
|
|||
|
$expire_time = $result['expire_time'] ?: 0;
|
|||
|
|
|||
|
$data = WeChat::getWxLink($uniacid, $path, $is_expire, $scene, $title, $expire_time);
|
|||
|
return $this->result(1, '成功', $data);
|
|||
|
}
|
|||
|
|
|||
|
}
|