Qrcode.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\wechat;
  10. use app\admin\service\Service;
  11. use app\common\models\wechat\WechatQrcode as WechatQrcodeModel;
  12. use app\common\models\users\Users as UsersModel;
  13. use mall\utils\Tool;
  14. class Qrcode extends Service {
  15. /**
  16. * 获取列表数据
  17. * @param $data
  18. * @return array
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\DbException
  21. * @throws \think\db\exception\ModelNotFoundException
  22. */
  23. public static function getList($data){
  24. $count = WechatQrcodeModel::count();
  25. $result = WechatQrcodeModel::page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray();
  26. foreach ($result as $k=>$v){
  27. $user = UsersModel::where("id",$v['user_id'])->find();
  28. $list['data'][$k]['image'] = Tool::thumb($v['path']);
  29. $list['data'][$k]['username'] = $user["username"];
  30. $list['data'][$k]['nickname'] = $user["nickname"];
  31. }
  32. return [ "count"=>$count, "data"=>$result ];
  33. }
  34. /**
  35. * 删除
  36. * @param $id
  37. * @return bool
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public static function delete($id){
  43. $row = WechatQrcodeModel::where('id',$id)->find();
  44. if(empty($row)){
  45. throw new \Exception("您要查找的数据不存在!",0);
  46. }
  47. WechatQrcodeModel::where('id',$id)->delete();
  48. Tool::deleteFile(Tool::getRootPath() . 'public' . $row['path']);
  49. return true;
  50. }
  51. /**
  52. * 清空
  53. * @return bool
  54. */
  55. public static function clear(){
  56. WechatQrcodeModel::where("1=1")->delete();
  57. Tool::deleteFile(Tool::getRootPath() . 'public/uploads/qrcode');
  58. return true;
  59. }
  60. }