StoreDiscountDao.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\store\product;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\store\product\StoreDiscounts;
  14. class StoreDiscountDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return StoreDiscounts::class;
  19. }
  20. public function incStock($id)
  21. {
  22. $res = $this->getModel()::getDb()->find($id);
  23. if ($res) {
  24. if ($res['is_limit']) $res->limit_num++;
  25. if ($res->sales > 1) $res->sales--;
  26. $res->save();
  27. }
  28. }
  29. public function decStock($id)
  30. {
  31. $res = $this->getModel()::getDb()->find($id);
  32. if (!$res) {
  33. return false;
  34. }
  35. $res->sales++;
  36. if ($res['is_limit']) {
  37. if ($res['limit_num'] > 0) {
  38. $res->limit_num--;
  39. } else {
  40. return false;
  41. }
  42. }
  43. $res->save();
  44. return true;
  45. }
  46. }