TjFlController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\market\classes\TjFlClass;
  4. use common\components\util;
  5. use Yii;
  6. class TjFlController extends BaseController
  7. {
  8. public function actionDetail()
  9. {
  10. $list = TjFlClass::getAllByCondition(['shopId' => $this->shopId, 'delStatus' => 0], 'hbAmount DESC', '*');
  11. $tjFl = $this->shop->tjFl ?? 0;
  12. util::success(['list' => $list, 'tjFl' => $tjFl]);
  13. }
  14. //保存福利内容 ssh 20210930
  15. public function actionSaveFl()
  16. {
  17. $data = Yii::$app->request->post('data');
  18. $arr = json_decode($data, true);
  19. if (is_array($arr) == false) {
  20. util::fail('数据错误');
  21. }
  22. TjFlClass::updateByCondition(['shopId' => $this->shopId], ['delStatus' => 1]);
  23. $tjFlAmount = 0;
  24. foreach ($arr as $key => $item) {
  25. $mini = $item['miniExpend'] ?? 0;
  26. $hbAmount = $item['hbAmount'] ?? 0;
  27. if ($mini <= $hbAmount) {
  28. util::fail('最低消费金额要大于红包金额');
  29. }
  30. $valid = $item['valid'] ?? 0;
  31. if (empty($valid)) {
  32. util::fail('请填写红包有效期');
  33. }
  34. $num = $item['num'] ?? 0;
  35. if ($num <= 0) {
  36. util::fail('请填写红包数量');
  37. }
  38. $totalHb = bcmul($hbAmount, $num, 2);
  39. $item['shopId'] = $this->shopId;
  40. $item['sjId'] = $this->sjId;
  41. $item['totalHb'] = $totalHb;
  42. TjFlClass::add($item);
  43. $tjFlAmount = bcadd($tjFlAmount, bcmul($hbAmount, $num), 2);
  44. }
  45. $tjFlSwitch = Yii::$app->request->post('tjFlSwitch', 0);
  46. $this->shop->tjFl = $tjFlSwitch;
  47. $this->shop->tjFlAmount = $tjFlAmount;
  48. $this->shop->save();
  49. util::complete('已保存');
  50. }
  51. }