canyin-project/ybcy/controllers/merchant/ConfigController.php
2024-11-01 16:07:54 +08:00

336 lines
15 KiB
PHP

<?php
namespace app\controllers\merchant;
use Illuminate\Support\Facades\DB;
use Yii;
use app\models\common\Config;
use yii\web\Controller;
class ConfigController extends CommonController{
//设置
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']=Config::getSystemSet('superPower',0)['makeName'];
}
if($result['ident']=="miniConfig" || $result['ident']=="wechatConfig"){
$res['uniacid']=$this->wqData['uniacid'];
}
if($result['ident']=="superPower"){//超级权限
//获取项目的应用列表
$plug=getSysInformation();
$channeArr=$plug['authData']['channel']['channel'];
$res['app']=$plug['appData'];
$res['channel_list']=$channeArr;
$res['plug_list']=$plug['authData']['channel']['plug'];
$res['use_list']=Config::menuConfig();
$res['makeName']=Config::getSystemSet('superPower',0)['makeName'];
}
if($result['ident']=="sysTopImage"){//应用权限
if(!$res){
$res=Config::getSystemSet('superPower',0);
}
$res['makeName']=Config::getSystemSet('sysTopImage',$this->wqData['uniacid'])['makeName'];
}
// if($result['ident']=="system"){//应用权限
// $res['role']=$this->userData['role'];
// }
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']=='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;
}
}
$res['portrait']=Yii::$app->session->get('userInfo')['portrait'];
$loginType=Yii::$app->session->get('userInfo')['loginType'];
if($result['ident']=='system'){
//自提订单数量
$storeId=$this->wqData['storeId'];
$res['selfCount']=(new \yii\db\Query())
->select('id')
->from('{{%ybwm_takeout_order}}')
->where('storeId=:storeId AND deliveryMode=10 AND deleteAt=0',[':storeId'=>$storeId])
->andWhere(['in','state',[2,3,4]])
->count();
}
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){
return $this->result(2,'必须开启一种支付');
}
if($result['payOpen']==1 AND (!$result['mchId'] || !$result['key']) ){
return $this->result(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['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和小程序密钥是否填写正确');
}
}
$re=Config::saveSystemSet($result,$result['ident'],$this->wqData['uniacid'],$result['identName']);
if($re){
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'];
$storeId=$this->wqData['storeId'];
if ($request->isGet) {
$res=Config::getStoreSet($result['ident'],$storeId);
if($result['ident']=='delivery'){
$shopInfo=(new \yii\db\Query())
->select(['address', 'lat','lng'])
->from('{{%ybwm_store}}')
->where('id=:storeId',[':storeId'=>$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'=>$storeId])->one();
$res['address']=$shopInfo['address'];
$res['lat']=$shopInfo['lat'];
$res['lng']=$shopInfo['lng'];
}
}
if($result['ident']=='instoreSet'){
$result['payMode']=$result['payMode']?:1;
$result['orderMode']=$result['orderMode']?:1;
}
if($result['ident']=='takeawayVoice'){
if(empty($res)){
$pid=(new \yii\db\Query())
->from('{{%ybwm_store}}')->where(['isMain'=>1])->one();
$res=Config::getStoreSet($result['ident'],$pid['id']);
if(!$res){
$res=array(
"newOrder"=>"1",
"receiving"=>"1",
"receivedOrder"=>"1",
"advanceOrder"=>"1",
"cancelOrder"=>"1",
"chargebackOrder"=>"1",
"reminderOrder"=>"1",
"errorOrder"=>"1",
"printerDisconnect"=>"1",
"slowOrder"=>"1"
);
}
}
}
return $this->result(1,'成功',$res);
}
if(!$result['ident']){
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']=='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'],$storeId,$result['identName'],1);
if($re){
return $this->result(1,'操作成功');
}else{
return $this->result(2,'网络异常,请稍后再试');
}
}
public function actionUpgradeInfo(){
$request = Yii::$app->request;
$result=axios_request();
$data=array(
'domain_url'=>$result['domain_url'],
'version'=>$result['version']
);
$url=Yii::$app->params['domain_url'].'/cloud/upgraded/appUpgradeInfo';
$file_arr=httpRequest($url,$data);
echo $file_arr;die;
}
}