IntegralGoodsLogic.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic\integral;
  20. use app\common\enum\IntegralGoodsEnum;
  21. use app\common\logic\BaseLogic;
  22. use app\common\model\IntegralGoods;
  23. /**
  24. * 积分商品
  25. * Class IntegralGoodsLogic
  26. * @package app\adminapi\logic\integral
  27. */
  28. class IntegralGoodsLogic extends BaseLogic
  29. {
  30. /**
  31. * @notes 添加积分商品
  32. * @param array $params
  33. * @return IntegralGoods|\think\Model
  34. * @author 段誉
  35. * @date 2022/3/30 12:17
  36. */
  37. public static function add(array $params)
  38. {
  39. return IntegralGoods::create([
  40. 'name' => $params['name'],
  41. 'code' => $params['code'] ?? '',
  42. 'image' => $params['image'],
  43. 'type' => $params['type'],
  44. 'market_price' => $params['market_price'] ?? '',
  45. 'stock' => $params['stock'],
  46. 'status' => $params['status'],
  47. 'exchange_way' => $params['exchange_way'] ?? 1,
  48. 'need_integral' => $params['need_integral'],
  49. 'need_money' => $params['need_money'] ?? 0,
  50. 'delivery_way' => $params['delivery_way'] ?? 0,
  51. 'balance' => $params['balance'] ?? 0,
  52. 'express_type' => $params['express_type'] ?? 0,
  53. 'express_money' => $params['express_money'] ?? 0,
  54. 'content' => $params['content'] ?? '',
  55. 'sort' => $params['sort'] ?? 0,
  56. ]);
  57. }
  58. /**
  59. * @notes 编辑积分商品
  60. * @param array $params
  61. * @author 段誉
  62. * @date 2022/3/30 14:08
  63. */
  64. public static function edit(array $params)
  65. {
  66. // 包邮或无需快递,运费重置为0
  67. if ($params['delivery_way'] == IntegralGoodsEnum::DELIVERY_NO_EXPRESS
  68. || (isset($params['express_type']) && $params['express_type'] == IntegralGoodsEnum::EXPRESS_TYPE_FREE)
  69. ) {
  70. $params['express_money'] = 0;
  71. $params['express_type'] = IntegralGoodsEnum::EXPRESS_TYPE_FREE;
  72. }
  73. IntegralGoods::update($params, ['id' => $params['id']], [
  74. 'name','code', 'image', 'market_price', 'stock', 'status','exchange_way',
  75. 'need_integral', 'need_money', 'delivery_way', 'balance', 'express_type',
  76. 'express_money', 'content', 'sort'
  77. ]);
  78. }
  79. /**
  80. * @notes 删除积分商品
  81. * @param int $id
  82. * @return bool
  83. * @author 段誉
  84. * @date 2022/3/30 14:11
  85. */
  86. public static function del(int $id): bool
  87. {
  88. return IntegralGoods::destroy($id);
  89. }
  90. /**
  91. * @notes 积分商品详情
  92. * @param int $id
  93. * @return array
  94. * @author 段誉
  95. * @date 2022/3/30 14:14
  96. */
  97. public static function detail(int $id)
  98. {
  99. return IntegralGoods::findOrEmpty($id)->toArray();
  100. }
  101. /**
  102. * @notes 设置积分商品状态
  103. * @param array $params
  104. * @return IntegralGoods
  105. * @author 段誉
  106. * @date 2022/3/30 14:15
  107. */
  108. public static function setStatus(array $params)
  109. {
  110. return IntegralGoods::update(['id' => $params['id'], 'status' => $params['status']]);
  111. }
  112. }