StoreOrderEconomizeServices.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\dao\order\StoreOrderEconomizeDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\ApiException;
  15. /**
  16. * Class StoreOrderInvoiceServices
  17. * @package app\services\order
  18. */
  19. class StoreOrderEconomizeServices extends BaseServices
  20. {
  21. /**
  22. * LiveAnchorServices constructor.
  23. * @param StoreOrderInvoiceDao $dao
  24. */
  25. public function __construct(StoreOrderEconomizeDao $dao)
  26. {
  27. $this->dao = $dao;
  28. }
  29. /**添加节省金额数据
  30. * @param array $add
  31. * @return mixed
  32. */
  33. public function addEconomize(array $add)
  34. {
  35. if (!$add) throw new ApiException(100026);
  36. return $this->dao->save($add);
  37. }
  38. /**
  39. * @param array $where
  40. * @return array|\think\Model|null
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function getOne(array $where)
  46. {
  47. if (!$where) throw new ApiException(100100);
  48. return $this->dao->getOne($where);
  49. }
  50. /**汇总付费会员节省金额
  51. * @param $uid
  52. * @return bool|float
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function sumEconomizeMoney($uid)
  58. {
  59. if (!$uid) return false;
  60. $list = $this->dao->getList(['uid' => $uid]);
  61. $economizeMoney = 0.00;
  62. if ($list) {
  63. foreach ($list as $k => $v) {
  64. $economizeMoney += $v['postage_price'];
  65. $economizeMoney += $v['member_price'];
  66. $economizeMoney += $v['offline_price'];
  67. $economizeMoney += $v['coupon_price'];
  68. }
  69. }
  70. return sprintf("%.2f",$economizeMoney);
  71. }
  72. }