Quan.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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\allwin\controller;
  9. use app\allwin\model\AllwinStoreQuan;
  10. use app\allwin\model\AllwinStore;
  11. class Quan extends Common{
  12. /**
  13. * 列表
  14. */
  15. public function index(){
  16. $view['lists'] = AllwinStoreQuan::where(['member_miniapp_id' => $this->member_miniapp_id])->order('id desc')->paginate(20);
  17. $view['pathMaps'] = [['name'=>'商圏管理','url'=> url("quan/index")]];
  18. return $this->fetch()->assign($view);
  19. }
  20. /**
  21. * 已绑定商圏列表
  22. */
  23. public function storeIndex(int $id){
  24. $view['quan_id'] = $id;
  25. $view['lists'] = AllwinStore::where(['member_miniapp_id' => $this->member_miniapp_id, 'quan_id' => $id])->order('id desc')->paginate(20);
  26. $view['pathMaps'] = [['name'=>'商圏管理','url'=> url("quan/index")],['name'=>'商圈商户','url'=> url("quan/storeindex",['id' => $id])]];
  27. return $this->fetch()->assign($view);
  28. }
  29. /**
  30. * 商圏列表
  31. */
  32. public function select(int $quan_id){
  33. $condition = [];
  34. $condition[] = ['member_miniapp_id', '=', $this->member_miniapp_id];
  35. if(request()->isAjax()){
  36. $ids = $this->request->param('ids');
  37. if(empty($ids)){
  38. return json(['code'=>0,'msg'=>'请选择要入住商圏的好店']);
  39. }
  40. $result = AllwinStore::where($condition)->whereIn('id',$ids)->update(['quan_id' => $quan_id]);
  41. if($result){
  42. return json(['code'=>200,'msg'=>'好店入住商圏成功','data' =>[]]);
  43. }else{
  44. return json(['code'=>0,'msg'=>'好店入住商圏失败']);
  45. }
  46. }else{
  47. $keyword = $this->request->param('keyword');
  48. if(!empty($keyword)) {
  49. $condition[] = ['name', 'like', '%' . $keyword . '%'];
  50. }
  51. $view['lists'] = AllwinStore::where($condition)->order('id desc')->paginate(20);
  52. $view['keyword'] = $keyword;
  53. $view['quan_id'] = $quan_id;
  54. return $this->fetch()->assign($view);
  55. }
  56. }
  57. //编辑
  58. public function edit(){
  59. if(request()->isAjax()){
  60. $param = [
  61. 'id' => $this->request->param('id/d',0),
  62. 'title' => $this->request->param('title/s'),
  63. 'content' => $this->request->param('content/s'),
  64. 'picture' => $this->request->param('picture/s'),
  65. ];
  66. $validate = $this->validate($param,'Quan.edit');
  67. if(true !== $validate){
  68. return json(['code'=>0,'msg'=>$validate]);
  69. }
  70. $result = AllwinStoreQuan::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $param['id']])->find();
  71. if($result){
  72. $result->title = $param['title'];
  73. $result->content = $param['content'];
  74. $result->picture = $param['picture'];
  75. $result->save();
  76. }else{
  77. $param['member_miniapp_id'] = $this->member_miniapp_id;
  78. AllwinStoreQuan::create($param);
  79. }
  80. return json(['code'=>200,'url'=>url('quan/index'),'msg'=>'操作成功']);
  81. }else{
  82. $view['info']= AllwinStoreQuan::where(['id' => $this->request->param('id/d',0),'member_miniapp_id' => $this->member_miniapp_id])->find();
  83. return $this->fetch()->assign($view);
  84. }
  85. }
  86. //删除商圈
  87. public function delete(int $id){
  88. $store = AllwinStore::where(['member_miniapp_id' => $this->member_miniapp_id,'quan_id' => $id])->find();
  89. if($store){
  90. return json(['code'=>403,'msg'=>'删除失败,商圏中还包含店铺']);
  91. }
  92. $result = AllwinStoreQuan::destroy($id);
  93. if($result){
  94. return json(['code'=>200,'msg'=>'操作成功']);
  95. }else{
  96. return json(['code'=>403,'msg'=>'删除失败']);
  97. }
  98. }
  99. //从商圏中删除好店
  100. public function deleteStore(int $id){
  101. $result = AllwinStore::where(['id' => $id])->update(['quan_id' => 0]);
  102. if($result){
  103. return json(['code'=>200,'msg'=>'操作成功']);
  104. }else{
  105. return json(['code'=>403,'msg'=>'删除失败']);
  106. }
  107. }
  108. }