ProductPresellSkuDao.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\common\dao\store\product;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\store\product\ProductPresellSku;
  5. use think\facade\Db;
  6. class ProductPresellSkuDao extends BaseDao
  7. {
  8. protected function getModel(): string
  9. {
  10. return ProductPresellSku::class;
  11. }
  12. public function clear($id)
  13. {
  14. $this->getModel()::getDB()->where('product_presell_id', $id)->delete();
  15. }
  16. public function descStock(int $product_presell_id, string $unique, int $desc)
  17. {
  18. return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)->update([
  19. 'stock' => Db::raw('stock-' . $desc),
  20. 'seles' => Db::raw('seles+' . $desc),
  21. ]);
  22. }
  23. public function incStock(int $product_presell_id, string $unique, int $desc)
  24. {
  25. return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)->update([
  26. 'stock' => Db::raw('stock+' . $desc),
  27. 'seles' => Db::raw('seles-' . $desc),
  28. ]);
  29. }
  30. /**
  31. * TODO 增加 参与或支付成功 人数
  32. * @param int $product_presell_id
  33. * @param string $unique
  34. * @param string $field
  35. * @return mixed
  36. * @author Qinii
  37. * @day 2020-11-27
  38. */
  39. public function incCount(int $product_presell_id,string $unique,string $field,$inc = 1)
  40. {
  41. return $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique', $unique)
  42. ->update([
  43. $field => Db::raw($field.'+' . $inc)
  44. ]);
  45. }
  46. /**
  47. * TODO 减少 参与或支付成功 人数
  48. * @param int $product_presell_id
  49. * @param string $unique
  50. * @param string $field
  51. * @return mixed
  52. * @author Qinii
  53. * @day 2020-11-27
  54. */
  55. public function desCount(int $product_presell_id,string $unique,$inc = 1)
  56. {
  57. $res = $this->getModel()::getDB()->where('product_presell_id', $product_presell_id)->where('unique',$unique)->find();
  58. if($res->presell->presell_type == 1 ){
  59. $res->one_pay = ($res->one_pay > 0) ? $res->one_pay - $inc : 0;
  60. }else{
  61. $res->two_pay = ($res->two_pay > 0) ? $res->two_pay - $inc : 0;
  62. }
  63. return $res->save();
  64. }
  65. }