Citys.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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\citys\model;
  9. use app\common\facade\Inform;
  10. use app\citys\model\Levels;
  11. use app\citys\model\Vip;
  12. use think\Model;
  13. use util\Util;
  14. use filter\Filter;
  15. use think\db\Where;
  16. class Citys extends Model{
  17. protected $pk = 'id';
  18. protected $json = ['images','fields','like_face'];
  19. protected $jsonAssoc = true;
  20. //用户
  21. public function user(){
  22. return $this->hasOne('app\common\model\SystemUser','id','uid');
  23. }
  24. //一对多管理回复的评论
  25. public function comments(){
  26. return $this->hasMany('CitysReply','info_id','id');
  27. }
  28. //所属模板
  29. public function cate(){
  30. return $this->hasOne('CitysCate','id','cate_id');
  31. }
  32. //所属主题
  33. public function types(){
  34. return $this->hasOne('CitysType','id','type_id');
  35. }
  36. //是否关注
  37. public function follow(){
  38. return $this->hasOne('CitysFollow','like_uid','uid');
  39. }
  40. //是否认证号
  41. public function mp(){
  42. return $this->hasOne('CitysMp','uid','uid');
  43. }
  44. //是否显示手机号
  45. public function showphone(){
  46. return $this->hasOne('CitysPhone','info_id','id');
  47. }
  48. //搜索器
  49. public function searchThemesAttr($query,$value){
  50. $value = Filter::filter_escape($value);
  51. if(!empty($value)){
  52. $query->where('themes','like', '%'. $value .'%');
  53. }
  54. }
  55. /**
  56. * 图片批量增加处理
  57. * @return void
  58. */
  59. public function getImagesAttr($value){
  60. $images = empty($value)?[] : $value;
  61. foreach ($images as $i => $img) {
  62. $images[$i] = $img;
  63. }
  64. return $images;
  65. }
  66. /**
  67. * 锁定
  68. * @param integer $id
  69. */
  70. public static function lock(int $id,$member_miniapp_id){
  71. $result = self::get($id);
  72. $data['is_lock'] = $result['is_lock'] ? 0 : 1;
  73. if($data['is_lock'] == 0) {
  74. //通知申请者到微信
  75. Inform::sms($result->uid,$member_miniapp_id,['title' =>'业务进展通知','type' => '同城信息申请','content' =>'您的同城信息申请已经通过审核','state' => '成功']);
  76. }
  77. return citys::where('id',$id)->update($data);
  78. }
  79. /**
  80. * 指定
  81. * @param integer $id
  82. */
  83. public static function top(int $id){
  84. $result = self::where(['id' => $id])->find();
  85. $data['is_top'] = $result['is_top'] ? 0 : 1;
  86. return citys::where('id',$id)->update($data);
  87. }
  88. /**
  89. * API的信息列表查询
  90. * @param integer $id
  91. */
  92. public static function apiLists($where,$order,$user,$keyword = ''){
  93. $rel = citys::with([
  94. 'user' => function($query) {
  95. $query->field('id,nickname,face');
  96. },
  97. 'cate' => function($query) {
  98. $query->field('id,tpl_id,price,title');
  99. },
  100. 'types' => function($query) {
  101. $query->field('id,title,price,endtips');
  102. },
  103. 'mp' => function($query) {
  104. $query->field('id,uid,logo,title,is_vip');
  105. },
  106. 'showphone' => function($query) use($user){
  107. $query->field('paid_at,info_id')->where(['uid' => $user->id ?? 0,'paid_at' => 1]);
  108. }
  109. ])->withSearch(['themes'],['themes' => $keyword])->where($where)->order($order)->paginate(10);
  110. $data = [];
  111. foreach ($rel as $key => $value) {
  112. $data[$key] = $value;
  113. if(empty($value->cate->tpl)){
  114. $data[$key]['button_name'] = '立即下单';
  115. $data[$key]['tips'] = '任何有用户发布,下单后请电话再次确认';
  116. $data[$key]['is_shop'] = 0;
  117. }else{
  118. $data[$key]['button_name'] = $value->cate->tpl->button_name;
  119. $data[$key]['tips'] = $value->cate->tpl->tips;
  120. $data[$key]['is_shop'] = $value->cate->tpl->is_shop;
  121. }
  122. $data[$key]['images'] = $value->images;
  123. $data[$key]['images_len'] = count($value->images);
  124. $data[$key]['fields'] = $value->fields;
  125. $data[$key]['create_time'] = util::ftime($value->create_time);
  126. $data[$key]['is_mp'] = empty($value->mp)?0:1;
  127. $data[$key]['showphone'] = empty($value->showphone)?0:1;
  128. //是否点赞
  129. $data[$key]['is_like'] = 0;
  130. $data[$key]['like_face'] = $value->like_face;
  131. //判断是否被关注
  132. $data[$key]['is_follow'] = !empty($value->follow) && ! empty($user) && $value->follow->uid = $user->id ? 1:0;
  133. }
  134. return $data;
  135. }
  136. //添加或编辑
  137. public static function postThemes($param){
  138. $data['themes'] = $param['content'] ?? '';
  139. $data['telphone'] = $param['telphone'];
  140. $data['top_money'] = $param['top_money'];
  141. $data['topday'] = $param['topday'];
  142. $data['fields'] = $param['fields'];
  143. $data['images'] = $param['imgs'] ?? [];
  144. $data['uid'] = $param['uid'];
  145. $data['cate_id'] = $param['cate_id'];
  146. $data['type_id'] = $param['type_id'];
  147. $data['order_no'] = $param['order_no'];
  148. $data['price'] = $param['price'];
  149. $data['send_price'] = $param['send_price'];
  150. $data['create_time'] = time();
  151. $data['views'] = rand(1,500);
  152. $data['is_lock'] = $param['is_lock'] ?? 0;
  153. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  154. return self::create($data);
  155. }
  156. /**
  157. * 读取信息列表
  158. * @param integer 读取ID
  159. * @return json
  160. */
  161. public function lists(array $where,int $num = 10){
  162. $rel = self::where($where)
  163. ->field('id,is_top,cate_id,cate_name,uid,member_miniapp_id,themes,images,sort,telphone,views,task_money,topday,is_pay,create_time')
  164. ->order('is_top desc,sort desc,id desc')
  165. ->paginate($num);
  166. $data = [];
  167. foreach ($rel as $key => $value) {
  168. $data[$key] = $value;
  169. $data[$key]['face'] = $value->user['face'];
  170. $data[$key]['nickname'] = $value['user']['nickname'];;
  171. $data[$key]['images'] = empty($value['images']) ? []: json_decode($value['images']);
  172. $data[$key]['create_time'] = util::ftime($value['create_time']);
  173. }
  174. return $data;
  175. }
  176. /**
  177. * 获取某个评论列表
  178. * @param integer 读取ID
  179. * @return json
  180. */
  181. public function reply(array $where,int $num = 10){
  182. $rel = self::view('cityinfo_info_reply','id,info_id,uid,reply,create_time')
  183. ->view('system_user','face,nickname','cityinfo_info_reply.uid = system_user.id')
  184. ->where($where)
  185. ->where(['state' => 1])
  186. ->order('id desc')->paginate($num,true)->toArray();
  187. $data = $rel['data'];
  188. foreach ($data as $key => $value) {
  189. $data[$key]['create_time'] = util::ftime($value['create_time']);
  190. }
  191. return $data;
  192. }
  193. }