181 lines
5.8 KiB
PHP
181 lines
5.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-23
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\controllers;
|
|
|
|
use app\models\Box;
|
|
use app\models\cms\Notice;
|
|
use app\models\cms\RichText;
|
|
use app\models\Store;
|
|
use app\modules\admin\behaviors\LoginBehavior;
|
|
use app\modules\admin\models\wechat\WechatAppForm;
|
|
use app\modules\admin\models\wechat\WechatOfficalAccountForm;
|
|
use app\modules\admin\models\wechat\WechatAppTplMsgForm;
|
|
use app\modules\admin\models\wechat\WechatOfficalAccountTplMsgForm;
|
|
use app\modules\admin\models\SlideEditForm;
|
|
use app\modules\admin\models\SlideListForm;
|
|
use app\modules\admin\models\SlideActionForm;
|
|
use app\models\wechat\WechatApp;
|
|
use app\models\wechat\WechatOfficalAccount;
|
|
use app\models\wechat\WechatAppTplMsg;
|
|
use app\models\wechat\WechatOfficalAccountTplMsg;
|
|
use app\models\Banner;
|
|
use app\models\PickLinkForm;
|
|
|
|
|
|
|
|
class WechatController extends Controller
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return array_merge(parent::behaviors(), [
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function actionMp()
|
|
{
|
|
$this->wechat_app = $this->wechat_app == null ? new WechatApp() : $this->wechat_app;
|
|
if(\Yii::$app->request->isPost){
|
|
$form = new WechatAppForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->model = $this->wechat_app;
|
|
$data = $form->save();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('mp',[
|
|
'model' => $this->wechat_app
|
|
]);
|
|
}
|
|
|
|
public function actionMpTplMsg()
|
|
{
|
|
$form = new WechatAppTplMsgForm();
|
|
if(\Yii::$app->request->isPost){
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$data = $form->save();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$list = $form->search();
|
|
return $this->render('mp-tpl-msg',[
|
|
'list' => $list
|
|
]);
|
|
}
|
|
|
|
public function actionMpSlide()
|
|
{
|
|
$form = new SlideListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$form->zone_id = Banner::ZONE_ID_WXAPP_INDEX;
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$data = $form->search();
|
|
return $this->render('mp-slide', $data);
|
|
}
|
|
|
|
public function actionMpSlideEdit($id = 0)
|
|
{
|
|
$zone_id = Banner::ZONE_ID_WXAPP_INDEX;
|
|
$model = Banner::findOne([
|
|
'id' => $id,
|
|
'cx_mch_id' => $this->cx_mch_id,
|
|
'zone_id' => $zone_id,
|
|
'is_delete' => 0
|
|
]);
|
|
if($model == null){
|
|
$model = new Banner();
|
|
}
|
|
if(\Yii::$app->request->isPost){
|
|
$media = \Yii::$app->request->post('media',0);
|
|
$form = new SlideEditForm();
|
|
if($media == Banner::MEDIA_IMG){
|
|
$form->scenario = 'img';
|
|
}
|
|
if($media == Banner::MEDIA_VIDEO){
|
|
$form->scenario = 'video';
|
|
}
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->zone_id = $zone_id;
|
|
$form->model = $model;
|
|
$form->user_id = \Yii::$app->admin->identity->user_id;
|
|
$data = $form->save();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$store = Store::find()->select('id,name')->where(['is_delete' => 0])->asArray()->all();
|
|
$box = Box::find()->select('id,name,store_id')->where(['is_delete' => 0])->asArray()->all();
|
|
$notice = Notice::find()->alias('n')
|
|
->select('n.id,n.store_id,rt.title as name')
|
|
->leftJoin(['rt' => RichText::tableName()],'rt.id=n.rich_text_id')
|
|
->where([
|
|
'n.cx_mch_id' => $this->cx_mch_id,
|
|
'n.is_delete' => 0,
|
|
'n.is_index' => 1,
|
|
])->asArray()->all();
|
|
|
|
$return_url = \Yii::$app->request->referrer;
|
|
return $this->render('mp-slide-edit', [
|
|
'model' => $model,
|
|
'return_url' => $return_url,
|
|
'links' => (new PickLinkForm())->getPickLink(),
|
|
'store' => $store,
|
|
'box' => $box,
|
|
'notice' => $notice,
|
|
]);
|
|
}
|
|
|
|
public function actionMpSlideShow()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new SlideActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->zone_id = Banner::ZONE_ID_WXAPP_INDEX;
|
|
$data = $form->show();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
public function actionMpSlideHide()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new SlideActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->zone_id = Banner::ZONE_ID_WXAPP_INDEX;
|
|
$data = $form->hide();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
public function actionMpSlideDel()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new SlideActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->cx_mch_id = $this->cx_mch_id;
|
|
$form->zone_id = Banner::ZONE_ID_WXAPP_INDEX;
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
} |