SettingForm.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace app\modules\admin\models\shareGroup;
  3. use app\models\CashExt;
  4. use app\models\Cat;
  5. use app\models\Goods;
  6. use app\models\GoodsCat;
  7. use app\models\Option;
  8. use yii\base\Model;
  9. class SettingForm extends Model
  10. {
  11. public $store_id;
  12. public $share_group_direct_profit;
  13. public $share_group_support_profit;
  14. public $share_group_auto_switch;
  15. public $share_group_commission_profit;
  16. public $share_group_balance_profit;
  17. public $share_group_other_accounts_switch;
  18. public $share_group_support_freeze_profit;
  19. public $support_group_price_send_type;
  20. public $pay_type;
  21. public $bank;
  22. public $lg;
  23. public $remaining_sum;
  24. public $cash_service_charge;
  25. public $min_money;
  26. public $cash_max_single_day;
  27. public $cash_max_day;
  28. public $goods_ids;
  29. public $cash_price_amount;
  30. public $cash_price_integral;
  31. public $cash_price_balance;
  32. public $cash_price_type;
  33. public $share_group_bg;
  34. public function rules()
  35. {
  36. return [
  37. [['store_id', 'share_group_auto_switch', 'share_group_other_accounts_switch', 'pay_type', 'bank', 'remaining_sum', 'support_group_price_send_type'], 'integer'],
  38. [['share_group_direct_profit', 'share_group_support_profit', 'share_group_commission_profit',
  39. 'share_group_balance_profit', 'share_group_support_freeze_profit', 'cash_service_charge',
  40. 'min_money', 'cash_max_single_day', 'cash_max_day', 'cash_price_amount', 'cash_price_integral', 'cash_price_balance'], 'number'],
  41. [['goods_ids', 'cash_price_type', 'share_group_bg'], 'string'],
  42. [['share_group_auto_switch', 'share_group_other_accounts_switch', 'bank', 'remaining_sum', 'lg'], 'in', 'range' => [0, 1]],
  43. [['pay_type'], 'in', 'range' => [0, 1, 2, 3]]
  44. ];
  45. }
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'store_id' => 'Store Id',
  50. 'share_group_direct_profit' => '直推佣金比例',
  51. 'share_group_support_profit' => '帮扶佣金比例',
  52. 'share_group_auto_switch' => '成团佣金自动复购开关',
  53. 'share_group_commission_profit' => '成团佣金奖励比例',
  54. 'share_group_balance_profit' => '成团余额奖励比例',
  55. 'share_group_other_accounts_switch' => '开始拼团区小号限制开关',
  56. 'share_group_support_freeze_profit' => '冻结帮扶佣金奖励比例',
  57. 'pay_type' => '提现方式【0微信 1支付宝 2微信&支付宝】',
  58. 'bank' => '是否开启银行卡提现',
  59. 'lg' => '是否开启灵工提现',
  60. 'remaining_sum' => '是否开启余额提现',
  61. 'cash_service_charge' => '提现手续费',
  62. 'min_money' => '最少提现金额',
  63. 'cash_max_single_day' => '每日提现上限',
  64. 'cash_max_day' => '平台提现上限',
  65. 'goods_ids' => '商品ID',
  66. 'share_group_bg' => '37拼购背景图'
  67. ];
  68. }
  69. public function settingIndex() {
  70. try {
  71. $store_id = $this->store_id;
  72. $data = [
  73. 'share_group_direct_profit' => 0,
  74. 'share_group_support_profit' => 0,
  75. 'share_group_auto_switch' => 0,
  76. 'share_group_commission_profit' => 0,
  77. 'share_group_balance_profit' => 0,
  78. 'share_group_other_accounts_switch' => 0,
  79. 'share_group_support_freeze_profit' => 0,
  80. 'pay_type' => '',
  81. 'bank' => 0,
  82. 'remaining_sum' => 0,
  83. 'lg' => 0,
  84. 'cash_service_charge' => 0,
  85. 'min_money' => 0,
  86. 'cash_max_single_day' => 0,
  87. 'cash_max_day' => 0,
  88. 'goods_ids' => '',
  89. 'support_group_price_send_type' => 0,//帮扶区直推佣金发放:0=原上级 1=新上级
  90. 'share_group_bg' => ''
  91. ];
  92. $share_group_setting = Option::get('share_group_setting', $store_id, 'share_group')['value'];
  93. $share_group_setting = json_decode($share_group_setting ?? '', true);
  94. if (empty($share_group_setting)) {
  95. $share_group_setting = $data;
  96. }
  97. if (!isset($share_group_setting['cash_price_type'])) {
  98. $share_group_setting = array_merge($share_group_setting, [
  99. 'cash_price_type' => '1',
  100. 'cash_price_amount' => 100,
  101. 'cash_price_integral' => 0,
  102. 'cash_price_balance' => 0,
  103. ]);
  104. }
  105. if (!isset($share_group_setting['support_group_price_send_type'])) {
  106. $share_group_setting['support_group_price_send_type'] = 0;
  107. }
  108. if (!isset($share_group_setting['lg'])) {
  109. $share_group_setting['lg'] = 0;
  110. }
  111. $share_group_setting['goods_info'] = [];
  112. $goods_ids = explode(',', $share_group_setting['goods_ids'] ?? '');
  113. if (!empty($goods_ids)) {
  114. $goods = Goods::find()->where(['id' => $goods_ids, 'is_delete' => 0, 'store_id' => $store_id])
  115. ->select('id, name, cover_pic, price, goods_num')->orderBy('id')->asArray()->all();
  116. $goods_ids = array_column($goods, 'id');
  117. $share_group_setting['goods_ids'] = implode(',', $goods_ids);
  118. foreach ($goods as &$item) {
  119. $goods_cat = GoodsCat::find()->alias('gc')
  120. ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id')
  121. ->where([ 'gc.goods_id' => $item['id'], 'c.is_delete' => 0, 'gc.is_delete' => 0, 'c.store_id' => $store_id])
  122. ->select(['c.name'])
  123. ->column();
  124. $item['cat'] = implode(' ', $goods_cat);
  125. }
  126. $share_group_setting['goods_info'] = $goods;
  127. }
  128. $share_group_setting['share_group_bg'] = $share_group_setting['share_group_bg'] ?? '';
  129. return [
  130. 'code' => 0,
  131. 'msg' => '获取成功',
  132. 'data' => $share_group_setting
  133. ];
  134. } catch (\Exception $e) {
  135. return [
  136. 'code' => 1,
  137. 'msg' => $e->getMessage()
  138. ];
  139. }
  140. }
  141. public function settingEdit() {
  142. try {
  143. $store_id = $this->store_id;
  144. if (!$this->validate()) {
  145. throw new \Exception($this->getErrorSummary(false)[0]);
  146. }
  147. $data = [
  148. 'share_group_direct_profit' => floatval($this->share_group_direct_profit),
  149. 'share_group_support_profit' => floatval($this->share_group_support_profit),
  150. 'share_group_auto_switch' => intval($this->share_group_auto_switch),
  151. 'share_group_commission_profit' => floatval($this->share_group_commission_profit),
  152. 'share_group_balance_profit' => floatval($this->share_group_balance_profit),
  153. 'share_group_other_accounts_switch' => intval($this->share_group_other_accounts_switch),
  154. 'share_group_support_freeze_profit' => floatval($this->share_group_support_freeze_profit),
  155. 'support_group_price_send_type' => intval($this->support_group_price_send_type),
  156. 'pay_type' => intval($this->pay_type),
  157. 'bank' => intval($this->bank),
  158. 'lg' => intval($this->lg),
  159. 'remaining_sum' => intval($this->remaining_sum),
  160. 'cash_service_charge' => floatval($this->cash_service_charge),
  161. 'min_money' => floatval($this->min_money),
  162. 'cash_max_single_day' => floatval($this->cash_max_single_day),
  163. 'cash_max_day' => floatval($this->cash_max_day),
  164. 'goods_ids' => $this->goods_ids,
  165. 'cash_price_type' => $this->cash_price_type ?? '1',
  166. 'cash_price_amount' => $this->cash_price_amount ?? 100,
  167. 'cash_price_integral' => $this->cash_price_integral ?? 0,
  168. 'cash_price_balance' => $this->cash_price_balance ?? 0,
  169. 'share_group_bg' => $this->share_group_bg
  170. ];
  171. // $total_profit = 0;
  172. // $cash_price_type = explode(',', $this->cash_price_type);
  173. // if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) {
  174. // $total_profit = bcadd($total_profit, $this->cash_price_amount, 2);
  175. // }
  176. // if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) {
  177. // $total_profit = bcadd($total_profit, $this->cash_price_integral, 2);
  178. // }
  179. // if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) {
  180. // $total_profit = bcadd($total_profit, $this->cash_price_balance, 2);
  181. // }
  182. // if ($total_profit != 100) {
  183. // return [
  184. // 'code' => 1,
  185. // 'msg' => '佣金/积分/余额比例设置错误'
  186. // ];
  187. // }
  188. $goods_ids = explode(',', $data['goods_ids'] ?? '');
  189. if (empty($goods_ids)) {
  190. throw new \Exception('请选择商品');
  191. }
  192. foreach ($goods_ids as $goods_id) {
  193. $goods = Goods::findOne(['id' => $goods_id, 'is_delete' => 0, 'store_id' => $store_id]);
  194. if (!$goods) {
  195. throw new \Exception('商品信息错误' . $goods_id);
  196. }
  197. }
  198. Option::set('share_group_setting', json_encode($data), $store_id, 'share_group');
  199. return [
  200. 'code' => 0,
  201. 'msg' => '保存成功'
  202. ];
  203. } catch (\Exception $e) {
  204. return [
  205. 'code' => 1,
  206. 'msg' => $e->getMessage()
  207. ];
  208. }
  209. }
  210. }