Config.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\store\model;
  11. use app\model\system\Config as ConfigModel;
  12. use app\model\BaseModel;
  13. use Carbon\Carbon;
  14. use app\model\system\Cron;
  15. /**
  16. * 店铺设置信息
  17. */
  18. class Config extends BaseModel
  19. {
  20. /**
  21. * 门店结算相关设置
  22. * @param $site_id
  23. * @return array
  24. */
  25. public function getStoreWithdrawConfig($site_id)
  26. {
  27. $config = new ConfigModel();
  28. $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'SHOP_STORE_WITHDRAW' ] ]);
  29. //数据格式化
  30. $data = [
  31. //是否进行门店结算
  32. 'is_settlement' => $res[ 'data' ][ 'value' ][ 'is_settlement' ] ?? 0,
  33. //结算周期 1 按天 2. 按周 3. 按月 4. 立即结算
  34. 'period_type' => $res[ 'data' ][ 'value' ][ 'period_type' ] ?? 4,
  35. //结算比率
  36. 'settlement_rate' => $res[ 'data' ][ 'value' ][ 'settlement_rate' ] ?? 0,
  37. //结算成本控制 cuppon,point,balance,fenxiao_commission
  38. 'settlement_cost' => $res[ 'data' ][ 'value' ][ 'settlement_cost' ] ?? '',//'cuppon,point,balance,fenxiao_commission'
  39. //是否允许提现
  40. 'is_withdraw' => $res[ 'data' ][ 'value' ][ 'is_withdraw' ] ?? 0,
  41. //是否提现审核
  42. 'is_audit' => $res[ 'data' ][ 'value' ][ 'is_audit' ] ?? 0,
  43. //可提现账户类型 wechat,alipay, bank
  44. 'withdraw_type' => $res[ 'data' ][ 'value' ][ 'withdraw_type' ] ?? '',
  45. 'withdraw_least' => $res[ 'data' ][ 'value' ][ 'withdraw_least' ] ?? 0, // 提现最低金额
  46. ];
  47. $res[ 'data' ][ 'value' ] = $data;
  48. return $res;
  49. }
  50. /**
  51. * 门店结算相关设置
  52. */
  53. public function setStoreWithdrawConfig($site_id, $data)
  54. {
  55. $config = new ConfigModel();
  56. $res = $config->setConfig($data, '门店结算设置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'SHOP_STORE_WITHDRAW' ] ]);
  57. $cron = new Cron();
  58. $execute_time = 0;
  59. switch ( $data[ 'period_type' ] ) {
  60. case 1://天
  61. $date = strtotime(date('Y-m-d 00:00:00'));
  62. $execute_time = strtotime('+1day', $date);
  63. break;
  64. case 2://周
  65. $execute_time = Carbon::parse('next monday')->timestamp;
  66. break;
  67. case 3://月
  68. $execute_time = Carbon::now()->addMonth()->firstOfMonth()->timestamp;
  69. break;
  70. }
  71. if ($execute_time > 0) {
  72. $cron->deleteCron([ [ 'event', '=', 'StoreWithdrawPeriodCalc' ], [ 'relate_id', '=', $site_id ] ]);
  73. $cron->addCron('2', '1', '门店周期结算', 'StoreWithdrawPeriodCalc', $execute_time, $site_id, $data[ 'period_type' ]);
  74. }
  75. return $res;
  76. }
  77. /**
  78. * 获取门店运营相关设置
  79. * @param $site_id
  80. */
  81. public function getStoreBusinessConfig($site_id)
  82. {
  83. $config = new ConfigModel();
  84. $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'SHOP_STORE_BUSINESS' ] ]);
  85. //数据格式化
  86. $data = [
  87. //门店运营模式 shop:店铺整体运营 store:连锁门店运营模式
  88. 'store_business' => $res[ 'data' ][ 'value' ][ 'store_business' ] ?? 'shop',
  89. //是否允许切换门店
  90. 'is_allow_change' => $res[ 'data' ][ 'value' ][ 'is_allow_change' ] ?? 1,
  91. 'confirm_popup_control' => $res[ 'data' ][ 'value' ][ 'confirm_popup_control' ] ?? 1, // 门店确认弹窗
  92. //门店控制权限
  93. 'store_auth' => $res[ 'data' ][ 'value' ][ 'store_auth' ] ?? '',//'config,balance,point,coupon,adjust'
  94. ];
  95. $res[ 'data' ][ 'value' ] = $data;
  96. return $res;
  97. }
  98. /**
  99. * 门店结算相关设置
  100. */
  101. public function setStoreBusinessConfig($site_id, $data)
  102. {
  103. $config = new ConfigModel();
  104. $res = $config->setConfig($data, '门店功能设置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'SHOP_STORE_BUSINESS' ] ]);
  105. return $res;
  106. }
  107. /**
  108. * addSettlementCron 添加门店结算计划任务 默认为3 - 月
  109. */
  110. public function addSettlementCron($site_id)
  111. {
  112. $config = new ConfigModel();
  113. $config->setConfig([ 'period_type' => 3 ], '门店结算设置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'SHOP_STORE_WITHDRAW' ] ]);
  114. $cron = new Cron();
  115. $execute_time = Carbon::now()->addMonth()->firstOfMonth()->timestamp;
  116. $cron->deleteCron([ [ 'event', '=', 'StoreWithdrawPeriodCalc' ], [ 'relate_id', '=', $site_id ] ]);
  117. $res = $cron->addCron('2', '1', '门店周期结算', 'StoreWithdrawPeriodCalc', $execute_time, $site_id, 3);
  118. return $this->success($res);
  119. }
  120. }