AllwinInfo.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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\model;
  9. use app\common\facade\Inform;
  10. use app\allwin\model\Levels;
  11. use app\allwin\model\Vip;
  12. use think\Model;
  13. use util\Util;
  14. use filter\Filter;
  15. use think\db\Where;
  16. class AllwinInfo extends Model{
  17. protected $pk = 'id';
  18. //用户
  19. public function user(){
  20. return $this->hasOne('app\common\model\SystemUser','id','user_id');
  21. }
  22. //一对多管理回复的评论
  23. public function comments(){
  24. return $this->hasMany('AllwinInfoReply','info_id','id');
  25. }
  26. //所属栏目
  27. public function cate(){
  28. return $this->hasOne('AllwinInfoCate','id','cate_id');
  29. }
  30. //是否关注
  31. public function follow(){
  32. return $this->hasOne('AllwinInfoFollow','like_uid','user_id');
  33. }
  34. //是否认证号
  35. public function mp(){
  36. return $this->hasOne('AllwinInfoMp','uid','user_id');
  37. }
  38. //搜索器
  39. public function searchThemesAttr($query,$value){
  40. $value = Filter::filter_escape($value);
  41. if(!empty($value)){
  42. $query->where('themes','like', '%'. $value .'%');
  43. }
  44. }
  45. /**
  46. * 锁定
  47. * @param integer $id
  48. */
  49. public static function lock(int $id,$member_miniapp_id){
  50. $result = self::get($id);
  51. $data['is_lock'] = $result['is_lock'] ? 0 : 1;
  52. if($data['is_lock'] == 0) {
  53. //通知申请者到微信
  54. Inform::sms($result->user_id,$member_miniapp_id,['title' =>'业务进展通知','type' => '同城信息申请','content' =>'您的同城信息申请已经通过审核','state' => '成功']);
  55. }
  56. return AllwinInfo::where('id',$id)->update($data);
  57. }
  58. /**
  59. * 指定
  60. * @param integer $id
  61. */
  62. public static function top(int $id){
  63. $result = self::where(['id' => $id])->find();
  64. $data['is_top'] = $result['is_top'] ? 0 : 1;
  65. return AllwinInfo::where('id',$id)->update($data);
  66. }
  67. /**
  68. * API的信息列表查询
  69. * @param integer $id
  70. */
  71. public static function apiLists($where,$order,$user,$keyword = ''){
  72. $rel = AllwinInfo::with([
  73. 'user' => function($query) {
  74. $query->field('id,nickname,face');
  75. },
  76. 'cate' => function($query) {
  77. $query->field('id,tpl_id,title');
  78. },
  79. 'mp' => function($query) {
  80. $query->field('id,uid,logo,title,is_vip');
  81. }
  82. ])->withSearch(['themes'],['themes' => $keyword])->where($where)->order($order)->paginate(10);
  83. $data = [];
  84. foreach ($rel as $key => $value) {
  85. $data[$key] = $value;
  86. if(empty($value->cate->tpl)){
  87. $data[$key]['button_name'] = '立即下单';
  88. $data[$key]['tips'] = '任何有用户发布,下单后请电话再次确认';
  89. $data[$key]['is_shop'] = 0;
  90. }else{
  91. $data[$key]['button_name'] = $value->cate->tpl->button_name;
  92. $data[$key]['tips'] = $value->cate->tpl->tips;
  93. $data[$key]['is_shop'] = $value->cate->tpl->is_shop;
  94. }
  95. $images = empty($value->images) ? [] : json_decode($value->images,true);
  96. foreach ($images as $i => $img) {
  97. $images[$i] = $img.'?x-oss-process=style/300';
  98. }
  99. $data[$key]['images'] = $images;
  100. $data[$key]['images_len'] = count($images);
  101. $data[$key]['fields'] = empty($value->fields) ? [] : json_decode($value->fields,true);
  102. $data[$key]['create_time'] = util::ftime($value->create_time);
  103. $data[$key]['is_mp'] = empty($value->mp)?0:1;
  104. //是否点赞
  105. $data[$key]['is_like'] = 0;
  106. $data[$key]['like_face'] = empty($value->like_face) ? [] : json_decode($value->like_face,true);
  107. //判断是否被关注
  108. $data[$key]['is_follow'] = !empty($value->follow) && ! empty($user) && $value->follow->uid = $user->id ? 1:0;
  109. }
  110. return $data;
  111. }
  112. //添加或编辑
  113. public static function postThemes($param){
  114. $data['themes'] = $param['content'];
  115. $data['telphone'] = $param['telphone'];
  116. $data['top_money'] = $param['top_money'];
  117. $data['topday'] = $param['topday'];
  118. $data['fields'] = $param['fields'];
  119. $data['images'] = $param['imgs'];
  120. $data['user_id'] = $param['user_id'];
  121. $data['cate_id'] = $param['cate_id'];
  122. $data['store_id'] = $param['store_id'];
  123. $data['order_no'] = $param['order_no'];
  124. $data['price'] = (int)$param['price'];
  125. $data['create_time'] = time();
  126. $data['views'] = rand(1,500);
  127. $data['is_lock'] = 1;
  128. $data['member_miniapp_id'] = $param['member_miniapp_id'];
  129. return self::create($data);
  130. }
  131. /**
  132. * 读取信息列表
  133. * @param integer 读取ID
  134. * @return json
  135. */
  136. public function lists(array $where,int $num = 10){
  137. $rel = self::where($where)
  138. ->field('id,is_top,cate_id,cate_name,user_id,member_miniapp_id,themes,images,sort,telphone,views,task_money,topday,is_pay,create_time')
  139. ->order('is_top desc,sort desc,id desc')
  140. ->paginate($num);
  141. $data = [];
  142. foreach ($rel as $key => $value) {
  143. $data[$key] = $value;
  144. $data[$key]['face'] = $value->user['face'];
  145. $data[$key]['nickname'] = $value['user']['nickname'];;
  146. $data[$key]['images'] = empty($value['images']) ? []: json_decode($value['images']);
  147. $data[$key]['create_time'] = util::ftime($value['create_time']);
  148. }
  149. return $data;
  150. }
  151. /**
  152. * 获取某个评论列表
  153. * @param integer 读取ID
  154. * @return json
  155. */
  156. public function reply(array $where,int $num = 10){
  157. $rel = self::view('allwin_info_reply','id,info_id,user_id,reply,create_time')
  158. ->view('system_user','face,nickname','allwin_info_reply.user_id = system_user.id')
  159. ->where($where)
  160. ->where(['state' => 1])
  161. ->order('id desc')->paginate($num,true)->toArray();
  162. $data = $rel['data'];
  163. foreach ($data as $key => $value) {
  164. $data[$key]['create_time'] = util::ftime($value['create_time']);
  165. }
  166. return $data;
  167. }
  168. /**
  169. * 信息发布获利
  170. * @param integer $miniapp_id 来源小程序
  171. * @param integer $uid 用户ID
  172. * @param float $cash_fee (分)
  173. * @param [type] $config 系统配置
  174. * @return void
  175. */
  176. public static function sendinfo($order){
  177. $level = Levels::where(['user_id' => $order->user_id,'level'=>[1,2]])->select();
  178. $level1 = 0;
  179. $level2 = 0;
  180. foreach ($level as $value) {
  181. if ($value['level'] == 1) {
  182. $level1 = $value['parent_id'];
  183. }
  184. if ($value['level'] == 2) {
  185. $level2 = $value['parent_id'];
  186. }
  187. }
  188. $config = AllwinInfoConfig::config($order->member_miniapp_id);
  189. if ($level1) {
  190. $rel1 = Vip::where(['user_id' => $level1,'state'=>1,'is_lock' =>0])->field('user_id')->find();
  191. if (!empty($rel1)) {
  192. $bring = intval($order->top_money*($config->bring/100));
  193. $l1_money = (float)money($bring/100);
  194. if ($l1_money > 0) {
  195. Bank::dueMoney($order->member_miniapp_id,$level1,$l1_money);
  196. BankBill::add(['miniapp_id'=>$order->member_miniapp_id,'store_id' => 0,'money'=>$l1_money,'uid'=>$level1,'pay_uid' => $order->user_id],'同城推荐奖励');
  197. }
  198. }
  199. }
  200. if ($level2) {
  201. $rel2 = Vip::where(['user_id' => $level2,'state'=>1,'is_lock' => 0])->field('user_id')->find();
  202. if (!empty($rel2)) {
  203. $reward = intval($order->top_money*($config->reward/100));
  204. $l2_money = (float)money($reward/100);
  205. if ($l2_money > 0) {
  206. Bank::dueMoney($order->member_miniapp_id,$level2,$l2_money);
  207. BankBill::add(['miniapp_id' => $order->member_miniapp_id,'store_id' => 0,'money'=> $l2_money,'uid'=>$level2,'pay_uid' =>$order->user_id],'同城推荐奖励');
  208. }
  209. }
  210. }
  211. }
  212. }