ProductPresellSkuDao.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\ProductPresellSku;
  14. use think\facade\Db;
  15. class ProductPresellSkuDao extends BaseDao
  16. {
  17. protected function getModel(): string
  18. {
  19. return ProductPresellSku::class;
  20. }
  21. public function clear($id)
  22. {
  23. $this->getModel()::getDB()->where('product_presell_id', $id)->delete();
  24. }
  25. public function descStock(int $product_presell_id, string $unique, int $desc)
  26. {
  27. return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)->update([
  28. 'stock' => Db::raw('stock-' . $desc),
  29. 'seles' => Db::raw('seles+' . $desc),
  30. ]);
  31. }
  32. public function incStock(int $product_presell_id, string $unique, int $desc)
  33. {
  34. return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)->update([
  35. 'stock' => Db::raw('stock+' . $desc),
  36. 'seles' => Db::raw('seles-' . $desc),
  37. ]);
  38. }
  39. /**
  40. * TODO 增加 参与或支付成功 人数
  41. * @param int $product_presell_id
  42. * @param string $unique
  43. * @param string $field
  44. * @return mixed
  45. * @author Qinii
  46. * @day 2020-11-27
  47. */
  48. public function incCount(int $product_presell_id,string $unique,string $field,$inc = 1)
  49. {
  50. return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)
  51. ->update([
  52. $field => Db::raw($field.'+' . $inc)
  53. ]);
  54. }
  55. /**
  56. * TODO 减少 参与或支付成功 人数
  57. * @param int $product_presell_id
  58. * @param string $unique
  59. * @param string $field
  60. * @return mixed
  61. * @author Qinii
  62. * @day 2020-11-27
  63. */
  64. public function desCount(int $product_presell_id,string $unique,$inc = 1)
  65. {
  66. $res = $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique',$unique)->find();
  67. if($res->presell->presell_type == 1 ){
  68. $res->one_pay = ($res->one_pay > 0) ? $res->one_pay - $inc : 0;
  69. }else{
  70. $res->two_pay = ($res->two_pay > 0) ? $res->two_pay - $inc : 0;
  71. }
  72. return $res->save();
  73. }
  74. }