ShopAdLogic.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\shop\logic\decoration;
  20. use app\common\basics\Logic;
  21. use app\common\enum\ShopAdEnum;
  22. use app\common\model\distribution\DistributionGoods;
  23. use app\common\model\shop\ShopAd;
  24. use app\common\server\FileServer;
  25. use think\facade\Validate;
  26. class ShopAdLogic extends Logic
  27. {
  28. static function lists($params, $shop_id)
  29. {
  30. $where = [
  31. [ 'shop_id', '=', $shop_id ],
  32. ];
  33. $page = $params['page'] ?? 1;
  34. $limit = $params['limit'] ?? 10;
  35. $append = [ 'place_name', 'terminal_name','status_name' ];
  36. $lists = ShopAd::where($where)->page($page, $limit)->append($append)->order('id desc')->select()->toArray();
  37. $count = ShopAd::where($where)->count();
  38. return [ 'count' => $count, 'lists' => $lists ];
  39. }
  40. static function add($params, $shop_id)
  41. {
  42. if (empty($params['terminal']) || ! isset(ShopAdEnum::getTerminal()[$params['terminal']])) {
  43. static::$error = '终端必须选择';
  44. return false;
  45. }
  46. if (empty($params['image'])) {
  47. static::$error = '广告图片必须';
  48. return false;
  49. }
  50. $params['shop_id'] = $shop_id;
  51. ShopAd::create($params, [
  52. 'shop_id',
  53. 'title',
  54. 'place',
  55. 'terminal',
  56. 'image',
  57. 'sort',
  58. 'link',
  59. 'status',
  60. ]);
  61. return true;
  62. }
  63. static function edit($params, $shop_id)
  64. {
  65. if (empty($params['terminal']) || ! isset(ShopAdEnum::getTerminal()[$params['terminal']])) {
  66. static::$error = '终端必须选择';
  67. return false;
  68. }
  69. if (empty($params['image'])) {
  70. static::$error = '广告图片必须';
  71. return false;
  72. }
  73. $where = [
  74. [ 'id', '=', $params['id'] ],
  75. [ 'shop_id', '=', $shop_id ],
  76. ];
  77. ShopAd::update($params, $where, [
  78. 'shop_id',
  79. 'title',
  80. 'place',
  81. 'terminal',
  82. 'image',
  83. 'sort',
  84. 'link',
  85. 'status',
  86. ]);
  87. return true;
  88. }
  89. static function status($params, $shop_id)
  90. {
  91. $where = [
  92. [ 'id', '=', $params['id'] ],
  93. [ 'shop_id', '=', $shop_id ],
  94. ];
  95. ShopAd::update($params, $where, [ 'status' ]);
  96. return true;
  97. }
  98. static function delete($params, $shop_id)
  99. {
  100. ShopAd::destroy(function ($query) use ($params, $shop_id) {
  101. $query->where('shop_id', $shop_id)->where('id', $params['id']);
  102. });
  103. return true;
  104. }
  105. }