ShopAccountService.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\service\admin\shop\site;
  3. use app\model\shop\Shop;
  4. use core\base\BaseAdminService;
  5. /**
  6. * 店铺服务层
  7. * Class ShopService
  8. * @package addon\mall\app\service\admin\shop\shop
  9. */
  10. class ShopAccountService extends BaseAdminService
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->model = new Shop();
  16. }
  17. /**
  18. * 获取店铺实例
  19. */
  20. public function find()
  21. {
  22. $shopInfo = $this->model->where([['site_id', '=', $this->site_id]])->findOrEmpty();
  23. return $shopInfo;
  24. }
  25. /**
  26. * 获取店铺信息
  27. */
  28. public function getInfo():array
  29. {
  30. $shopInfo = $this->model
  31. ->with([ 'categoryName' ])
  32. ->where([['site_id', '=', $this->site_id]])->findOrEmpty()->toArray();
  33. if (!empty($shopInfo)) {
  34. $withdrawal_money = floatval($shopInfo['money_get'] - $shopInfo['money'] - $shopInfo['money_cash_outing'] ?? 0);
  35. $shopInfo['withdrawal_money'] = number_format($withdrawal_money,2,'.','');
  36. $settlement_money = 0;
  37. $settlement_array = event('ShopWaitSettlement', ['site_id' => $this->site_id]);
  38. if(!empty($settlement_array))
  39. {
  40. foreach ($settlement_array as $k => $v)
  41. {
  42. $settlement_money += $v;
  43. }
  44. }
  45. $shopInfo['settlement_money'] = number_format($settlement_money,2,'.','');
  46. }
  47. return $shopInfo;
  48. }
  49. /**
  50. * 店铺收款方式编辑
  51. */
  52. public function edit(array $data)
  53. {
  54. $shop_info = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->findOrEmpty()->toArray();
  55. if(empty($shop_info)) return true;
  56. $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->update($data);
  57. return true;
  58. }
  59. /**
  60. * 检查店铺配置信息是否完善
  61. * @return bool
  62. */
  63. public function check()
  64. {
  65. $shop_info = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->findOrEmpty()->toArray();
  66. if (empty($shop_info)) {
  67. return false;
  68. } else {
  69. if ($shop_info['bank_type'] == 1) {
  70. if(empty($shop_info['bank_account_name']) || empty($shop_info['bank_account_no']) || empty($shop_info['bank_name']) || empty($shop_info['bank_address'])) return false;
  71. }
  72. if ($shop_info['bank_type'] == 2) {
  73. if(empty($shop_info['alipay_name']) || empty($shop_info['alipay_account_no'])) return false;
  74. }
  75. }
  76. return true;
  77. }
  78. }