SystemArticleLogic.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\admin\logic;
  3. use app\admin\model\dao\MoneyLog;
  4. use app\admin\model\dao\ScoreLog;
  5. use app\admin\model\dao\ShopOrder;
  6. use app\admin\model\dao\SystemArticle;
  7. use app\admin\model\dao\User;
  8. use app\common\model\BoxModel;
  9. use app\common\model\SystemArticleModel;
  10. use app\common\model\UserMoneyModel;
  11. use think\facade\Cache;
  12. use think\facade\Db;
  13. class SystemArticleLogic
  14. {
  15. public static function getList($page, $limit, $where, $sort)
  16. {
  17. $count = (new SystemArticleModel())
  18. ->where($where)
  19. ->count();
  20. $list = (new SystemArticleModel())
  21. ->where($where)
  22. ->withAttr('type', function ($val, $data) {
  23. return config('type.article')[$val] ? config('type.article')[$val] : '未知类型';
  24. })
  25. ->page($page, $limit)
  26. ->order($sort)
  27. ->select();
  28. return [$count, $list];
  29. }
  30. public static function add($row)
  31. {
  32. $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
  33. $row['create_time'] = sr_getcurtime(time());
  34. unset($row['file']);
  35. $type_info = SystemArticle::getById($row['type']);
  36. if ($type_info) {
  37. $count = SystemArticle::count($row['type']);
  38. if ($count >= $type_info['max_count']) {
  39. return [false, '这种类型只能存在' . $type_info['max_count'] . '种'];
  40. }
  41. }
  42. return (new SystemArticleModel())->insert($row);
  43. }
  44. }