CustomLevelController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\custom\classes\CustomLevelClass;
  4. use common\components\util;
  5. use Yii;
  6. class CustomLevelController extends BaseController
  7. {
  8. //等级详情 shish 20211016
  9. public function actionGetInfo()
  10. {
  11. $info = CustomLevelClass::getByCondition(['shopId' => $this->shopId]);
  12. if (empty($info)) {
  13. $data = [
  14. 'sjId' => $this->sjId,
  15. 'shopId' => $this->shopId,
  16. ];
  17. CustomLevelClass::add($data, true);
  18. $info = CustomLevelClass::getByCondition(['shopId' => $this->shopId]);
  19. }
  20. util::success(['info' => $info]);
  21. }
  22. //添加修改等级 shish 20211016
  23. public function actionReplace()
  24. {
  25. $post = Yii::$app->request->post();
  26. $info = CustomLevelClass::getByCondition(['shopId' => $this->shopId], true);
  27. if (empty($info)) {
  28. util::fail('出错了');
  29. }
  30. $id = $info->id ?? 0;
  31. $qtNum = $post['qtNum'] ?? 0;
  32. if (is_numeric($qtNum) == false || $qtNum <= 0) {
  33. util::fail('青铜等级的数量要大于0');
  34. }
  35. $byNum = $post['byNum'] ?? 0;
  36. if ($byNum <= $qtNum) {
  37. util::fail('白银等级的数量要大于青铜');
  38. }
  39. $hjNum = $post['hjNum'] ?? 0;
  40. if ($hjNum <= $byNum) {
  41. util::fail('黄金等级的数量要大于白银');
  42. }
  43. $zsNum = $post['zsNum'] ?? 0;
  44. if ($zsNum <= $hjNum) {
  45. util::fail('钻石等级的数量要大于黄金');
  46. }
  47. CustomLevelClass::updateById($id, $post);
  48. util::complete('修改成功');
  49. }
  50. }