StoreSettingController.php 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  1. <?php
  2. namespace addons\Store\backend\controllers;
  3. use addons\Agent\common\models\AgentLevel;
  4. use addons\Boss\common\models\AddonsBossLevel;
  5. use addons\Distribution\common\models\DistributionLevel;
  6. use addons\DoubleCopy\common\models\DoubleCopyLevel;
  7. use addons\Store\common\enums\StoreEnum;
  8. use addons\Store\common\models\Store;
  9. use addons\Store\common\models\StoreCate;
  10. use addons\Store\common\models\StoreGoods;
  11. use addons\Store\common\models\StoreScoreStoreApply;
  12. use addons\Store\common\services\MerchantReduceProfitService;
  13. use addons\Store\common\sms\SmsConfig;
  14. use addons\Store\common\sms\PayRemindMessage;
  15. use addons\Store\common\sms\ShopExpireMessage;
  16. use addons\Store\common\models\StoreGoodsExtra;
  17. use addons\Store\common\models\StoreSettings;
  18. use addons\Store\common\models\StoreServiceRatioLog;
  19. use common\enums\RabbitMqEnum;
  20. use common\enums\AddonsEnum;
  21. use common\enums\ShippingTypeEnum;
  22. use common\enums\StatusEnum;
  23. use common\globals\GlobalInvoke;
  24. use common\helpers\wechat\WechatTemplate;
  25. use common\models\common\MallSetting;
  26. use common\models\goods\Goods;
  27. use common\models\mall\MallAddons;
  28. use common\models\user\UserLevel;
  29. use common\enums\WithdrawWayEnum;
  30. use common\helpers\sms\Sms;
  31. use common\models\mall\MallHost;
  32. use Overtrue\EasySms\EasySms;
  33. use function GuzzleHttp\json_encode;
  34. class StoreSettingController extends BaseController
  35. {
  36. public function actionIndex()
  37. {
  38. if (!\Yii::$app->request->isAjax) {
  39. return $this->render('/setting/index');
  40. }
  41. $is_install_distribution = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION);
  42. $is_install_agent = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AGENT);
  43. $is_install_boss = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_BOSS);
  44. $is_install_area = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AREA);
  45. $is_install_double_copy = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DOUBLE_COPY);
  46. $is_install_rebate = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_REBATE);
  47. if (\Yii::$app->request->isGet) {
  48. $web_url = \Yii::$app->services->setting->mall->get($this->mall_id, 'basic.web_url');
  49. if (empty($web_url)) {
  50. $h5_domain = 'https://h5.qijianshirjcs.com/';
  51. $mall_sign = '';
  52. } else {
  53. $url_info = explode('?', $web_url);
  54. $h5_domain = $url_info[0];
  55. $mall_sign = substr($url_info[1], mb_strlen('sign='));
  56. }
  57. $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
  58. $cashier = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'cashier');
  59. $enter = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter');
  60. $mode = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'mode');
  61. $decoration = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'decoration');
  62. $goodsStore = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'goodsStore');
  63. $finance = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'finance');
  64. $payment = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'payment');
  65. $tips = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'tips');
  66. $advertising = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'advertising');
  67. $scoreGive = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'scoreGive');
  68. $rating_setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'rating_setting');
  69. $sms_setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'sms_setting');
  70. if (!empty($enter['goods_ids'])) {
  71. $goods_ids = json_decode($enter['goods_ids'], true);
  72. $goods = Goods::find()
  73. ->select('id,goods_name,cover_pic')
  74. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $goods_ids])
  75. ->asArray()
  76. ->all();
  77. } else {
  78. $goods_ids = $goods = [];
  79. }
  80. if (empty($enter)) {
  81. $enter = null;
  82. } else {
  83. $enter['goods_ids'] = $goods_ids;
  84. $enter['goods_list'] = $goods;
  85. $enter['template_store'] = empty($enter['template_store']) ? '' : json_decode($enter['template_store'], true);
  86. }
  87. if (empty($basic)) {
  88. $basic = [
  89. 'is_distribution_enable' => $is_install_distribution,
  90. 'is_agent_enable' => $is_install_agent,
  91. 'is_boss_enable' => $is_install_boss,
  92. 'is_area_enable' => $is_install_area,
  93. 'is_basic_null' => true,
  94. 'is_double_copy_enable' => $is_install_double_copy,
  95. 'is_rebate_enable' => $is_install_rebate,
  96. ];
  97. } else {
  98. $basic['is_distribution_enable'] = $is_install_distribution;
  99. $basic['is_agent_enable'] = $is_install_agent;
  100. $basic['is_boss_enable'] = $is_install_boss;
  101. $basic['is_area_enable'] = $is_install_area;
  102. $basic['is_double_copy_enable'] = $is_install_double_copy;
  103. $basic['is_rebate_enable'] = $is_install_rebate;
  104. }
  105. if(empty($basic['service_fee_settle_type'])) $basic['service_fee_settle_type'] = 1;
  106. if(empty($basic['localtion_limit'])) $basic['localtion_limit'] = 10;
  107. if(empty($basic['double_copy_status'])) $basic['double_copy_status'] = 0;
  108. if(empty($basic['store_distribution_status'])) $basic['store_distribution_status'] = 0;
  109. if(empty($basic['store_agent_status'])) $basic['store_agent_status'] = 0;
  110. if(empty($basic['store_area_status'])) $basic['store_area_status'] = 0;
  111. if(empty($basic['store_boss_status'])) $basic['store_boss_status'] = 0;
  112. if(empty($basic['store_rebate_status'])) $basic['store_rebate_status'] = 0;
  113. if(empty($basic['store_distribution_fee_type'])) $basic['store_distribution_fee_type'] = 1;
  114. if(empty($basic['store_area_fee_type'])) $basic['store_area_fee_type'] = 1;
  115. if(empty($basic['service_fee_type'])) $basic['service_fee_type'] = 0;
  116. if(empty($basic['max_platform_ratio'])) $basic['max_platform_ratio'] = null;
  117. if(empty($basic['min_platform_ratio'])) $basic['min_platform_ratio'] = null;
  118. if(empty($scoreGive['score_give_setting'])) {
  119. $scoreGive['score_give_setting'] = [
  120. 'is_open'=>0,
  121. 'bear'=>0,
  122. 'condition'=>1,
  123. 'give_type'=>1,
  124. 'give_num'=>0,
  125. 'settlement'=>0
  126. ];
  127. }else{
  128. $scoreGive['score_give_setting'] = json_decode($scoreGive['score_give_setting'],true);
  129. }
  130. if(!isset($scoreGive['score_give_is_store_alone'])){
  131. $scoreGive['score_give_is_store_alone'] = 0;
  132. }
  133. $scoreGive['store_limit_type'] = $scoreGive['store_limit_type'] ?? 0;
  134. $scoreGive['store_limit_stores'] = isset($scoreGive['store_limit_stores']) ? json_decode($scoreGive['store_limit_stores'], true) : [];
  135. $scoreGive['store_limit_protocol'] = $scoreGive['store_limit_protocol'] ?? '';
  136. if(empty($advertising)) {
  137. $advertising= ['is_open'=>0,'type'=>1, 'pic'=>'', 'url'=>''];
  138. }else{
  139. if(!isset($advertising['type'])) $advertising['type']= 1;
  140. }
  141. if(empty($rating_setting)) {
  142. $rating_setting= ['total_score'=>1,'environment_score'=>1, 'service_score'=>1, 'staff_score'=>1];
  143. }
  144. if (empty($sms_setting)) {
  145. $sms_setting = [
  146. 'is_pay_remind' => 0,
  147. 'pay_template_id' => '',
  148. 'pay_template_variable' => '',
  149. 'is_alert_expire' => 0,
  150. 'expire_day' => '',
  151. 'expire_template_id' => '',
  152. 'expire_template_variable' => ''
  153. ];
  154. }
  155. /* cashier */
  156. /* ---------- 用户权重相关配置处理 start ------ */
  157. $member_levels = UserLevel::find()
  158. ->select('level,name as level_name')
  159. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  160. ->asArray()
  161. ->all();
  162. if (empty($member_levels)) {
  163. $member_levels = [
  164. // ['level' => 0, 'level_name' => '默认权重'],
  165. ];
  166. }
  167. if (!empty($cashier['members'])) {
  168. $setting_members = json_decode($cashier['members'], true);
  169. $mem_levels = array_column($setting_members, 'level');
  170. $mem_level_discount_map = array_column($setting_members, 'discount', 'level');
  171. } else {
  172. $mem_levels = [];
  173. $mem_level_discount_map = [];
  174. }
  175. foreach ($member_levels as &$mlevel) {
  176. if (!in_array($mlevel['level'], $mem_levels)) {
  177. $mlevel['discount'] = 0;
  178. } else {
  179. $mlevel['discount'] = floatval($mem_level_discount_map[$mlevel['level']] ?? 0);
  180. }
  181. }
  182. //获取服务费比例
  183. $platform_basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
  184. $cashier['platform_service_fee_setting'] = [
  185. 'max_platform_ratio' => $platform_basic['max_platform_ratio'],
  186. 'min_platform_ratio' => $platform_basic['min_platform_ratio']
  187. ];
  188. // dd($member_levels);
  189. /* ---------- 用户权重相关配置处理 end ------ */
  190. $currency_arr = ['commission' => '佣金', 'score' => '积分'];
  191. $mode['distribution_currency'] = $currency_arr;
  192. $currency = array_keys($currency_arr);
  193. // $addons_currency_arr = GlobalInvoke::exec(GlobalInvoke::INVOKE_COMMISSION_TYPE, $this->mall_id, ['mall_id' => $this->mall_id]);
  194. $addons_currency_arr = [];
  195. $addons_currency = [];
  196. $all_addons_currency = [];
  197. foreach ($addons_currency_arr as $v) {
  198. $mode['distribution_currency'] = array_merge($mode['distribution_currency'], array_column($v, 'label', 'name'));
  199. $temp_currency = array_column($v, 'name');
  200. $currency = array_merge($currency, $temp_currency);
  201. $addons_currency = array_merge($addons_currency, $temp_currency);
  202. $all_addons_currency = array_merge($all_addons_currency, array_column($v, 'label', 'name'));
  203. }
  204. /* ---------- 分销权重相关配置处理 start ------ */
  205. $level = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION, 'basic.level');
  206. if (empty($level)) $level = 0;
  207. $distribution_levels = [];
  208. if (!$is_install_distribution) {
  209. $is_distribution_enable = 0;
  210. } else {
  211. $is_distribution_enable = 1;
  212. $distribution_levels = DistributionLevel::find()
  213. ->select('level,name as level_name')
  214. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  215. ->asArray()
  216. ->all();
  217. $init_data = ['level' => 0, 'level_name' => '默认权重'];
  218. if (empty($distribution_levels)) {
  219. $distribution_levels = [$init_data];
  220. } else {
  221. array_unshift($distribution_levels, $init_data);
  222. }
  223. }
  224. /* ---------- 分销权重相关配置处理 end ------ */
  225. /* ---------- 经销权重相关配置处理 start ------ */
  226. $cashier_agent_currency = ['settings' => '佣金'];
  227. $cashier['cashier_agent_currencys'] = array_merge($cashier_agent_currency, $all_addons_currency);
  228. $cashier_agent_currency_arr = array_keys($cashier['cashier_agent_currencys']);
  229. $agent_enable = $this->getCashierEnable(['settings' => ''], $addons_currency, $cashier, 'agent');
  230. $cashier = array_merge($cashier, $agent_enable['cashier']);
  231. $cashier['agent_enable_keys'] = $agent_enable['enable_keys'] ?? '';
  232. // 保存数据是额外验证的字段
  233. $cashier['validate_fields'] = array_merge($agent_enable['keys'], $agent_enable['ratio']);
  234. if (!$is_install_agent) {
  235. $agent_setting_keys = [];
  236. foreach ($cashier_agent_currency_arr as $agent_currency) {
  237. $agent_currency_key = 'agent_' . $agent_currency;
  238. $agent_setting_keys[] = $agent_currency_key;
  239. $cashier[$agent_currency_key] = [
  240. 'team_rewards' => [],
  241. 'equal_rewards' => [],
  242. 'over_rewards' => [],
  243. ];
  244. }
  245. $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $agent_setting_keys);
  246. // $agent_settings = [
  247. // 'team_rewards' => [
  248. // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
  249. // ],
  250. // 'equal_rewards' => [
  251. // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
  252. // ],
  253. // 'over_rewards' => [
  254. // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
  255. // ],
  256. // ];
  257. $is_agent_enable = 0;
  258. } else {
  259. $is_agent_enable = 1;
  260. $agent_levels = AgentLevel::find()
  261. ->select('level,name as level_name')
  262. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  263. ->asArray()
  264. ->all();
  265. if (empty($agent_levels)) {
  266. $agent_levels = [
  267. // ['level' => 0, 'level_name' => '默认权重'],
  268. ];
  269. }
  270. $agent_data = $this->getCashierAgentData($agent_levels, $cashier_agent_currency_arr, $cashier);
  271. $cashier = array_merge($cashier, $agent_data['data']);
  272. $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $agent_data['currency_keys']);
  273. // if (!empty($cashier['agent_settings'])) {
  274. // $agent_settings = json_decode($cashier['agent_settings'], true);
  275. // } else {
  276. // $agent_settings = [
  277. // 'team_rewards' => [
  278. // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
  279. // ],
  280. // 'equal_rewards' => [
  281. // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
  282. // ],
  283. // 'over_rewards' => [
  284. // // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
  285. // ],
  286. // ];
  287. // }
  288. // foreach ($agent_settings as $reward_name => $setting) {
  289. // foreach ($setting as $val) {
  290. // $agent_settings[$reward_name][$val['level']] = $val;
  291. // }
  292. // }
  293. // $ag_levels = array_column($agent_settings['team_rewards'], 'level');
  294. // $agent_level_settings = [];
  295. // foreach ($agent_levels as $alevel) {
  296. // if (!in_array($alevel['level'], $ag_levels)) {
  297. // $arr = $alevel;
  298. // $arr['commission_rate'] = 0;
  299. // $agent_level_settings['team_rewards'][] = $arr;
  300. // $agent_level_settings['equal_rewards'][] = $arr;
  301. // $agent_level_settings['over_rewards'][] = $arr;
  302. // } else {
  303. // $arr = [
  304. // 'level' => $alevel['level'],
  305. // 'level_name' => $alevel['level_name'],
  306. // 'commission_rate' => $agent_settings['team_rewards'][$alevel['level']]['commission_rate'] ?? 0,
  307. // ];
  308. // $agent_level_settings['team_rewards'][] = $arr;
  309. // $arr['commission_rate'] = $agent_settings['equal_rewards'][$alevel['level']]['commission_rate'] ?? 0;
  310. // $agent_level_settings['equal_rewards'][] = $arr;
  311. // $arr['commission_rate'] = $agent_settings['over_rewards'][$alevel['level']]['commission_rate'] ?? 0;
  312. // $agent_level_settings['over_rewards'][] = $arr;
  313. // }
  314. // }
  315. // $agent_settings = $agent_level_settings;
  316. /* ---------- 经销权重相关配置处理 end ------ */
  317. }
  318. if (empty($cashier)) {
  319. $cashier = [
  320. 'service_fee_ratio' => 0,
  321. 'member_status' => 0,
  322. 'is_distribution' => 0,
  323. 'is_agent' => 0,
  324. ];
  325. }
  326. $cashier['deepNames'] = [];
  327. if ($level > 0) $cashier['deepNames'][] = '一级';
  328. if ($level > 1) $cashier['deepNames'][] = '二级';
  329. if ($level > 2) $cashier['deepNames'][] = '三级';
  330. $cashier['members'] = $member_levels;
  331. $cashier_distribution_currencys = ['settings' => '佣金', 'settings_score' => '积分'];
  332. $cashier_distribution_currencys = array_merge($cashier_distribution_currencys, $all_addons_currency);
  333. $distribution_settings = $this->cashierDistributionData($distribution_levels, $cashier, array_keys($cashier_distribution_currencys));
  334. $cashier = array_merge($cashier, $distribution_settings['response']);
  335. $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $distribution_settings['distribution_currency_key']);
  336. $cashier['is_distribution_enable'] = $is_distribution_enable;
  337. // $cashier['agent_settings'] = $agent_settings;
  338. $cashier['is_agent_enable'] = $is_agent_enable;
  339. // 分销收银配置是否开启的开关
  340. $distribution_enable_arr = ['settings' => '', 'settings_score' => 'score'];
  341. $distribution_enable = $this->getCashierEnable($distribution_enable_arr, $addons_currency, $cashier, 'distribution');
  342. $cashier = array_merge($cashier, $distribution_enable['cashier']);
  343. $distribution_enable_keys = $distribution_enable['enable_keys'] ?? '';
  344. $cashier['distribution_enable_keys'] = $distribution_enable_keys;
  345. $cashier['validate_fields'] = array_merge($cashier['validate_fields'], $distribution_enable['keys'], $distribution_enable['ratio']);
  346. $cashier['cashier_distribution_currencys'] = $cashier_distribution_currencys;
  347. /* 模式相关设置 */
  348. /* 分销模式设置 ---- start ------ */
  349. $mode['is_distribution_enable'] = $is_distribution_enable;
  350. if ($is_install_distribution) {
  351. $mode['Distribution'] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_DISTRIBUTION] ?? '', $distribution_levels, $currency, AddonsEnum::ADDONS_NAME_DISTRIBUTION);
  352. } else {
  353. $mode['Distribution'] = null;
  354. }
  355. /* 分销模式设置 ---- end ------ */
  356. /* 经销模式设置 ---- start ------ */
  357. $mode['is_agent_enable'] = $is_agent_enable;
  358. $mode['agent_currency'] = $mode['distribution_currency'];
  359. if ($is_install_agent) {
  360. $mode['Agent'] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_AGENT] ?? '', $agent_levels, $currency, AddonsEnum::ADDONS_NAME_AGENT);
  361. } else {
  362. $mode['Agent'] = null;
  363. }
  364. /* 经销模式设置 ---- end ------ */
  365. /* 股东分红模式设置 ---- start ------ */
  366. if ($is_install_boss) {
  367. $cashier['is_boss_enable'] = 1;
  368. $levels = AddonsBossLevel::find()
  369. ->select('level,name as level_name')
  370. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  371. ->asArray()
  372. ->all();
  373. $cashier_boss_settings=[];
  374. if(isset($cashier['boss_settings'])){
  375. $cashier['boss_settings']=json_decode($cashier['boss_settings'],true);
  376. $cashier_boss_settings=isset($cashier['boss_settings']['rewards'])?$cashier['boss_settings']['rewards']:[];
  377. }
  378. $cashier['boss_settings']['rewards']=$this->getBossSetting($levels,$cashier_boss_settings);
  379. $cashier['boss_settings']['is_boss']=isset($cashier['boss_settings']['is_boss'])?$cashier['boss_settings']['is_boss']:0;
  380. $mode_boss_settings=[];
  381. if(isset($mode['boss_settings'])){
  382. $mode['boss_settings']=json_decode($mode['boss_settings'],true);
  383. $mode_boss_settings=isset($mode['boss_settings']['rewards'])?$mode['boss_settings']['rewards']:[];
  384. }
  385. $mode['boss_settings']['rewards']=$this->getBossSetting($levels,$mode_boss_settings);
  386. if(!empty($mode['boss_settings']['rewards'])){
  387. array_multisort(array_column($mode['boss_settings']['rewards'], 'level'), SORT_ASC, $mode['boss_settings']['rewards']);
  388. }
  389. $mode['boss_settings']['is_boss']=isset($mode['boss_settings']['is_boss'])?$mode['boss_settings']['is_boss']:0;
  390. $mode['is_boss_enable'] = 1;
  391. // $bs_details = [];
  392. // if (!empty($mode['Boss'])) {
  393. // $mode_boss_settings = json_decode($mode['Boss'], true);
  394. // if (!empty($mode_boss_settings['detail'])) {
  395. // foreach ($mode_boss_settings['detail'] as $detail) {
  396. // $bs_details[$detail['level']] = $detail;
  397. // }
  398. // }
  399. // }
  400. // $bs_level_settings = [];
  401. // foreach ($boss_levels as $blevel) {
  402. // if (empty($bs_details[$blevel['level']])) {
  403. // $arr = [
  404. // 'level' => $blevel['level'],
  405. // 'level_name' => $blevel['level_name'],
  406. // 'prize' => 0,
  407. // 'extra_prize' => 0,
  408. // ];
  409. // $bs_level_settings[] = $arr;
  410. // } else {
  411. // $bs_details[$blevel['level']]['level_name'] = $blevel['level_name'];
  412. // $bs_level_settings[] = $bs_details[$blevel['level']];
  413. // }
  414. // }
  415. // if (!empty($bs_level_settings)) {
  416. // $mode_boss_settings['detail'] = $bs_level_settings;
  417. // }
  418. // $mode['Boss'] = $mode_boss_settings;
  419. } else {
  420. $mode['is_boss_enable'] = 0;
  421. // $mode['Boss'] = null;
  422. }
  423. $boss_key=['boss_settings'];
  424. $cashier['validate_fields'] = array_merge($cashier['validate_fields'],$boss_key);
  425. /* 股东分红模式设置 ---- end ------ */
  426. /* 区域分红模式设置 ---- start ------ */
  427. $area_currency_arr = ['detail' => '佣金', 'detail_score' => '积分'];
  428. $area_currency_list = array_merge($area_currency_arr, $all_addons_currency);
  429. $mode['area_currency'] = $area_currency_list;
  430. $cashier['area_currency'] = $area_currency_list;
  431. $area_currency = array_keys($area_currency_arr);
  432. $area_currency = array_merge($area_currency, $addons_currency);
  433. if ($is_install_area) {
  434. $mode['is_area_enable'] = 1;
  435. $area_levels = [
  436. 6 => ['level' => 6, 'level_name' => '大区代'],
  437. 1 => ['level' => 1, 'level_name' => '省代'],
  438. 2 => ['level' => 2, 'level_name' => '市代'],
  439. 3 => ['level' => 3, 'level_name' => '区代'],
  440. 4 => ['level' => 4, 'level_name' => '镇代'],
  441. 5 => ['level' => 5, 'level_name' => '小区代']
  442. ];
  443. $mode['Area'] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_AREA] ?? '', $area_levels, $area_currency, AddonsEnum::ADDONS_NAME_AREA, 0, ['remaining_ratio']);
  444. } else {
  445. $mode['is_area_enable'] = 0;
  446. $mode['Area'] = null;
  447. }
  448. /* 收银台区域分红模式设置 ---- start ------ */
  449. if ($is_install_area) {
  450. $area_levels = [
  451. 6 => ['level' => 6, 'level_name' => '大区代'],
  452. 1 => ['level' => 1, 'level_name' => '省代'],
  453. 2 => ['level' => 2, 'level_name' => '市代'],
  454. 3 => ['level' => 3, 'level_name' => '区代'],
  455. 4 => ['level' => 4, 'level_name' => '镇代'],
  456. 5 => ['level' => 5, 'level_name' => '小区代']
  457. ];
  458. // 获取配置信息
  459. $areaSystem = $this->getAddonsData(
  460. $cashier['AreaCashier'] ?? '',
  461. $area_levels,
  462. $area_currency,
  463. AddonsEnum::ADDONS_NAME_AREA,
  464. 0,
  465. ['remaining_ratio']
  466. );
  467. $cashier['is_area_enable_cashier'] = 1;
  468. $cashier['AreaCashier'] = $areaSystem;
  469. } else {
  470. $cashier['is_area_enable_cashier'] = 0;
  471. $cashier['AreaCashier'] = null;
  472. }
  473. /* 收银台区域分红模式设置 ---- end ------ */
  474. /* 股东分红模式设置 ---- end ------ */
  475. $double_copy_carshier_key = AddonsEnum::ADDONS_NAME_DOUBLE_COPY.'_Cashier';
  476. if ($is_install_double_copy) {
  477. $double_copy_levels = DoubleCopyLevel::find()
  478. ->select('level,name as level_name')
  479. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  480. ->asArray()
  481. ->all();
  482. $mode[AddonsEnum::ADDONS_NAME_DOUBLE_COPY] = $this->getAddonsData($mode[AddonsEnum::ADDONS_NAME_DOUBLE_COPY] ?? '', $double_copy_levels, ['commission'], AddonsEnum::ADDONS_NAME_DOUBLE_COPY, 1, [], ['is_percent' => 0]);
  483. $mode[$double_copy_carshier_key] = $this->getAddonsData($mode[$double_copy_carshier_key] ?? '', $double_copy_levels, ['commission'], AddonsEnum::ADDONS_NAME_DOUBLE_COPY, 1, [], ['is_percent' => 0]);
  484. $cashier['is_double_copy_enable_cashier'] = 1;
  485. $cashier[$double_copy_carshier_key] = $this->getAddonsData($cashier[$double_copy_carshier_key] ?? '', $double_copy_levels, ['commission'], AddonsEnum::ADDONS_NAME_DOUBLE_COPY, 1, [], ['is_percent' => 0]);
  486. } else {
  487. $mode[AddonsEnum::ADDONS_NAME_DOUBLE_COPY] = null;
  488. $mode[$double_copy_carshier_key] = null;
  489. $cashier['is_double_copy_enable_cashier'] = 0;
  490. }
  491. if ($is_install_rebate) {
  492. $mode[AddonsEnum::ADDONS_NAME_REBATE] = $this->getRebateData($mode[AddonsEnum::ADDONS_NAME_REBATE] ?? '');
  493. } else {
  494. $mode[AddonsEnum::ADDONS_NAME_REBATE] = null;
  495. }
  496. // dd($mode);
  497. if(!isset( $cashier['member_status'])){
  498. $cashier['member_status'] = 0;
  499. }
  500. $goodsStore['is_limit_max_price'] = isset($goodsStore['is_limit_max_price'])&&$goodsStore['is_limit_max_price']=='true'?true:false;
  501. $H5Url = \Yii::$app->services->setting->platform->get('system.h5_url');
  502. $store_h5_login_url = $H5Url . '/#/plugins2/Store/admin/login?sign=' . $this->mall['mall_sign'];
  503. $store_setting['store_h5_login_url'] =$store_h5_login_url ;
  504. //收银台设置
  505. $cashier['collect_reward_info'] = json_decode($cashier['collect_reward_info'] ?? '', true) ?? [];
  506. $cashier['payment_reward_info'] = json_decode($cashier['payment_reward_info'] ?? '', true) ?? [];
  507. $cashier['collect_reward'] = array_column($cashier['collect_reward_info'],'type');
  508. $cashier['payment_reward'] = array_column($cashier['payment_reward_info'],'type');
  509. $payment_reward_info = [];
  510. $collect_reward_info = [];
  511. $scoreExpansionConfig = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_SCORE_EXPANSION, 'basic');
  512. if(!empty($scoreExpansionConfig) && !empty($scoreExpansionConfig['frozen_status'])){
  513. $name = empty($scoreExpansionConfig['integral_name']) ? '激活积分' : '激活'.$scoreExpansionConfig['integral_name'];
  514. $payment_reward_info[] = [
  515. 'name'=> $name,
  516. 'type' => 'payment_parent_reward_score',
  517. 'value' => '',
  518. ];
  519. $payment_reward_info[] = [
  520. 'name'=> $name,
  521. 'type' => 'payment_reward_score',
  522. 'value' => '',
  523. ];
  524. $collect_reward_info[] = [
  525. 'name'=> $name,
  526. 'type' => 'collect_reward_score',
  527. 'value' => '',
  528. ];
  529. $collect_reward_info[] = [
  530. 'name'=>$name,
  531. 'type' => 'collect_parent_reward_score',
  532. 'value' => '',
  533. ];
  534. }
  535. if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_CONTRIBUTION_CURRENCY)) {
  536. $collect_reward_info[] = [
  537. 'name'=> '贡献值',
  538. 'type' => 'collect_reward_contribution',
  539. 'value' => '',
  540. ];
  541. }
  542. if(!empty($collect_reward_info) && !empty($cashier['collect_reward_info'])){
  543. foreach($collect_reward_info as &$info){
  544. foreach($cashier['collect_reward_info'] as $item){
  545. if($item['type'] == $info['type']){
  546. $info['value'] = $item['value'];
  547. }
  548. }
  549. }
  550. }
  551. if(!empty($payment_reward_info) && !empty($cashier['payment_reward_info'])){
  552. foreach($payment_reward_info as &$info){
  553. foreach($cashier['payment_reward_info'] as $item){
  554. if($item['type'] == $info['type']){
  555. $info['value'] = $item['value'];
  556. }
  557. }
  558. }
  559. }
  560. //收款方
  561. $cashier['collect_reward_info'] = $collect_reward_info;
  562. $cashier['preferential_undertaking'] = $cashier['preferential_undertaking']??'1';
  563. //付款方
  564. $cashier['payment_reward_info'] = $payment_reward_info;
  565. //收款码额度
  566. $cashier['cashier_amount_info'] = json_decode($cashier['cashier_amount_info'] ?? '',true) ?? [];
  567. $cashier['cashier_amount'] = array_column($cashier['cashier_amount_info'],'type');
  568. $cashier_amount_info = [
  569. ['type' => 'cashier_amount','value' => 0],
  570. ['type' => 'cashier_amount_month','value' => 0]
  571. ];
  572. if(!empty($cashier_amount_info) && !empty($cashier['cashier_amount_info'])){
  573. foreach($cashier_amount_info as &$info){
  574. foreach($cashier['cashier_amount_info'] as $item){
  575. if($item['type'] == $info['type']){
  576. $info['value'] = $item['value'];
  577. }
  578. }
  579. }
  580. }
  581. $cashier['cashier_amount_info'] = $cashier_amount_info;
  582. $cashier['cashier_settle_type'] = $cashier['cashier_settle_type'] ?? 1;
  583. //货款设置
  584. $basic['payment_settle_info'] = json_decode($basic['payment_settle_info'],true) ?? [];
  585. $basic['payment_settle'] = array_column($basic['payment_settle_info'],'type');
  586. $payment_settle_info = [
  587. ['type' => 'settle_judge_yes','value' => 0],
  588. ['type' => 'settle_judge_no','value' => 0]
  589. ];
  590. if(!empty($payment_settle_info) && !empty($basic['payment_settle_info'])){
  591. foreach($payment_settle_info as &$info){
  592. foreach($basic['payment_settle_info'] as $item){
  593. if($item['type'] == $info['type']){
  594. $info['value'] = $item['value'];
  595. }
  596. }
  597. }
  598. }
  599. $basic['payment_settle_info'] = $payment_settle_info;
  600. //资产设置
  601. $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
  602. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY,$this->mall_id);
  603. $all_withdraw = array_merge($default_withdraw_way,$extension_withdraw_way);
  604. if (!empty($all_withdraw['alipay_tax'])) {
  605. $all_withdraw['alipay_tax'] = $all_withdraw['alipay_tax']['name'];
  606. }
  607. $finance['balance_withdraw_way'] = $all_withdraw;
  608. //提现条件
  609. if(!empty($finance['balance_cash_type'])){
  610. $finance['balance_cash_type'] = json_decode($finance['balance_cash_type'],true);
  611. }else{
  612. //默认银行卡/余额提现
  613. $finance['balance_cash_type'] = ['balance','bank'];
  614. }
  615. if(!isset($finance['balance_cash_service_fee'])){
  616. $balance_cash_service_fee = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance.balance_cash_service_fee');
  617. $finance['balance_cash_service_fee'] = $balance_cash_service_fee;
  618. }
  619. if(!isset($finance['balance_cash_service_fee_limit'])){
  620. $finance['balance_cash_service_fee_limit'] = 0;
  621. }
  622. //支付方式
  623. if(!isset($payment['payment_is_enable'])){
  624. $payment['payment_is_enable'] = 0;
  625. }
  626. if(!isset($payment['score_pay_setting'])){
  627. $payment['score_pay_setting'] = 0;
  628. }
  629. if(!isset($payment['score_pay'])){
  630. $payment['score_pay'] = 0;
  631. }
  632. if(!isset($payment['score_pay_password_status'])){
  633. $payment['score_pay_password_status'] = 0;
  634. }
  635. if(empty($payment['payment_type'])){
  636. $payment['payment_type'] = [];
  637. }else{
  638. $payment['payment_type'] = json_decode($payment['payment_type'],true);
  639. }
  640. if (empty($payment['pay_after_link'])) {
  641. $payment['pay_after_link'] = '';
  642. } else {
  643. $payment['pay_after_link'] = json_decode($payment['pay_after_link'], true);
  644. }
  645. $payment['payment_way'] = \Yii::$app->services->pay->getEnablePaymentType($this->mall_id);
  646. if(!isset($payment['score_open_type'])) $payment['score_open_type'] = 1;
  647. $goodsStore['express_title_arr'] = ($goodsStore['express_title_arr'] ?? '') ? json_decode($goodsStore['express_title_arr'] ?? '',true) : ShippingTypeEnum::getMap();
  648. $deduction_proportion = [['min'=>'','max'=>'','deduction_ratio'=>'']];
  649. if(empty($payment['score_deduction'])){
  650. $payment['score_deduction'] = [
  651. 'is_score_deduction' => 0,
  652. 'effective' => 1,
  653. 'bear' => 0,
  654. 'score_balance_ratio' => '',
  655. 'deduction_proportion' => $deduction_proportion,
  656. 'deduction_type' => 0,
  657. 'max_deduction_percent' => 0,
  658. 'store_limit_type' => 0,
  659. 'store_limit_stores' => [],
  660. 'store_limit_stores_deduction' => []
  661. ];
  662. }else{
  663. $payment['score_deduction'] = json_decode($payment['score_deduction'],true);
  664. if(empty($payment['score_deduction']['deduction_proportion'])){
  665. $payment['score_deduction']['deduction_proportion'] = $deduction_proportion;
  666. }
  667. $payment['score_deduction']['deduction_type'] = $payment['score_deduction']['deduction_type'] ?? 0;
  668. $payment['score_deduction']['max_deduction_percent'] = $payment['score_deduction']['max_deduction_percent'] ?? 0;
  669. $payment['score_deduction']['store_limit_type'] = $payment['score_deduction']['store_limit_type'] ?? 0;
  670. $payment['score_deduction']['store_limit_stores_deduction'] = $payment['score_deduction']['store_limit_stores_deduction'] ?? [];
  671. $payment['score_deduction']['store_limit_stores'] = array_keys($payment['score_deduction']['store_limit_stores_deduction']);
  672. }
  673. if(!isset($decoration['default_store_cate_style'])){
  674. $decoration['default_store_cate_style'] = 1;
  675. }
  676. $settings = [
  677. 'basic' => $basic,
  678. 'cashier' => $cashier,
  679. 'enter' => $enter,
  680. 'mode' => $mode,
  681. 'decoration' => $decoration,
  682. 'goodsStore' => $goodsStore,
  683. 'store_setting' => $store_setting,
  684. 'finance' => $finance,
  685. 'payment' => $payment,
  686. 'tips' => empty($tips) ? ['link_tips' => '', 'bank_account_tips' => '',] : $tips,
  687. 'advertising' => $advertising,
  688. 'scoreGive' => $scoreGive,
  689. 'rating_setting' => $rating_setting,
  690. 'sms_setting' => $sms_setting,
  691. ];
  692. $group = \Yii::$app->request->get('group');
  693. if (!empty($group)) {
  694. $settings = $settings[$group] ?? [];
  695. }
  696. $settings['h5_domain'] = MallHost::getHost($this->mall_id, 'h5_url');
  697. $settings['mall_sign'] = $this->mall['mall_sign'];
  698. $settings['level'] = $level;
  699. $settings['basic']['o2o_url'] = 'plugins2/Store/store/storeindex';
  700. $notice_wechat_config = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'notice');
  701. $notice_wechat_template_message_list = StoreEnum::getWechatTemplateMap();
  702. $notice_wechat = empty($notice_wechat_config['notice_wechat']) ? [] : json_decode($notice_wechat_config['notice_wechat'],true);
  703. $notice_wechat_template_message_value = $notice_wechat['template_message'] ?? [];
  704. foreach ($notice_wechat_template_message_list as $key=>$template_name){
  705. if(!isset($notice_wechat_template_message_value[$key])){
  706. $notice_wechat_template_message_value[$key] = ['tem_key'=>'', 'name'=>$template_name, 'tempid'=>'',];
  707. }
  708. }
  709. $settings['notice_wechat']['is_logging'] = $notice_wechat['is_logging'] ?? 1;
  710. $settings['notice_wechat']['template_message'] = $notice_wechat_template_message_value;
  711. return $this->success('success', $settings);
  712. } else {
  713. $post = \Yii::$app->request->post();
  714. $group = $post['group'] ?? '';
  715. unset($post['_csrf'], $post['group']);
  716. if (empty($group)) {
  717. return $this->error('参数错误');
  718. }
  719. $validate_fields = [];
  720. if ($group == 'cashier') {
  721. $validate_fields = $post[$group]['validate_fields'];
  722. }
  723. $rules = [
  724. 'basic' => [
  725. [['o2o_url', 'goods_auth', 'service_fee', 'settle_type', 'platform_ratio', 'risk_management', 'risk_management_ratio', 'settle_scene', 'store_distribution_status', 'store_agent_status', 'store_area_status', 'store_boss_status', 'double_copy_status','store_rebate_status','service_fee_settle_type'], 'required'],
  726. [['o2o_url','platform_address','suona_appSecret','suona_appId','suona_host'], 'string', 'max' => 255],
  727. [['goods_auth', 'settle_type', 'risk_management', 'settle_scene', 'store_distribution_status', 'store_agent_status', 'store_area_status', 'store_boss_status','watch_times','recommend_nums','is_show_location_store', 'double_copy_status','store_rebate_status','is_enable_dollars_symbol', 'is_location_limit', 'service_fee_type', 'store_distribution_fee_type', 'store_area_fee_type','service_fee_settle_type'], 'integer'],
  728. [['service_fee', 'platform_ratio', 'risk_management_ratio', 'min_platform_ratio','max_platform_ratio'], 'number', 'min' => 0, 'max' => 100, 'message' => '比例取值在 0 ~ 100 之间'],
  729. [['localtion_limit'], 'number'],
  730. [['payment_settle_info','payment_settle','score_give_setting','total_score','speciality','service_attitude','timeliness'],'safe'],
  731. [['dollars_symbol'],'string'],
  732. ],
  733. 'cashier' => [
  734. //distribution_settings distribution_settings_score no required
  735. [['service_fee_ratio', 'member_status', 'is_distribution', 'is_agent','preferential_undertaking'], 'required'],
  736. [['member_status', 'is_distribution', 'is_distribution_score', 'is_agent', 'cashier_settle_type'], 'integer'],
  737. [array_merge(['members', 'agent_settings'], $validate_fields), 'safe'],
  738. [['service_fee_ratio'], 'number', 'min' => 0, 'max' => 100, 'message' => '比例取值在 0 ~ 100 之间'],
  739. [['collect_reward','payment_reward','collect_reward_info','payment_reward_info','cashier_amount','cashier_amount_info','cashier_bg_img','payment_settle_info','DoubleCopy_Cashier', 'AreaCashier'],'safe'],
  740. ],
  741. 'enter' => [
  742. [['is_enable', 'time_status', 'expired_days', 'store_audit', 'upload_license_image', 'mode'], 'required'],
  743. [['is_enable', 'time_status', 'expired_days', 'store_audit', 'upload_license_image', 'mode','store_auth', 'is_template', 'is_front_template'], 'integer'],
  744. [['recruit_title', 'recruit_content', 'recruit_btn_text', 'dow_center_agreement'], 'string'],
  745. ['goods_ids', 'safe'],
  746. [['buy_store_num', 'finish_order_num','template_store'], 'safe'],
  747. ],
  748. 'mode' => [
  749. [['is_enable_mode'], 'required'],
  750. ['is_enable_mode', 'integer'],
  751. [['Distribution', 'Agent', 'Boss', 'Area','boss_settings', 'DoubleCopy','Rebate'], 'safe']
  752. ],
  753. 'decoration' => [
  754. [['custom_goods_style','default_goods_style','custom_store_style','default_store_style','default_store_cate_style', 'store_category_switch'], 'integer'],
  755. [['near_shop_title'],'string']
  756. ],
  757. 'goodsStore' => [
  758. [['min_price','max_price','is_limit_max_price', 'is_hidden_goods_store'], 'safe'],
  759. [['express_title_arr'],'safe']
  760. ],
  761. 'store' => [
  762. [['store_h5_login_url'], 'safe'], [['service_fee_ratio', 'member_status', 'is_distribution', 'is_agent','preferential_undertaking'], 'required'],
  763. ],
  764. 'finance' => [
  765. ['freeze_is_enable', 'integer'],
  766. ['finance_name', 'string'],
  767. [['balance_cash_type','balance_cash_service_fee','balance_cash_service_fee_limit','balance_cash_service_fee_month','balance_cash_service_fee_diff','balance_cash_service_fee_month'],'safe'],
  768. ],
  769. 'payment' => [
  770. [['payment_is_enable','score_pay_setting','score_pay','score_pay_password_status','score_open_type'], 'integer'],
  771. [['store_limit_protocol'], 'string'],
  772. [['payment_type', 'pay_after_link','score_deduction'],'safe'],
  773. ],
  774. 'tips' => [
  775. [['bank_account_tips', 'link_tips'],'string'],
  776. ],
  777. 'advertising' => [
  778. [['is_open','type'],'integer'],
  779. [['pic', 'url'],'string'],
  780. ],
  781. 'rating_setting' => [
  782. [['total_score','environment_score','service_score','staff_score'],'integer'],
  783. ],
  784. 'scoreGive' => [
  785. [['score_give_setting', 'store_limit_stores'], 'safe'],
  786. [['score_give_is_store_alone', 'store_limit_type'], 'integer'],
  787. [['store_limit_protocol'], 'string']
  788. ],
  789. 'sms_setting' => [
  790. [['is_pay_remind', 'pay_template_id', 'pay_template_variable'], 'safe'],
  791. [['is_pay_remind', 'is_alert_expire', 'expire_day'], 'integer'],
  792. [['pay_template_id', 'pay_template_variable', 'expire_template_id', 'expire_template_variable'], 'string']
  793. ],
  794. 'notice' => [
  795. [['notice_wechat'], 'safe'],
  796. ]
  797. ];
  798. $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]);
  799. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  800. if ('basic' == $group) {
  801. // if(isset($post['basic']['recommend_nums'])){
  802. // $store_goods= StoreGoods::find()
  803. // ->select("count(*) counts,store_id")
  804. // ->where(['mall_id'=>$this->mall_id,'status'=>StatusEnum::ENABLED,'is_recommend'=>1])
  805. // ->groupBy('store_id')->orderBy('counts desc')->asArray()->one();
  806. // if(!empty($store_goods['counts'])&&$post['basic']['recommend_nums']<$store_goods['counts']){
  807. // return $this->error('允许推荐商品数量不能低于'.$store_goods['counts']);
  808. // }
  809. // }
  810. $post[$group]['o2o_url'] = trim($post[$group]['o2o_url']);
  811. if (!empty($post[$group]['payment_settle'])) {
  812. foreach($post[$group]['payment_settle_info'] as $key => $item){
  813. if(!in_array($item['type'],$post[$group]['payment_settle'])){
  814. unset($post[$group]['payment_settle_info'][$key]);
  815. }
  816. }
  817. }else{
  818. $post[$group]['payment_settle_info'] = [];
  819. }
  820. unset($post[$group]['payment_settle']);
  821. if ($post[$group]['service_fee'] == 1 && $post[$group]['service_fee_type'] == 1) {
  822. if ($post[$group]['min_platform_ratio'] > $post[$group]['max_platform_ratio']) {
  823. return $this->error('服务费最高比例不能小于最低比例');
  824. }
  825. }
  826. } elseif ('enter' == $group) {
  827. if (empty($post[$group]['goods_ids'])) {
  828. $post[$group]['goods_ids'] = '';
  829. } else {
  830. $post[$group]['goods_ids'] = json_encode($post[$group]['goods_ids']);
  831. }
  832. if (empty($post[$group]['template_store'])) {
  833. $post[$group]['template_store'] = '';
  834. } else {
  835. $post[$group]['template_store'] = json_encode($post[$group]['template_store']);
  836. }
  837. }elseif ('goodsStore' == $group) {
  838. if($post['goodsStore']['is_limit_max_price']=='false'){
  839. if($post['goodsStore']['min_price']>$post['goodsStore']['max_price']){
  840. return $this->error('最低价格不能大于最高价格');
  841. }
  842. }
  843. }elseif ('cashier' == $group) {
  844. if (!empty($post[$group]['collect_reward'])) {
  845. foreach($post[$group]['collect_reward_info'] as $key => $item){
  846. if(in_array($item['type'],$post[$group]['collect_reward'])){
  847. unset($post[$group]['collect_reward_info'][$key]['name']);
  848. }else{
  849. unset($post[$group]['collect_reward_info'][$key]);
  850. }
  851. }
  852. }else{
  853. $post[$group]['collect_reward_info'] = [];
  854. }
  855. unset($post[$group]['collect_reward']);
  856. if (!empty($post[$group]['payment_reward'])) {
  857. foreach($post[$group]['payment_reward_info'] as $key => $item){
  858. if(in_array($item['type'],$post[$group]['payment_reward'])){
  859. unset($post[$group]['payment_reward_info'][$key]['name']);
  860. }else{
  861. unset($post[$group]['payment_reward_info'][$key]);
  862. }
  863. }
  864. }else{
  865. $post[$group]['payment_reward_info'] = [];
  866. }
  867. unset($post[$group]['payment_reward']);
  868. if (!empty($post[$group]['cashier_amount'])) {
  869. foreach($post[$group]['cashier_amount_info'] as $key => $item){
  870. if(!in_array($item['type'],$post[$group]['cashier_amount'])){
  871. unset($post[$group]['cashier_amount_info'][$key]);
  872. }
  873. }
  874. }else{
  875. $post[$group]['cashier_amount_info'] = [];
  876. }
  877. unset($post[$group]['cashier_amount']);
  878. $basic = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
  879. //需要收取服务费
  880. if (!empty($basic['service_fee']) && !empty($post[$group]['service_fee_ratio'])) {
  881. //收银台服务费是否在基础设置的服务费区间
  882. if ($post[$group]['service_fee_ratio'] > $basic['max_platform_ratio'] || $post[$group]['service_fee_ratio'] < $basic['min_platform_ratio']) {
  883. return $this->error('只能设置在平台服务费比例区间内的比例当前平台服务费比例:' . $basic['min_platform_ratio'] . '%~' . $basic['max_platform_ratio'] . '%');
  884. }
  885. }
  886. }elseif ('finance' == $group) {
  887. if (empty($post[$group]['balance_cash_type'])) {
  888. $post[$group]['balance_cash_type'] = '';
  889. } else {
  890. $post[$group]['balance_cash_type'] = json_encode($post[$group]['balance_cash_type']);
  891. }
  892. }elseif ('payment' == $group) {
  893. if (empty($post[$group]['payment_type'])) {
  894. $post[$group]['payment_type'] = '';
  895. } else {
  896. $post[$group]['payment_type'] = json_encode($post[$group]['payment_type']);
  897. }
  898. if (!empty($post[$group]['pay_after_link'])) {
  899. $post[$group]['pay_after_link'] = json_encode($post[$group]['pay_after_link']);
  900. }
  901. empty($post[$group]['score_deduction']['store_limit_stores_deduction']) && $post[$group]['score_deduction']['store_limit_stores_deduction'] = [];
  902. if(isset($post[$group]['score_deduction']['store_limit_stores'])) unset($post[$group]['score_deduction']['store_limit_stores']);
  903. }elseif ('tips' == $group) {
  904. }elseif ('scoreGive' == $group) {
  905. if(empty($post[$group]['score_give_setting']['give_num'])){
  906. $post[$group]['score_give_setting']['give_num'] = 0;
  907. }
  908. empty($post[$group]['store_limit_stores']) && $post[$group]['store_limit_stores'] = [];
  909. }elseif ('rating_setting' == $group) {
  910. if (empty($post[$group]['total_score']) && empty($post[$group]['environment_score']) && empty($post[$group]['service_score']) && empty($post[$group]['staff_score'])) {
  911. return $this->error('请设置评分设置');
  912. }
  913. } elseif ('sms_setting' == $group) {
  914. if ($post[$group]['is_pay_remind'] && (empty($post[$group]['pay_template_id'] || empty($post[$group]['pay_template_variable'])))) {
  915. return $this->error('请完善短信设置');
  916. }
  917. }
  918. \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, $post);
  919. if ('basic' == $group && $post[$group]['service_fee_type']) {
  920. //收银设置服务费
  921. $cashier_service_fee_ratio = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'cashier.service_fee_ratio');
  922. if ($cashier_service_fee_ratio > $post[$group]['max_platform_ratio'] || $cashier_service_fee_ratio < $post[$group]['min_platform_ratio']) {
  923. \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, ['cashier' => [
  924. 'service_fee_ratio' => $post[$group]['max_platform_ratio']
  925. ]]);
  926. }
  927. //服务费是区间的时候 要处理 O2O的服务费独立设置
  928. \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [
  929. 'mall_id' => $this->mall_id,
  930. 'max_platform_ratio' => $post[$group]['max_platform_ratio'],
  931. 'min_platform_ratio' => $post[$group]['min_platform_ratio'],
  932. ], StoreGoodsExtra::class, 'updateServiceFeeSetting');
  933. \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [
  934. 'mall_id' => $this->mall_id,
  935. 'max_platform_ratio' => $post[$group]['max_platform_ratio'],
  936. 'min_platform_ratio' => $post[$group]['min_platform_ratio'],
  937. ], StoreSettings::class, 'updateServiceFeeSetting');
  938. }
  939. return $this->success('保存成功');
  940. }
  941. }
  942. public function actionSendSms()
  943. {
  944. try {
  945. $post = \Yii::$app->request->post();
  946. // $params = \Yii::$app->request->post();
  947. // if (empty($params['mobile'])) return $this->error('请输入手机号码');
  948. $smsConfig = MallSetting::getConfByGroup($this->mall_id, 'notice_sms', true);
  949. switch ($smsConfig['platform']['value']) {
  950. case 'aliyun'://阿里云配置
  951. $mobile = $smsConfig['mobile']['value'];
  952. break;
  953. case 'qcloud'://阿里云配置
  954. $mobile = $smsConfig['qcloud_mobile']['value'];
  955. break;
  956. case 'submail'://阿里云配置
  957. $mobile = $smsConfig['submail_mobile']['value'];
  958. break;
  959. }
  960. if (!$mobile) {
  961. return $this->error('请完善平台设置-短信设置-手机号');
  962. }
  963. $SmsConfig = new Sms($this->mall_id);
  964. switch ($post['type']) {
  965. case 3:
  966. // $SmsConfig = new SmsConfig($this->mall_id);
  967. $easy_sms = $SmsConfig->easySms;
  968. $message = new PayRemindMessage($this->mall_id, 'order_123', '自提');
  969. break;
  970. case 4:
  971. // $SmsConfig = new Sms($this->mall_id);
  972. $easy_sms = $SmsConfig->easySms;
  973. $message = new ShopExpireMessage($this->mall_id, '6', '测试门店');
  974. break;
  975. }
  976. $easy_sms->send($mobile, $message);
  977. return $this->success('发送成功');
  978. } catch (\Exception $e) {
  979. return $this->error($e->getMessage());
  980. }
  981. }
  982. public function getCashierEnable($init_enable_arr, $addons_currency, $cashier, $addon_key)
  983. {
  984. $addons_distribution_enable_arr = [];
  985. foreach ($addons_currency as $v) {
  986. $addons_distribution_enable_arr[$v] = $v;
  987. }
  988. $enable_keys = [];
  989. $keys = [];
  990. $ratio = [];
  991. $remaining_ratio = [];
  992. $loop_enble_arr = array_merge($init_enable_arr, $addons_distribution_enable_arr);
  993. foreach ($loop_enble_arr as $k => $item) {
  994. $ratio_index = $addon_key . '_' . $k . '_remaining_ratio';
  995. $ratio[] = $ratio_index;
  996. $remaining_ratio[$ratio_index] = $cashier[$ratio_index] ?? 0;
  997. if (empty($item)) {
  998. $keys[] = 'is_' . $addon_key;
  999. $enable_keys['is_' . $addon_key] = 0;
  1000. } else {
  1001. $keys[] = 'is_' . $addon_key . '_' . $item;
  1002. $enable_keys['is_' . $addon_key . '_' . $item] = 0;
  1003. }
  1004. }
  1005. foreach (array_merge($enable_keys, $remaining_ratio) as $k => $v) {
  1006. if (!isset($cashier[$k])) {
  1007. $cashier[$k] = $v;
  1008. }
  1009. }
  1010. return compact('cashier', 'keys', 'ratio');
  1011. }
  1012. public function getCashierAgentData($agent_levels, $currencys, $cashier)
  1013. {
  1014. $data = [];
  1015. $currency_keys = [];
  1016. foreach ($currencys as $currency) {
  1017. $currency_key = 'agent_' . $currency;
  1018. $currency_keys[] = $currency_key;
  1019. if (!empty($cashier[$currency_key])) {
  1020. $currency_settings = json_decode($cashier[$currency_key], true);
  1021. } else {
  1022. $currency_settings = [
  1023. 'team_rewards' => [],
  1024. 'equal_rewards' => [],
  1025. 'over_rewards' => [],
  1026. ];
  1027. }
  1028. foreach ($currency_settings as $reward_name => $setting) {
  1029. foreach ($setting as $val) {
  1030. $currency_settings[$reward_name][$val['level']] = $val;
  1031. }
  1032. }
  1033. $ag_levels = array_column($currency_settings['team_rewards'], 'level');
  1034. $level_settings = [];
  1035. foreach ($agent_levels as $alevel) {
  1036. if (!in_array($alevel['level'], $ag_levels)) {
  1037. $arr = $alevel;
  1038. $arr['commission_rate'] = 0;
  1039. $level_settings['team_rewards'][] = $arr;
  1040. $level_settings['equal_rewards'][] = $arr;
  1041. $level_settings['over_rewards'][] = $arr;
  1042. } else {
  1043. $arr = [
  1044. 'level' => $alevel['level'],
  1045. 'level_name' => $alevel['level_name'],
  1046. 'commission_rate' => $currency_settings['team_rewards'][$alevel['level']]['commission_rate'] ?? 0,
  1047. ];
  1048. $level_settings['team_rewards'][] = $arr;
  1049. $arr['commission_rate'] = $currency_settings['equal_rewards'][$alevel['level']]['commission_rate'] ?? 0;
  1050. $level_settings['equal_rewards'][] = $arr;
  1051. $arr['commission_rate'] = $currency_settings['over_rewards'][$alevel['level']]['commission_rate'] ?? 0;
  1052. $level_settings['over_rewards'][] = $arr;
  1053. }
  1054. }
  1055. $data[$currency_key] = $level_settings;
  1056. }
  1057. return compact('data', 'currency_keys');
  1058. }
  1059. /**
  1060. * @Description: 处理插件模式数据
  1061. * @Author: qi
  1062. * @DateTime 2022-11-10 09:59:45
  1063. * @param string $init_data
  1064. * @param array $level_data
  1065. * @param array $currencys
  1066. * @param string $addons_name
  1067. * @param integer $level
  1068. * @param array $append_fields
  1069. * @param array $ext
  1070. * @return array
  1071. */
  1072. protected function getAddonsData($init_data, $level_data, $currencys, $addons_name, $level = 1, $append_fields = [], $ext = [])
  1073. {
  1074. $settings = [];
  1075. $container_arr = [];
  1076. if (!empty($init_data)) {
  1077. // 已存储的数据
  1078. $settings = json_decode($init_data, true);
  1079. foreach ($currencys as $currency) {
  1080. if (!isset($settings[$currency])) continue;
  1081. $currency_detail = $level == 1 ? $settings[$currency]['detail'] : $settings[$currency];
  1082. if(!empty($currency_detail)){
  1083. foreach ($currency_detail as $detail) {
  1084. // 币种对应的权重数据
  1085. if (!isset($detail['level'])) {
  1086. continue;
  1087. }
  1088. $container_arr[$currency . '_' . $detail['level']] = $detail;
  1089. }
  1090. }
  1091. }
  1092. }else{
  1093. foreach ($currencys as $currency) {
  1094. $settings[$currency]['is_enable'] = 0;
  1095. if(!empty($ext)){
  1096. foreach($ext as $key => $val){
  1097. $settings[$currency][$key] = $val;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. $method_name = 'get' . $addons_name . 'InitData';
  1103. foreach ($currencys as $item) {
  1104. $level_settings = [];
  1105. // 不存在该权重数据就初始化,存在该权重则更新权重名称
  1106. foreach ($level_data as $dlevel) {
  1107. if (!isset($container_arr[$item . '_' . $dlevel['level']])) {
  1108. $arr = [
  1109. 'level' => $dlevel['level'],
  1110. 'level_name' => $dlevel['level_name'],
  1111. ];
  1112. $arr = array_merge($arr, $this->$method_name());
  1113. $level_settings[] = $arr;
  1114. } else {
  1115. // 更新对应权重名称
  1116. $container_arr[$item . '_' . $dlevel['level']]['level_name'] = $dlevel['level_name'];
  1117. $level_settings[] = $container_arr[$item . '_' . $dlevel['level']];
  1118. }
  1119. }
  1120. if (!empty($level_settings)) {
  1121. if ($level == 1) {
  1122. $settings[$item]['detail'] = $level_settings;
  1123. } else {
  1124. $settings[$item] = $level_settings;
  1125. }
  1126. }
  1127. }
  1128. foreach ($currencys as $v) {
  1129. foreach ($append_fields as $field) {
  1130. if (isset($settings[$v . '_' . $field])) continue;
  1131. $settings[$v . '_' . $field] = 0;
  1132. }
  1133. }
  1134. unset($container_arr);
  1135. return $settings;
  1136. }
  1137. /**
  1138. * 获取推三返一数据
  1139. * 作者:zengfanhua
  1140. * 创建时间:2024/07/14 02:11:21
  1141. */
  1142. protected function getRebateData($init_data)
  1143. {
  1144. $settings = [];
  1145. if (!empty($init_data)) {
  1146. // 已存储的数据
  1147. $settings = json_decode($init_data, true);
  1148. return $settings;
  1149. }
  1150. else
  1151. {
  1152. $detail=$this->getRebateInitData();
  1153. return ['is_enable'=>0,'detail'=>$detail];
  1154. }
  1155. }
  1156. protected function getDistributionInitData()
  1157. {
  1158. return [
  1159. 'first_prize' => 0,
  1160. 'second_prize' => 0,
  1161. 'third_prize' => 0,
  1162. 'is_percent' => 0,
  1163. 'remaining_ratio' => 0
  1164. ];
  1165. }
  1166. protected function getAgentInitData()
  1167. {
  1168. return [
  1169. 'agent_team_prize' => 0,
  1170. 'agent_equal_prize' => 0,
  1171. 'agent_over_prize' => 0,
  1172. 'agent_extra_prize' => 0,
  1173. 'remaining_ratio' => 0,
  1174. 'is_percent_over' => 0,
  1175. 'is_percent_equal' => 0,
  1176. 'is_percent_team' => 0,
  1177. 'is_percent_extra' => 0
  1178. ];
  1179. }
  1180. protected function getAreaInitData()
  1181. {
  1182. return [
  1183. 'prize' => 0,
  1184. 'equal_prize' => 0,
  1185. ];
  1186. }
  1187. protected function getDoubleCopyInitData()
  1188. {
  1189. return [
  1190. 'first_prize' => 0,
  1191. 'indirect_prize' => 0,
  1192. 'second_prize' => 0,
  1193. 'equal_prize' => 0,
  1194. 'allowance_price' => 0,
  1195. ];
  1196. }
  1197. protected function getRebateInitData()
  1198. {
  1199. return [
  1200. 'initiate_type' => 0,
  1201. 'initiate_level' => [],
  1202. 'consume_type' => 0,
  1203. 'consume_level' => [],
  1204. 'reward_type' => 1,
  1205. 'reward_info' => [],
  1206. 'is_repeat' => 0,
  1207. 'join_type' => 0,
  1208. 'repeat_setting' => 0,
  1209. 'agent_limit_num' => 0,
  1210. ];
  1211. }
  1212. protected function cashierDistributionData($distribution_levels, $cashier, $currencys = [])
  1213. {
  1214. // $data = [];
  1215. // $level_arr = [];
  1216. // switch ($type) {
  1217. // case 'score':
  1218. // if (!empty($cashier['distribution_settings_score'])) {
  1219. // $distribution_settings_score = json_decode($cashier['distribution_settings_score'], true);
  1220. // $level_arr = array_column($distribution_settings_score, 'level');
  1221. // $data = $distribution_settings_score;
  1222. // }
  1223. // break;
  1224. // case 'commission':
  1225. // if (!empty($cashier['distribution_settings'])) {
  1226. // $distribution_settings = json_decode($cashier['distribution_settings'], true);
  1227. // $level_arr = array_column($distribution_settings, 'level');
  1228. // $data = $distribution_settings;
  1229. // }
  1230. // break;
  1231. // }
  1232. // foreach ($distribution_levels as $val) {
  1233. // if (!in_array($val['level'], $level_arr)) {
  1234. // $data[] = [
  1235. // 'level' => $val['level'],
  1236. // 'level_name' => $val['level_name'],
  1237. // 'commission_rate' => [0, 0]
  1238. // ];
  1239. // }
  1240. // if (isset($data[$val['level']])) {
  1241. // $data[$val['level']]['level_name'] = $val['level_name'];
  1242. // }
  1243. // }
  1244. // return $data;
  1245. $response = [];
  1246. $distribution_currency_key = [];
  1247. $now_level_arr = (array)array_column($distribution_levels, 'level');
  1248. foreach ($currencys as $currency) {
  1249. $level_arr = [];
  1250. $currency_key = 'distribution_' . $currency;
  1251. $distribution_currency_key[] = $currency_key;
  1252. if (!empty($cashier[$currency_key])) {
  1253. $settings = json_decode($cashier[$currency_key], true);
  1254. $level_arr = array_column($settings, 'level');
  1255. $response[$currency_key] = $settings;
  1256. }
  1257. if(isset($response[$currency_key]) && !empty($response[$currency_key])){
  1258. foreach($response[$currency_key] as $key => $value){
  1259. if(!in_array($value['level'], $now_level_arr)){
  1260. unset($response[$currency_key][$key]);
  1261. }
  1262. }
  1263. $response[$currency_key] = array_values($response[$currency_key]);
  1264. }
  1265. foreach ($distribution_levels as $val) {
  1266. if (!in_array($val['level'], $level_arr)) {
  1267. $response[$currency_key][] = [
  1268. 'level' => $val['level'],
  1269. 'level_name' => $val['level_name'],
  1270. 'commission_rate' => [0, 0],
  1271. ];
  1272. }
  1273. if (isset($response[$currency_key][$val['level']])) {
  1274. $response[$currency_key][$val['level']]['level_name'] = $val['level_name'];
  1275. }
  1276. }
  1277. }
  1278. return compact('response', 'distribution_currency_key');
  1279. }
  1280. protected function getBossSetting($level=[],$boss_levels=[])
  1281. {
  1282. $level_arr=[];
  1283. foreach ($level as $k => $v) {
  1284. $level_arr[$k]['level']=$v['level'];
  1285. $level_arr[$k]['level_name']=$v['level_name'];
  1286. if(count($boss_levels)==0){
  1287. $level_arr[$k]['prize']=0;
  1288. $level_arr[$k]['extra_prize']=0;
  1289. }else{
  1290. foreach ($boss_levels as $val) {
  1291. $i=1;
  1292. if($v['level']==$val['level']){
  1293. $level_arr[$k]['prize']=$val['prize'];
  1294. $level_arr[$k]['extra_prize']=$val['extra_prize'];
  1295. }else{
  1296. $i++;
  1297. }
  1298. if($i>count($level)){
  1299. $level_arr[$k]['prize']=0;
  1300. $level_arr[$k]['extra_prize']=0;
  1301. }
  1302. }
  1303. }
  1304. }
  1305. return $level_arr;
  1306. }
  1307. /**
  1308. * 让利列表
  1309. * @return mixed|string|null
  1310. */
  1311. public function actionReduceProfit()
  1312. {
  1313. if (\Yii::$app->request->isAjax) {
  1314. if (\Yii::$app->request->isPost) { // 审核
  1315. $setting = $this->request->post();
  1316. // 数据校验
  1317. $res = \Yii::$app->services->validate->validate($setting, [
  1318. [['id', 'status', 'remark'], 'required'],
  1319. [['id', 'status'], 'integer'],
  1320. [['remark'], 'string']
  1321. ], [
  1322. 'id' => '审核对象',
  1323. ]);
  1324. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  1325. try {
  1326. $ret = (new MerchantReduceProfitService())->audit($this->mall_id, $setting['id'],
  1327. $this->admin->id, $setting['status'], $setting['remark']);
  1328. return is_string($ret) ? $this->error($ret) : $this->success('操作成功');
  1329. } catch (\Exception $e) {
  1330. return $this->error($e->getMessage());
  1331. }
  1332. } else {
  1333. $params = $this->request->post();
  1334. // 数据校验
  1335. $res = \Yii::$app->services->validate->validate($params, [
  1336. [['store_keyword', 'date_start', 'date_end'], 'string'],
  1337. [['rate'], 'number'],
  1338. [['status', 'page', 'limit', 'cate'], 'integer'],
  1339. ]);
  1340. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  1341. $ret = (new MerchantReduceProfitService())->page($this->mall_id, $params);
  1342. if (is_array($ret)) {
  1343. $cate_list = StoreCate::find()
  1344. ->select('id,name')
  1345. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  1346. ->asArray()
  1347. ->all();
  1348. $ret['cate_list'] = $cate_list;
  1349. }
  1350. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  1351. }
  1352. }
  1353. return $this->render($this->action->id);
  1354. }
  1355. public function actionScoreStoreApply()
  1356. {
  1357. $search = $this->request->get();
  1358. // 数据校验
  1359. $res = \Yii::$app->services->validate->validate($search, [
  1360. [['store_info', 'store_cate'], 'string'],
  1361. [['check_status', 'score_method', 'page', 'limit'], 'integer'],
  1362. [['date'], 'safe']
  1363. ]);
  1364. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  1365. $where = [['mall_id' => $this->mall_id], ['score_method' => $search['score_method'] ?? 1], ['<>', 'status', StatusEnum::DELETE]];
  1366. isset($search['check_status']) && $where[] = ['check_status' => $search['check_status']];
  1367. if (!empty($search['store_info'])) {
  1368. $store_ids = Store::find()->where(['or',
  1369. ['id' => trim($search['store_info'])],
  1370. ['like', 'store_name', trim($search['store_info'])],
  1371. ['like', 'shop_owner', trim($search['store_info'])]
  1372. ])->select('id')->column();
  1373. $where[] = ['store_id' => $store_ids];
  1374. }
  1375. if (!empty($search['date'])) {
  1376. $where[] = ['or', ['between', 'created_at', strtotime($search['date'][0]), strtotime($search['date'][1])], ['between', 'check_time', strtotime($search['date'][0]), strtotime($search['date'][1])]];
  1377. }
  1378. if (!empty($search['store_cate'])) {
  1379. $cate_ids = StoreCate::find()->where(['like', 'name', trim($search['store_cate'])])->select('id')->column();
  1380. $where[] = ['store_c_id' => $cate_ids];
  1381. }
  1382. $result = StoreScoreStoreApply::listPage(['where' => $where, 'page' => $search['page'], 'limit' => $search['limit'], 'with' => ['store' => function ($query) {
  1383. $query->select('id, c_id, store_name, logo_img, shop_owner, shop_mobile, address, ')->with(['cate']);
  1384. }], 'order' => 'created_at desc']);
  1385. if (!empty($result['list'])) {
  1386. $user_ids_arr = array_unique(array_column($result['list'], 'store_user_id'));
  1387. $user_list = \common\models\user\User::lists(['where' => [['id' => $user_ids_arr]], 'index' => 'id', 'select' => 'id, nickname, mobile, avatar_url']);
  1388. foreach ($result['list'] as &$item) {
  1389. $item['user'] = isset($user_list[$item['store_user_id']]) ? $user_list[$item['store_user_id']] : null;
  1390. }
  1391. }
  1392. $result['list'] = $result['list'] ?? [];
  1393. $result['status_map'] = [
  1394. '-1' => '未通过',
  1395. '0' => '待审核',
  1396. '1' => '已通过'
  1397. ];
  1398. return $this->success('获取成功', $result);
  1399. }
  1400. public function actionScoreStoreCheck()
  1401. {
  1402. $trans = \Yii::$app->db->beginTransaction();
  1403. try {
  1404. $request = \Yii::$app->request;
  1405. if (!$request->isPost) throw new \Exception("非法请求");
  1406. $data = $request->post();
  1407. $res = \Yii::$app->services->validate->validate($data, [
  1408. [['id', 'check_status'], 'required'],
  1409. [['id', 'check_status'], 'integer'],
  1410. [['reason'], 'string']
  1411. ]);
  1412. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  1413. $model = StoreScoreStoreApply::findOne(['mall_id' => $this->mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]);
  1414. if (empty($model)) throw new \Exception("当前数据不存在,无法执行修改状态");
  1415. $data['check_time'] = time();
  1416. $model->load($data, '');
  1417. if (!$model->save()) throw new \Exception("修改状态失败,原因:". $model->getErrorMessage());
  1418. if ($data['check_status'] == 1) {
  1419. // 添加门店限制
  1420. if ($model->score_method == 2) {
  1421. $score_deduction_config = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'payment.score_deduction', true);
  1422. $score_deduction_config = json_decode($score_deduction_config, true);
  1423. $score_deduction_config['store_limit_stores_deduction'] = $score_deduction_config['store_limit_stores_deduction'] ?? [];
  1424. $store_limit_stores_deduction = &$score_deduction_config['store_limit_stores_deduction'];
  1425. if (!isset($store_limit_stores_deduction[$model->store_id])) {
  1426. $store_limit_stores_deduction[$model->store_id] = "";
  1427. };
  1428. \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, ['payment' => [
  1429. 'score_deduction' => $score_deduction_config
  1430. ]]);
  1431. $store_limit_stores = array_keys($store_limit_stores_deduction);
  1432. }else {
  1433. $store_limit_stores = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'scoreGive.store_limit_stores', true);
  1434. $store_limit_stores = !empty($store_limit_stores) ? json_decode($store_limit_stores, true) : [];
  1435. if (!in_array($model->store_id, $store_limit_stores)){
  1436. array_unshift($store_limit_stores, (string)$model->store_id);
  1437. };
  1438. \Yii::$app->services->setting->addons->set($this->mall_id, StoreEnum::ADDONS_NAME, ['scoreGive' => [
  1439. 'store_limit_stores' => $store_limit_stores
  1440. ]]);
  1441. }
  1442. }
  1443. $trans->commit();
  1444. return $this->success('修改状态成功', $store_limit_stores ?? []);
  1445. }catch (\Exception $e){
  1446. $trans->rollBack();
  1447. return $this->error($e->getMessage());
  1448. }
  1449. }
  1450. public function actionStoreServiceRatioLog()
  1451. {
  1452. try {
  1453. if (\Yii::$app->request->isAjax) {
  1454. $get = $this->request->get();
  1455. $page = \Yii::$app->request->get('page');
  1456. $limit = \Yii::$app->request->get('limit');
  1457. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
  1458. if ($get['keyword']) {
  1459. $store_list = Store::lists([
  1460. 'where' => [
  1461. [
  1462. 'OR',
  1463. ['like', 'store_name', $get['keyword']],
  1464. ['like', 'shop_mobile', $get['keyword']],
  1465. // ['=', 'id', $get['shop_mobile']],
  1466. ],
  1467. ['=', 'mall_id', $this->mall_id]
  1468. ],
  1469. 'select' => 'id'
  1470. ]);
  1471. if ($store_list) {
  1472. $store_ids = array_column($store_list, 'id');
  1473. $wheres[] = ['in', 'store_id', $store_ids];
  1474. }
  1475. }
  1476. if ($get['start_time'] && $get['end_time']) {
  1477. //搜索订单支付时间
  1478. $start_time = strtotime($get['start_time']);
  1479. $end_time = strtotime($get['end_time']);
  1480. $wheres[] = ['between', 'created_at', $start_time, $end_time];
  1481. }
  1482. $with = ['store'];
  1483. $search = [
  1484. 'where' => $wheres,
  1485. 'page' => $page,
  1486. 'order' => 'id desc',
  1487. 'limit' => $limit,
  1488. 'with' => $with,
  1489. ];
  1490. $list = StoreServiceRatioLog::listPage($search);
  1491. return $this->success('success', $list);
  1492. }
  1493. // return $this->render('/store-service-ratio-log/store-service-ratio-log');
  1494. return $this->render($this->action->id);
  1495. } catch (\Exception $e) {
  1496. return $this->error($e->getMessage());
  1497. }
  1498. }
  1499. /**
  1500. * 获取微信消息模版ID
  1501. * @return mixed|void|null
  1502. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  1503. * @throws \GuzzleHttp\Exception\GuzzleException
  1504. */
  1505. public function actionGetWechatNotice()
  1506. {
  1507. if (\Yii::$app->request->isAjax && \Yii::$app->request->post()) {
  1508. $params = \Yii::$app->request->post();
  1509. $res = \Yii::$app->services->validate->validate($params, [
  1510. [['key'], 'required'], [['key'], 'string']
  1511. ]);
  1512. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  1513. // 根据key获取对应的微信消息模板ID
  1514. try {
  1515. $notice_wechat_config = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'notice');
  1516. $notice_wechat = empty($notice_wechat_config['notice_wechat']) ? [] : json_decode($notice_wechat_config['notice_wechat'],true);
  1517. $notice_wechat_template_message_value = $notice_wechat['template_message'] ?? [];
  1518. $tempid = '';
  1519. if(!empty($notice_wechat_template_message_value)){
  1520. if(!empty($notice_wechat_template_message_value[$params['key']]['tempid'])){
  1521. $tempid = $notice_wechat_template_message_value[$params['key']]['tempid'];
  1522. }
  1523. }
  1524. $template = new WechatTemplate($this->mall_id);
  1525. $response = $template->addTemplate($params['key'],$tempid);
  1526. if ($response['errcode'] != 0) return $this->error('获取失败:' . $response['errmsg']);
  1527. return $this->success('获取模板成功,记得左下角按钮进行保存哦', $response['template_id']);
  1528. } catch (\Exception $e) {
  1529. return $this->error('获取失败:' . $e->getMessage());
  1530. }
  1531. }
  1532. }
  1533. }