| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020-04-24
- *
- *
- */
- namespace app\controller\admin\wechat;
- use crmeb\basic\BaseController;
- use app\common\repositories\system\CacheRepository;
- use crmeb\services\WechatService;
- use Exception;
- use think\db\exception\DbException;
- use think\facade\Db;
- /**
- * Class WechatMenu
- * @package app\controller\admin\wechat
- * @author xaboy
- * @day 2020-04-24
- */
- class WechatMenu extends BaseController
- {
- /**
- * @param CacheRepository $repository
- * @return mixed
- * @author xaboy
- * @day 2020-04-24
- */
- public function info(CacheRepository $repository)
- {
- return app('json')->success($repository->getResult('wechat_menus') ?? []);
- }
- /**
- * @param CacheRepository $repository
- * @return mixed
- * @throws DbException
- * @author xaboy
- * @day 2020-04-24
- */
- public function save(CacheRepository $repository)
- {
- $buttons = (array)$this->request->param('button', []);
- if (!count($buttons)) return app('json')->fail('请添加至少一个按钮');
- $repository->save('wechat_menus', $buttons);
- $isnertall=[];
- $key=1;
- foreach ($buttons as $k=>&$v){
- // unset($v['key']);
- foreach ($v['sub_button'] as &$item){
- if($item['type']=='click'){
- $Wkey='WeChatMenuKey'.$key;
- $isnertall[]=[
- 'key'=>$Wkey,
- 'type'=>'text',
- 'data'=>json_encode(['content'=>$item['key']]),
- 'status'=>1,
- 'hidden'=>1,
- 'is_menu'=>1
- ];
- $item['key']=$Wkey;
- $key++;
- }
- }
- }
- try {
- WechatService::create()->getApplication()->menu->add($buttons);
- } catch (Exception $e) {
- return app('json')->fail('设置失败:' . $e->getMessage());
- }
- Db::name('wechat_reply')->where('is_menu',1)->delete();
- Db::name('wechat_reply')->insertAll($isnertall);
- return app('json')->success('设置成功');
- }
- }
|