SmartbcStore.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\smartbc\model;
  9. use app\common\facade\Inform;
  10. use think\Model;
  11. use util\Util;
  12. class SmartbcStore extends Model{
  13. protected $autoWriteTimestamp = true;
  14. protected $updateTime = false;
  15. //加入的群组
  16. public function group(){
  17. return $this->belongsToMany('SmartbcStoreGroup','SmartbcStoreUnion','group_id','store_id');
  18. }
  19. //所属管理员
  20. public function user(){
  21. return $this->hasOne('app\common\model\SystemUser','id','manage_uid');
  22. }
  23. //连锁门店
  24. public function chain(){
  25. return $this->hasMany('SmartbcStoreChain','store_id','id');
  26. }
  27. //搜索好店名称
  28. public function searchNameAttr($query,$value){
  29. if(!empty($value)){
  30. $query->where('name','like', '%'.$value .'%');
  31. }
  32. }
  33. //添加或编辑
  34. public static function edit($param){
  35. $data['manage_uid'] = trim($param['manage_uid']);
  36. $data['cate_id'] = trim($param['cate_id']);
  37. $data['cate_sid'] = trim($param['cate_sid']);
  38. $data['cate_name'] = trim($param['cate_name']);
  39. $data['name'] = trim($param['name']);
  40. $data['address'] = trim($param['address']);
  41. $data['longitude'] = trim($param['longitude']);
  42. $data['latitude'] = trim($param['latitude']);
  43. $data['telphone'] = trim($param['telphone']);
  44. $data['img'] = trim($param['img']);
  45. $data['mch_id'] = trim($param['mch_id']);
  46. $data['is_top'] = 0;
  47. $data['imgs'] = json_encode($param['imgs']);
  48. if(isset($param['id'])){
  49. self::update($data,['id'=>(int)$param['id']]);
  50. return $param['id'];
  51. }else{
  52. $data['create_time'] = time();
  53. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  54. $data['sort'] = 0;
  55. return self::insertGetId($data);
  56. }
  57. }
  58. /**
  59. * 置顶或取消
  60. * @param integer $id
  61. */
  62. public static function isTop(int $id){
  63. $result = self::where(['id' => $id])->field('is_top')->find();
  64. $data['is_top'] = $result['is_top'] ? 0 : 1;
  65. return self::where('id',$id)->update($data);
  66. }
  67. /**
  68. * 锁定或取消
  69. * @param integer $id
  70. */
  71. public static function isLock(int $id,$member_miniapp_id){
  72. $result = self::where(['id' => $id])->field('is_lock,manage_uid')->find();
  73. $data['is_lock'] = $result['is_lock'] ? 0 : 1;
  74. if($data['is_lock'] == 0) {
  75. //通知申请者到微信
  76. Inform::sms($result->manage_uid,$member_miniapp_id,['title' =>'业务进展通知','type' => '好店申请','content' =>'您的好店申请已经通过审核','state' => '成功']);
  77. }
  78. return self::where('id',$id)->update($data);
  79. }
  80. //根据管理ID获取所属商户
  81. public static function manageStore(int $uid){
  82. return self::with(['chain' => function($query) {
  83. $query->field('id,store_id,title,address,telphone,longitude,latitude');
  84. }])->where(['manage_uid' => $uid])->field('id,name,address,img,telphone,longitude,latitude,mch_id')->find();
  85. }
  86. /**
  87. * 读取商家详情(api)
  88. * @param integer 读取ID
  89. * @return json
  90. */
  91. public static function getView(array $where){
  92. $data = self::where($where)->find();
  93. if(empty($data)){
  94. return false;
  95. }else{
  96. if($data['latitude'] > 0 && $data['longitude'] > 0 ){
  97. $map = bdMap_to_txMap($data['latitude'],$data['longitude']);
  98. $data['longitude'] = $map['lng'];
  99. $data['latitude'] = $map['lat'];;
  100. }
  101. $data['img'] = $data['img']."?x-oss-process=style/w100";
  102. $imgs = empty($data['imgs']) ? [] :json_decode($data['imgs']);
  103. $imga = [];
  104. foreach ($imgs as $key => $img) {
  105. $imga[$key] = $img."?x-oss-process=style/500";
  106. }
  107. $data['imgs'] = $imga;
  108. $data['create_time'] = util::ftime($data['create_time']);
  109. $data['tags'] = explode(',',$data['tags']);
  110. $data['distance'] = '0km'; //经纬度距离判断
  111. $data['chains'] = $data['chains'];
  112. return $data;
  113. }
  114. }
  115. }