ShareCustomForm.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1;
  8. use yii\base\Model;
  9. class ShareCustomForm extends Model
  10. {
  11. public $store_id;
  12. public $data;
  13. public $store;
  14. public function rules()
  15. {
  16. return [
  17. [['data'], 'required'],
  18. [['data'], 'string'],
  19. ];
  20. }
  21. public function saveData()
  22. {
  23. if (!$this->validate()) {
  24. return $this->errorResponse;
  25. }
  26. Option::set('share_custom_data', $this->data, $this->store_id);
  27. return [
  28. 'code' => 0,
  29. 'msg' => '保存成功',
  30. ];
  31. }
  32. public function getData()
  33. {
  34. // TODO: 默认数据
  35. // $data = Option::get('share_custom_data', $this->store_id);
  36. $default_data = $this->getDefaultData();
  37. if (!$data) {
  38. $data = $default_data;
  39. } else {
  40. $data = json_decode($data, true);
  41. $data = $this->checkData($data, $default_data);
  42. }
  43. return [
  44. 'code' => 0,
  45. 'data' => $data,
  46. ];
  47. }
  48. //检查是否有新增的值
  49. public function checkData($list = array(), $default_list = array())
  50. {
  51. $ignore = ['menu'];
  52. $new_list = [];
  53. foreach ($default_list as $index => $value) {
  54. if (isset($list[$index])) {
  55. if (is_array($value) && !in_array($index, $ignore)) {
  56. $new_list[$index] = $this->checkData($list[$index], $value);
  57. } else {
  58. $new_list[$index] = $list[$index];
  59. }
  60. } else {
  61. $new_list[$index] = $value;
  62. }
  63. }
  64. return $new_list;
  65. }
  66. public function getDefaultData()
  67. {
  68. return [
  69. 'menus' => [
  70. 'money'=>[
  71. 'name' => '分销佣金',
  72. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/images/share-custom/img-share-price.png',
  73. 'open_type' => 'navigator',
  74. 'url' => '/user/share-money/share-money',
  75. 'tel' => '',
  76. ],
  77. 'order'=>[
  78. 'name' => '分销订单',
  79. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/images/share-custom/img-share-order.png',
  80. 'open_type' => 'navigator',
  81. 'url' => '/user/share-order/share-order',
  82. 'tel' => '',
  83. ],
  84. 'cash'=>[
  85. 'name' => '提现明细',
  86. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/images/share-custom/img-share-cash.png',
  87. 'open_type' => 'navigator',
  88. 'url' => '/pages/cash-detail/cash-detail',
  89. 'tel' => '',
  90. ],
  91. 'team'=>[
  92. 'name' => '我的团队',
  93. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/images/share-custom/img-share-team.png',
  94. 'open_type' => 'navigator',
  95. 'url' => '/user/share-team/share-team',
  96. 'tel' => '',
  97. ],
  98. 'qrcode'=>[
  99. 'name' => '推广二维码',
  100. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/images/share-custom/img-share-qrcode.png',
  101. 'open_type' => 'navigator',
  102. 'url' => '/user/share-qrcode/share-qrcode',
  103. 'tel' => '',
  104. ],
  105. ],
  106. 'words' => [
  107. 'can_be_presented'=>[
  108. 'name' => '可提现佣金',
  109. 'default' => '可提现佣金',
  110. ],
  111. 'already_presented'=>[
  112. 'name' => '已提现佣金',
  113. 'default' => '已提现佣金',
  114. ],
  115. 'parent_name'=>[
  116. 'name' => '推荐人',
  117. 'default' => '推荐人',
  118. ],
  119. 'pending_money'=>[
  120. 'name' => '待打款佣金',
  121. 'default' => '待打款佣金',
  122. ],
  123. 'cash'=>[
  124. 'name' => '提现',
  125. 'default' => '提现',
  126. ],
  127. 'user_instructions'=>[
  128. 'name' => '用户须知',
  129. 'default' => '用户须知',
  130. ],
  131. 'apply_cash'=>[
  132. 'name' => '我要提现',
  133. 'default' => '我要提现',
  134. ],
  135. 'cash_type'=>[
  136. 'name' => '提现方式',
  137. 'default' => '提现方式',
  138. ],
  139. 'cash_money'=>[
  140. 'name' => '提现金额',
  141. 'default' => '提现金额',
  142. ],
  143. 'order_money_un'=>[
  144. 'name' => '未结算佣金',
  145. 'default' => '未结算佣金',
  146. ],
  147. 'share_name'=>[
  148. 'name' => '分销商',
  149. 'default' => '分销商',
  150. ],
  151. ]
  152. ];
  153. }
  154. }