Card.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 商品分类管理
  7. */
  8. namespace app\bestbao\controller;
  9. use app\bestbao\model\BestbaoCard;
  10. use app\bestbao\model\BestbaoInformation;
  11. class Card extends Common{
  12. public function initialize(){
  13. parent::initialize();
  14. $this->assign('pathMaps',[['name'=>'卡片管理','url'=>'javascript:;']]);
  15. }
  16. /**
  17. * 企业信息
  18. * @return void
  19. */
  20. public function index(){
  21. if(request()->isAjax()){
  22. $id = $this->request->param('id/d');
  23. $data = [
  24. 'title' => $this->request->param('title/s'),
  25. 'content' => $this->request->param('content/s'),
  26. 'logo' => $this->request->param('logo/s'),
  27. 'phone' => $this->request->param('phone/s'),
  28. 'email' => $this->request->param('email/s'),
  29. 'address' => $this->request->param('address/s'),
  30. 'longitude' => $this->request->param('longitude/s'),
  31. 'latitude' => $this->request->param('latitude/s'),
  32. 'member_miniapp_id' => $this->member_miniapp_id,
  33. 'create_time' => time(),
  34. 'update_time' => time(),
  35. ];
  36. $validate = $this->validate($data,'Card.edit');
  37. if(true !== $validate){
  38. return json(['code'=>0,'msg'=>$validate]);
  39. }
  40. if($id > 0){
  41. $data['id'] = $id;
  42. $result = BestbaoCard::update($data);
  43. }else{
  44. $result = BestbaoCard::create($data);
  45. }
  46. if($result){
  47. return enjson(200,'操作成功',['url'=>url('card/index')]);
  48. }else{
  49. return enjson(0);
  50. }
  51. }else{
  52. $view['info'] = BestbaoCard::where(['member_miniapp_id' => $this->member_miniapp_id])->find();
  53. $view['imgs'] = empty($view['info']['imgs']) ? [] : json_decode($view['info']['imgs'],true);
  54. return view()->assign($view);
  55. }
  56. }
  57. /**
  58. * 获取地图定位
  59. * @param [type] $address
  60. * @return void
  61. */
  62. public function baidu($address){
  63. $view['address'] = $address;
  64. $view['cityname'] = '北京市';
  65. return view()->assign($view);
  66. }
  67. /**
  68. * 资讯列表
  69. */
  70. public function information(){
  71. $view['lists'] = BestbaoInformation::where(['member_miniapp_id' => $this->member_miniapp_id])->order('create_time desc')->paginate(10);
  72. return view()->assign($view);
  73. }
  74. /**
  75. * @return \think\response\Json|\think\response\View
  76. * 编辑添加资讯
  77. */
  78. public function informationEdit(){
  79. if(request()->isAjax()){
  80. $id = $this->request->param('id/d');
  81. $data = [
  82. 'title' => $this->request->param('title/s'),
  83. 'note' => $this->request->param('note/s'),
  84. 'picture' => $this->request->param('picture/s'),
  85. 'content' => $this->request->param('content/s'),
  86. 'member_miniapp_id' => $this->member_miniapp_id,
  87. ];
  88. $validate = $this->validate($data,'Card.informationEdit');
  89. if(true !== $validate){
  90. return json(['code'=>0,'msg'=>$validate]);
  91. }
  92. if($id > 0){
  93. $data['id'] = $id;
  94. $result = BestbaoInformation::update($data);
  95. }else{
  96. $data['create_time'] = time();
  97. $result = BestbaoInformation::create($data);
  98. }
  99. if($result){
  100. return enjson(200,'操作成功',['url'=>url('Card/information')]);
  101. }else{
  102. return enjson(0);
  103. }
  104. }else{
  105. $view['info'] = BestbaoInformation::where(['id' => $this->request->param('id/d',0),'member_miniapp_id' => $this->member_miniapp_id])->find();
  106. return view()->assign($view);
  107. }
  108. }
  109. //删除
  110. public function informationDel(int $id){
  111. $result = BestbaoInformation::destroy($id);
  112. if($result){
  113. return enjson(200);
  114. }else{
  115. return enjson(403,'删除失败');
  116. }
  117. }
  118. }