123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace app\bestbao\controller;
- use app\bestbao\model\BestbaoCard;
- use app\bestbao\model\BestbaoInformation;
- class Card extends Common{
- public function initialize(){
- parent::initialize();
- $this->assign('pathMaps',[['name'=>'卡片管理','url'=>'javascript:;']]);
- }
-
- public function index(){
- if(request()->isAjax()){
- $id = $this->request->param('id/d');
- $data = [
- 'title' => $this->request->param('title/s'),
- 'content' => $this->request->param('content/s'),
- 'logo' => $this->request->param('logo/s'),
- 'phone' => $this->request->param('phone/s'),
- 'email' => $this->request->param('email/s'),
- 'address' => $this->request->param('address/s'),
- 'longitude' => $this->request->param('longitude/s'),
- 'latitude' => $this->request->param('latitude/s'),
- 'member_miniapp_id' => $this->member_miniapp_id,
- 'create_time' => time(),
- 'update_time' => time(),
- ];
- $validate = $this->validate($data,'Card.edit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- if($id > 0){
- $data['id'] = $id;
- $result = BestbaoCard::update($data);
- }else{
- $result = BestbaoCard::create($data);
- }
- if($result){
- return enjson(200,'操作成功',['url'=>url('card/index')]);
- }else{
- return enjson(0);
- }
- }else{
- $view['info'] = BestbaoCard::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
- $view['imgs'] = empty($view['info']['imgs']) ? [] : json_decode($view['info']['imgs'],true);
- return view()->assign($view);
- }
- }
-
- public function baidu($address){
- $view['address'] = $address;
- $view['cityname'] = '北京市';
- return view()->assign($view);
- }
-
- public function information(){
- $view['lists'] = BestbaoInformation::where(['member_miniapp_id' => $this->member_miniapp_id])->order('create_time desc')->paginate(10);
- return view()->assign($view);
- }
-
- public function informationEdit(){
- if(request()->isAjax()){
- $id = $this->request->param('id/d');
- $data = [
- 'title' => $this->request->param('title/s'),
- 'note' => $this->request->param('note/s'),
- 'picture' => $this->request->param('picture/s'),
- 'content' => $this->request->param('content/s'),
- 'member_miniapp_id' => $this->member_miniapp_id,
- ];
- $validate = $this->validate($data,'Card.informationEdit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- if($id > 0){
- $data['id'] = $id;
- $result = BestbaoInformation::update($data);
- }else{
- $data['create_time'] = time();
- $result = BestbaoInformation::create($data);
- }
- if($result){
- return enjson(200,'操作成功',['url'=>url('Card/information')]);
- }else{
- return enjson(0);
- }
- }else{
- $view['info'] = BestbaoInformation::where(['id' => $this->request->param('id/d',0),'member_miniapp_id' => $this->member_miniapp_id])->find();
- return view()->assign($view);
- }
- }
-
- public function informationDel(int $id){
- $result = BestbaoInformation::destroy($id);
- if($result){
- return enjson(200);
- }else{
- return enjson(403,'删除失败');
- }
- }
- }
|