StoreSettingController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace addons\Happiness\backend\controllers;
  3. use addons\Happiness\common\enums\HappinessEnum;
  4. use addons\Happiness\common\models\HappinessStore;
  5. use common\globals\GlobalInvoke;
  6. use addons\Happiness\common\enums\HappinessWithdrawWayEnum;
  7. class StoreSettingController extends BaseController
  8. {
  9. public function actionIndex()
  10. {
  11. if (!\Yii::$app->request->isAjax) {
  12. return $this->render('/setting/index');
  13. }
  14. if (\Yii::$app->request->isGet) {
  15. $basic = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME, 'basic');
  16. if(empty($basic['localtion_limit'])) $basic['localtion_limit'] = 10;
  17. //资产设置
  18. $default_withdraw_way = HappinessWithdrawWayEnum::getDefaultWithDrawWayMap(HappinessWithdrawWayEnum::WITHDRAW_TYPE_2);
  19. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY,$this->mall_id);
  20. $all_withdraw = array_merge($default_withdraw_way,$extension_withdraw_way);
  21. if (!empty($all_withdraw['alipay_tax'])) {
  22. $all_withdraw['alipay_tax'] = $all_withdraw['alipay_tax']['name'];
  23. }
  24. if (!empty($all_withdraw['bank_tax'])) unset($all_withdraw['bank_tax']);
  25. if (!empty($all_withdraw['alipay_tax'])) unset($all_withdraw['alipay_tax']);
  26. if (!empty($all_withdraw['auto'])) unset($all_withdraw['auto']);
  27. $basic['balance_withdraw_way'] = $all_withdraw;
  28. if(!empty($basic['balance_cash_type'])){
  29. $basic['balance_cash_type'] = json_decode($basic['balance_cash_type'],true);
  30. }else{
  31. //默认银行卡/余额提现
  32. $basic['balance_cash_type'] = ['balance','bank'];
  33. }
  34. $basic['name_rule'] = !empty($basic['name_rule'])?json_decode($basic['name_rule'],true):['no'];//命名规则
  35. $basic['name_rule_copy'] = !empty($basic['name_rule_copy'])?json_decode($basic['name_rule_copy'],true):[];//副命名规则
  36. $basic['recharge_list'] = !empty($basic['recharge_list'])?json_decode($basic['recharge_list'],true):[];//充值设置
  37. $basic['goods_label'] = !empty($basic['goods_label'])?json_decode($basic['goods_label'],true):[];//商品标签
  38. $basic['pay_type_list'] = !empty($basic['pay_type_list'])? json_decode($basic['pay_type_list'],true):[];//支付方式
  39. $basic['business_list'] = !empty($basic['business_list'])? json_decode($basic['business_list'],true):[];//身份收益设置
  40. $basic['agent_list'] = !empty($basic['agent_list'])? json_decode($basic['agent_list'],true):[];//身份收益设置
  41. $basic['boss_list'] = !empty($basic['boss_list'])? json_decode($basic['boss_list'],true):[];//身份收益设置
  42. $basic['pay_after_link'] = !empty($basic['pay_after_link'])? json_decode($basic['pay_after_link'],true)
  43. :'';//支付后跳转设置
  44. $basic['compute_period'] = $basic['compute_period'] ?? 0;
  45. //支付方式
  46. $pay_type_list = \Yii::$app->services->pay->getEnablePaymentType($this->mall_id);
  47. $settings = [
  48. 'basic' => $basic,
  49. 'pay_type_list' => $pay_type_list
  50. ];
  51. $group = \Yii::$app->request->get('group');
  52. if (!empty($group)) {
  53. $settings = $settings[$group] ?? [];
  54. }
  55. return $this->success('success', $settings);
  56. } else {
  57. $post = \Yii::$app->request->post();
  58. $group = $post['group'] ?? '';
  59. unset($post['_csrf'], $post['group']);
  60. if (empty($group)) {
  61. return $this->error('参数错误');
  62. }
  63. $rules = [
  64. 'basic' => [
  65. [['is_enable','store_audit', 'delivery_fee', 'service_fee', 'settle_type', 'start_limit', 'start_amount', 'add_limit', 'add_amount', 'delivery_amount','settlement_method'], 'integer'],
  66. [['is_location_limit', 'delivery_fee', 'platform_ratio', 'balance_cash_service_fee', 'localtion_limit'], 'number'],
  67. [['balance_cash_type', 'balance_withdraw_way','recruit_content','recharge_list','goods_label','pay_type_list','business_list','name_rule','name_rule_copy','boss_list','agent_list','pay_after_link'], 'safe'],
  68. [['name_rule_no','name_rule_copy_no','recruit_title'], 'string'],
  69. [['store_share_scale','share_scale','lock_scale','pension_scale','pv_scale','commission_day'], 'number'],
  70. [['compute_period'], 'integer']
  71. ],
  72. ];
  73. $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]);
  74. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  75. $localtion_limit = $post[$group]['localtion_limit'] ? $post[$group]['localtion_limit']: 100000;
  76. if ($post[$group]['is_location_limit'] == 0) $localtion_limit = 100000;
  77. $post[$group]['name_rule']=!empty($post[$group]['name_rule'])?json_encode($post[$group]['name_rule']): '';//命名规则
  78. $post[$group]['name_rule_copy']=!empty($post[$group]['name_rule_copy'])?json_encode($post[$group]['name_rule_copy']): '';//副命名规则
  79. $post[$group]['recharge_list']=!empty($post[$group]['recharge_list'])?json_encode($post[$group]['recharge_list']): '';//充值设置
  80. $post[$group]['goods_label']=!empty($post[$group]['goods_label'])?json_encode($post[$group]['goods_label']): '';//商品标签
  81. $post[$group]['pay_type_list']=!empty($post[$group]['pay_type_list'])?json_encode($post[$group]['pay_type_list']): '';//支付设置
  82. $post[$group]['business_list']=!empty($post[$group]['business_list'])?json_encode($post[$group]['business_list']): '';//身份收益设置
  83. $post[$group]['agent_list']=!empty($post[$group]['agent_list'])?json_encode($post[$group]['agent_list']): '';//身份收益设置
  84. $post[$group]['boss_list']=!empty($post[$group]['boss_list'])?json_encode($post[$group]['boss_list']): '';//身份收益设置
  85. $post[$group]['pay_after_link']=!empty($post[$group]['pay_after_link'])?json_encode($post[$group]['pay_after_link']): '';
  86. \Yii::$app->services->setting->addons->set($this->mall_id, HappinessEnum::ADDONS_NAME, $post);
  87. HappinessStore::updateAll(['distribution_scope' => $localtion_limit], ['mall_id' => $this->mall_id, 'is_alone' => 0]);
  88. return $this->success('保存成功');
  89. }
  90. }
  91. // public function actionTest()
  92. // {
  93. // $data = [
  94. // 'id' => 60752
  95. // ];
  96. // $res = (new OrderCloseListener())->asyncHandle($data);
  97. // print_r($res);exit;
  98. // }
  99. }