You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StoreOrderEconomizeServices.php 2.0KB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\services\order;
  3. use app\dao\order\StoreOrderEconomizeDao;
  4. use app\services\BaseServices;
  5. use crmeb\traits\ServicesTrait;
  6. use think\exception\ValidateException;
  7. /**
  8. * 计算节省金额
  9. * Class StoreOrderEconomizeServices
  10. * @package app\services\order
  11. */
  12. class StoreOrderEconomizeServices extends BaseServices
  13. {
  14. use ServicesTrait;
  15. /**
  16. * LiveAnchorServices constructor.
  17. * @param StoreOrderInvoiceDao $dao
  18. */
  19. public function __construct(StoreOrderEconomizeDao $dao)
  20. {
  21. $this->dao = $dao;
  22. }
  23. /**
  24. * 添加节省金额数据
  25. * @param array $add|\think\Model
  26. */
  27. public function addEconomize(array $add)
  28. {
  29. if (!$add) throw new ValidateException('数据不存在');
  30. return $this->dao->save($add);
  31. }
  32. /**
  33. * @param array $where
  34. * @return array|\think\Model|null
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getOne(array $where)
  40. {
  41. if (!$where) throw new ValidateException('条件缺失');
  42. return $this->dao->getOne($where);
  43. }
  44. /**
  45. * 汇总付费会员节省金额
  46. * @param $uid
  47. * @return false|string
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function sumEconomizeMoney($uid)
  53. {
  54. if (!$uid) return false;
  55. $list = $this->dao->getList(['uid' => $uid]);
  56. $economizeMoney = 0.00;
  57. if ($list) {
  58. foreach ($list as $k => $v) {
  59. $economizeMoney += $v['postage_price'];
  60. $economizeMoney += $v['member_price'];
  61. $economizeMoney += $v['offline_price'];
  62. $economizeMoney += $v['coupon_price'];
  63. }
  64. }
  65. return sprintf("%.2f", $economizeMoney);
  66. }
  67. }