Chain.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\ais\controller\store;
  9. use app\ais\controller\Common;
  10. use app\ais\model\AisStoreCate;
  11. use app\ais\model\AisStore;
  12. use app\ais\model\AisStoreChain;
  13. class Chain extends Common{
  14. public function initialize() {
  15. parent::initialize();
  16. $this->cate = new AisStoreCate();
  17. $this->store = new AisStore();
  18. }
  19. /**
  20. * 连锁门店
  21. */
  22. public function index(int $store_id){
  23. $view['info'] = AisStore::where(['id' => $store_id])->find();
  24. $view['lists'] = AisStoreChain::where(['store_id' => $store_id])->order('sort desc,id desc')->paginate(20);
  25. $view['store_id'] = $store_id;
  26. return view()->assign($view);
  27. }
  28. //编辑
  29. public function edit(int $store_id){
  30. if(request()->isAjax()){
  31. $data = [
  32. 'store_id' => $store_id,
  33. 'id' => $this->request->param('id/d',0),
  34. 'title' => $this->request->param('title/s'),
  35. 'address' => $this->request->param('address/s'),
  36. 'longitude' => $this->request->param('longitude/s'),
  37. 'latitude' => $this->request->param('latitude/s'),
  38. 'telphone' => $this->request->param('telphone/s'),
  39. 'update_time' => time(),
  40. 'member_miniapp_id' => $this->member_miniapp_id
  41. ];
  42. $validate = $this->validate($data,'Store.chain');
  43. if(true !== $validate){
  44. return json(['code'=>0,'msg'=>$validate]);
  45. }
  46. if($data['id']){
  47. $rel = AisStoreChain::update($data);
  48. }else{
  49. $rel = AisStoreChain::create($data);
  50. }
  51. if($rel){
  52. return enjson(200);
  53. }
  54. return enjson(0);
  55. }else{
  56. $view['id'] = $this->request->param('id/d',0);
  57. $view['info'] = AisStoreChain::where(['store_id' => $store_id,'id' => $view['id']])->find();
  58. $view['store_id'] = $store_id;
  59. return view()->assign($view);
  60. }
  61. }
  62. //删除
  63. public function delete(int $id){
  64. AisStoreChain::where($this->mini_program)->where(['id' =>$id])->delete(); //删除好店
  65. return json(['code'=>200,'msg'=>'操作成功']);
  66. }
  67. /**
  68. * 门店排序
  69. */
  70. public function sort(){
  71. if(request()->isAjax()){
  72. $data = [
  73. 'sort' => $this->request->param('sort/d'),
  74. 'id' => $this->request->param('id/d'),
  75. ];
  76. $validate = $this->validate($data,'Category.sort');
  77. if(true !== $validate){
  78. return json(['code'=>0,'msg'=>$validate]);
  79. }
  80. $result = AisStoreChain::where(['id' => $data['id']])->update(['sort' => $data['sort']]);
  81. if($result){
  82. return enjson(200);
  83. }
  84. return enjson(0);
  85. }
  86. }
  87. }