ShareSettingForm.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\constants\OptionSetting;
  9. use app\models\CashExt;
  10. use app\models\Goods;
  11. use app\models\Option;
  12. use yii\base\Model;
  13. class ShareSettingForm extends Model
  14. {
  15. public $data;
  16. public $name;
  17. public $model;
  18. public $store_id;
  19. /**
  20. * 设置分销金额
  21. */
  22. public function setMoneySetting() {
  23. $this->model->store_id = $this->store_id;
  24. $this->model->group = OptionSetting::SHARE_GROUP_NAME;
  25. $this->model->name = OptionSetting::SHARE_MONEY_SETTING;
  26. $this->model->value = json_encode($this->data);
  27. if (!$this->model->isNewRecord) {
  28. $this->model->updated_at = time();
  29. }
  30. if (!$this->model->save()) {
  31. foreach ($this->model->errors as $error) {
  32. return [
  33. 'code' => 1,
  34. 'msg' => $error,
  35. ];
  36. }
  37. }
  38. return [
  39. 'code' => 0,
  40. 'msg' => '保存成功'
  41. ];
  42. }
  43. /**
  44. * 设置分销
  45. */
  46. public function setBasicSetting() {
  47. if (!is_numeric($this->data['min_money']) || !is_numeric($this->data['cash_max_day'])
  48. || !is_numeric($this->data['auto_share_val'])) {
  49. return ['code' => 1, 'msg' => '金额字段请输入数字'];
  50. }
  51. if ($this->data['share_goods_status'] == 2) {
  52. if (empty($this->data['share_goods_id'])) {
  53. return ['code' => 1, 'msg' => '请选择指定商品'];
  54. }
  55. }
  56. $data = [
  57. 'level'=> [
  58. 'text' => '开启分销',
  59. 'value' => $this->data['level']
  60. ],
  61. 'is_rebate' => [
  62. 'text' => '自购返利开关',
  63. 'value' => $this->data['is_rebate']
  64. ],
  65. 'condition' => [
  66. 'text' => '成为下线条件',
  67. 'value' => $this->data['condition']
  68. ],
  69. 'enforce_bind_parent' => [
  70. 'text' => '强制绑定上级',
  71. 'value' => $this->data['enforce_bind_parent']
  72. ],
  73. 'share_condition' => [
  74. 'text' => '成为分销商条件',
  75. 'value' => $this->data['share_condition']
  76. ],
  77. 'rec_member_integral' => [
  78. 'text' => '推荐会员送积分',
  79. 'value' => intval($this->data['rec_member_integral'])
  80. ],
  81. 'd_rec_member_integral' => [
  82. 'text' => '被推荐会员送积分',
  83. 'value' => intval($this->data['d_rec_member_integral'])
  84. ],
  85. 'pay_type' => [
  86. 'text' => '提现方式',
  87. 'value' => $this->data['pay_type']
  88. ],
  89. 'auto_money' => [
  90. 'text' => '自动打款金额',
  91. 'value' => $this->data['auto_money']
  92. ],
  93. 'min_money' => [
  94. 'text' => '最小提现额度',
  95. 'value' => $this->data['min_money']
  96. ],
  97. 'cash_max_day' => [
  98. 'text' => '每天最大提现额度',
  99. 'value' => $this->data['cash_max_day']
  100. ],
  101. 'cash_max_single_day' => [
  102. 'text' => '每人每天提现额度',
  103. 'value' => $this->data['cash_max_single_day']
  104. ],
  105. 'cash_service_charge' => [
  106. 'text' => '提现手续费',
  107. 'value' => floatval($this->data['cash_service_charge'])
  108. ],
  109. 'auto_share_val' => [
  110. 'text' => '消费自动成为分销商',
  111. 'value' => $this->data['auto_share_val']
  112. ],
  113. 'share_goods_status' => [
  114. 'text' => '购买指定商品成为分销商',
  115. 'value' => $this->data['share_goods_status']
  116. ],
  117. 'share_goods_id' => [
  118. 'text' => '购买指定商品id',
  119. 'value' => $this->data['share_goods_id']
  120. ],
  121. 'content' => [
  122. 'text' => '用户须知',
  123. 'value' => $this->data['content']
  124. ],
  125. 'agree' => [
  126. 'text' => '协议',
  127. 'value' => $this->data['agree']
  128. ],
  129. 'remaining_sum' => [
  130. 'text' => '余额提现',
  131. 'value' => $this->data['remaining_sum']
  132. ],
  133. 'bank' => [
  134. 'text' => '银行卡',
  135. 'value' => $this->data['bank']
  136. ],
  137. 'lg' => [
  138. 'text' => '灵工提现',
  139. 'value' => $this->data['lg']
  140. ],
  141. 'apply_image' => [
  142. 'text' => '申请页面',
  143. 'value' => $this->data['apply_image']
  144. ],
  145. 'no_checked_image' => [
  146. 'text' => '待审核页面',
  147. 'value' => $this->data['no_checked_image']
  148. ],
  149. 'wx_title' => [
  150. 'text' => '小程序标题昵称',
  151. 'value' => $this->data['wx_title']
  152. ],
  153. 'parent_label' => [
  154. 'text' => '自定义上级名称显示',
  155. 'value' => $this->data['parent_label']
  156. ],
  157. 'cash_price_type' => [
  158. 'text' => '佣金到账类型',
  159. 'value' => $this->data['cash_price_type'] ?? '1'
  160. ],
  161. 'cash_price_amount' => [
  162. 'text' => '现金',
  163. 'value' => $this->data['cash_price_amount'] ?? 100
  164. ],
  165. 'cash_price_integral' => [
  166. 'text' => '积分',
  167. 'value' => $this->data['cash_price_integral'] ?? 0
  168. ],
  169. 'cash_price_balance' => [
  170. 'text' => '余额',
  171. 'value' => $this->data['cash_price_balance'] ?? 0
  172. ],
  173. 'invite_type' => [
  174. 'text' => '邀请类型',
  175. 'value' => $this->data['invite_type']??1
  176. ],
  177. ];
  178. // $total_profit = 0;
  179. // $cash_price_type = explode(',', $this->data['cash_price_type']);
  180. // if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) {
  181. // $total_profit = bcadd($total_profit, $this->data['cash_price_amount'], 2);
  182. // }
  183. // if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) {
  184. // $total_profit = bcadd($total_profit, $this->data['cash_price_integral'], 2);
  185. // }
  186. // if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) {
  187. // $total_profit = bcadd($total_profit, $this->data['cash_price_balance'], 2);
  188. // }
  189. // if ($total_profit != 100) {
  190. // return [
  191. // 'code' => 1,
  192. // 'msg' => '佣金/积分/余额比例设置错误'
  193. // ];
  194. // }
  195. $this->model->store_id = $this->store_id;
  196. $this->model->group = OptionSetting::SHARE_GROUP_NAME;
  197. $this->model->name = OptionSetting::SHARE_BASIC_SETTING;
  198. $this->model->value = json_encode($data);
  199. if (!$this->model->isNewRecord) {
  200. $this->model->updated_at = time();
  201. }
  202. if (!$this->model->save()) {
  203. foreach ($this->model->errors as $error) {
  204. return [
  205. 'code' => 1,
  206. 'msg' => $error,
  207. ];
  208. }
  209. }
  210. return [
  211. 'code' => 0,
  212. 'msg' => '保存成功'
  213. ];
  214. }
  215. /**
  216. * 设置saas分销
  217. */
  218. public function setSaasBasicSetting() {
  219. if (!is_numeric($this->data['min_money']) || !is_numeric($this->data['cash_max_day']) ) {
  220. return ['code' => 1, 'msg' => '金额字段请输入数字'];
  221. }
  222. $data = [
  223. 'pay_type' => [
  224. 'text' => '提现方式',
  225. 'value' => $this->data['pay_type']
  226. ],
  227. 'min_money' => [
  228. 'text' => '最小提现额度',
  229. 'value' => $this->data['min_money']
  230. ],
  231. 'cash_max_day' => [
  232. 'text' => '每天最大提现额度',
  233. 'value' => $this->data['cash_max_day']
  234. ],
  235. 'cash_service_charge' => [
  236. 'text' => '提现手续费',
  237. 'value' => floatval($this->data['cash_service_charge'])
  238. ]
  239. ];
  240. //商盟固定store_id
  241. $this->model->store_id = -1;
  242. $this->model->group = OptionSetting::SHARE_GROUP_NAME;
  243. $this->model->name = OptionSetting::SHARE_BASIC_SETTING;
  244. $this->model->value = json_encode($data);
  245. if (!$this->model->isNewRecord) {
  246. $this->model->updated_at = time();
  247. }
  248. if (!$this->model->save()) {
  249. foreach ($this->model->errors as $error) {
  250. return [
  251. 'code' => 1,
  252. 'msg' => $error,
  253. ];
  254. }
  255. }
  256. return [
  257. 'code' => 0,
  258. 'msg' => '保存成功'
  259. ];
  260. }
  261. /**
  262. * 获取设置
  263. */
  264. public function getShareSetting() {
  265. if (empty($this->name)) {
  266. return [
  267. 'code' => 1,
  268. "msg" => $this->getErrorSummary(false)[0]
  269. ];
  270. }
  271. $values = Option::find()->where(['store_id' => $this->store_id,
  272. 'group' => OptionSetting::SHARE_GROUP_NAME, 'name' => $this->name])->select('value')->One();
  273. if($values){
  274. $data = json_decode($values->value, true);
  275. }else{
  276. $data = [];
  277. }
  278. $goods = [];
  279. if (isset($data['share_goods_id']['value'])) {
  280. $ids = \explode(',', $data['share_goods_id']['value']);
  281. $goods = Goods::find()->select('cover_pic, goods_num, id, is_negotiable, name, original_price, price, product_type')
  282. ->where(['id' => $ids])->all();
  283. }
  284. if ($this->name === 'share_basic_setting') {
  285. $data_ = [
  286. 'auto_share_val' => [
  287. 'text' => '消费自动成为分销商',
  288. 'value' => 0
  289. ],
  290. 'share_condition' => [
  291. 'text' => '成为分销商条件',
  292. 'value' => 0
  293. ],
  294. 'level'=> [
  295. 'text' => '开启分销',
  296. 'value' => 1
  297. ],
  298. 'is_rebate' => [
  299. 'text' => '自购返利开关',
  300. 'value' => 0
  301. ],
  302. 'condition' => [
  303. 'text' => '成为下线条件',
  304. 'value' => 0
  305. ],
  306. 'enforce_bind_parent' => [
  307. 'text' => '强制绑定上级',
  308. 'value' => 0
  309. ],
  310. 'rec_member_integral' => [
  311. 'text' => '推荐会员送积分',
  312. 'value' => 0
  313. ],
  314. 'd_rec_member_integral' => [
  315. 'text' => '被推荐会员送积分',
  316. 'value' => 0
  317. ],
  318. 'pay_type' => [
  319. 'text' => '提现方式',
  320. 'value' => ''
  321. ],
  322. 'min_money' => [
  323. 'text' => '最小提现额度',
  324. 'value' => 0
  325. ],
  326. 'cash_max_day' => [
  327. 'text' => '每天最大提现额度',
  328. 'value' => 100
  329. ],
  330. 'cash_max_single_day' => [
  331. 'text' => '每人每天提现额度',
  332. 'value' => 100
  333. ],
  334. 'cash_service_charge' => [
  335. 'text' => '提现手续费',
  336. 'value' => floatval(0)
  337. ],
  338. 'share_goods_status' => [
  339. 'text' => '购买指定商品成为分销商',
  340. 'value' => ''
  341. ],
  342. 'share_goods_id' => [
  343. 'text' => '购买指定商品id',
  344. 'value' => ''
  345. ],
  346. 'content' => [
  347. 'text' => '用户须知',
  348. 'value' => ''
  349. ],
  350. 'agree' => [
  351. 'text' => '协议',
  352. 'value' => ''
  353. ],
  354. 'remaining_sum' => [
  355. 'text' => '余额提现',
  356. 'value' => 0
  357. ],
  358. 'bank' => [
  359. 'text' => '银行卡',
  360. 'value' => 0
  361. ],
  362. 'cash_price_type' => [
  363. 'text' => '佣金到账类型',
  364. 'value' => '1'
  365. ],
  366. 'cash_price_amount' => [
  367. 'text' => '现金',
  368. 'value' => 100
  369. ],
  370. 'cash_price_integral' => [
  371. 'text' => '积分',
  372. 'value' => 0
  373. ],
  374. 'cash_price_balance' => [
  375. 'text' => '余额',
  376. 'value' => 0
  377. ],
  378. 'auto_money' => [
  379. 'text' => '自动打款金额',
  380. 'value' => 0
  381. ]
  382. ];
  383. $data = array_merge($data_, $data);
  384. }
  385. if($this->name === 'share_money_setting' && !$data){
  386. $data = [
  387. 'cash_price_amount' => ['text' => '现金','value' => 100],
  388. 'cash_price_balance' => ['text' => '余额','value' => 0],
  389. 'cash_price_integral' => ['text' => '积分','value' => 0],
  390. 'cash_price_type' => ['text' => '佣金到账类型','value' => "1"],
  391. 'commission_type' => [2],
  392. 'expire_day' => "0",
  393. 'giveType' => 1,
  394. 'level_one' => ['text' => '一级分销','value' => 0],
  395. 'level_three' => ['text' => '三级分销','value' => 0],
  396. 'level_two' => ['text' => '二级分销','value' => 0],
  397. 'scale' => "0",
  398. 'share_goods_id' => []
  399. ];
  400. }
  401. if ($this->name === 'share_basic_setting') {
  402. if (!isset($data['cash_price_type'])) {
  403. $data = array_merge($data, [
  404. 'cash_price_type' => [
  405. 'text' => '佣金到账类型',
  406. 'value' => '1'
  407. ],
  408. 'cash_price_amount' => [
  409. 'text' => '现金',
  410. 'value' => 100
  411. ],
  412. 'cash_price_integral' => [
  413. 'text' => '积分',
  414. 'value' => 0
  415. ],
  416. 'cash_price_balance' => [
  417. 'text' => '余额',
  418. 'value' => 0
  419. ],
  420. ]);
  421. }
  422. }
  423. if ($this->name === 'share_money_setting') {
  424. if (!isset($data['commission_type'])) {
  425. $data['commission_type'] = [2];
  426. }
  427. if (!isset($data['expire_day'])) {
  428. $data['expire_day'] = 0;
  429. }
  430. if (!isset($data['giveType'])) {
  431. $data['giveType'] = 1;
  432. }
  433. if (!isset($data['scale'])) {
  434. $data['scale'] = '0';
  435. }
  436. }
  437. $data['share_goods_id']['value'] = $data['share_goods_id']['value'] ?? '';
  438. return ['code' => 0, 'msg' => 'success', 'data' => $data, 'goods' => $goods];
  439. }
  440. }