ShopService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 app\service\admin\shop\site
  9. */
  10. class ShopService 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. return $this->model->where([['site_id', '=', $this->site_id]])->findOrEmpty();
  23. }
  24. /**
  25. * 获取店铺信息
  26. * @return array
  27. */
  28. public function getInfo()
  29. {
  30. return $this->model->with(['categoryName'])->where([['site_id', '=', $this->site_id]])->findOrEmpty()->toArray();
  31. }
  32. /**
  33. * 店铺资产概况
  34. */
  35. public function getAccountInfo():array
  36. {
  37. $shopInfo = $this->model->where([['site_id', '=', $this->site_id]])->findOrEmpty()->toArray();
  38. if (!empty($shopInfo)) {
  39. $withdrawal_money = floatval($shopInfo['money_get'] - $shopInfo['money'] - $shopInfo['money_cash_outing'] ?? 0);
  40. $shopInfo['withdrawal_money'] = number_format($withdrawal_money,2,'.','');
  41. $settlement_money = 0;
  42. $settlement_array = event('ShopWaitSettlement', ['site_id' => $this->site_id]);
  43. if(!empty($settlement_array))
  44. {
  45. foreach ($settlement_array as $k => $v)
  46. {
  47. $settlement_money += $v;
  48. }
  49. }
  50. $shopInfo['settlement_money'] = number_format($settlement_money,2,'.','');
  51. }
  52. return $shopInfo;
  53. }
  54. /**
  55. * 店铺收款方式编辑
  56. */
  57. public function edit(array $data)
  58. {
  59. $shop_info = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->findOrEmpty()->toArray();
  60. if(empty($shop_info)) return true;
  61. $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->update($data);
  62. return true;
  63. }
  64. /**
  65. * 检查店铺配置信息是否完善
  66. * @return bool
  67. */
  68. public function check()
  69. {
  70. $shop_info = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->findOrEmpty()->toArray();
  71. if (empty($shop_info)) {
  72. return false;
  73. } else {
  74. if ($shop_info['bank_type'] == 1) {
  75. 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;
  76. }
  77. if ($shop_info['bank_type'] == 2) {
  78. if(empty($shop_info['alipay_name']) || empty($shop_info['alipay_account_no'])) return false;
  79. }
  80. }
  81. return true;
  82. }
  83. }