CustomLevelController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. 'qtNum' => 200,
  17. 'qtAmount' => 10000,
  18. 'byNum' => 500,
  19. 'byAmount' => 50000,
  20. 'hjNum' => 1000,
  21. 'hjAmount' => 300000,
  22. 'zsNum' => 5000,
  23. 'zsAmount' => 1800000
  24. ];
  25. CustomLevelClass::add($data, true);
  26. $info = CustomLevelClass::getByCondition(['shopId' => $this->shopId]);
  27. }
  28. util::success(['info' => $info]);
  29. }
  30. //添加修改等级 shish 20211016
  31. public function actionReplace()
  32. {
  33. $shopAdmin = $this->shopAdmin;
  34. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  35. util::fail('管理员才能操作');
  36. }
  37. $post = Yii::$app->request->post();
  38. $info = CustomLevelClass::getByCondition(['shopId' => $this->shopId], true);
  39. if (empty($info)) {
  40. util::fail('出错了');
  41. }
  42. $id = $info->id ?? 0;
  43. $qtNum = $post['qtNum'] ?? 0;
  44. if (is_numeric($qtNum) == false || $qtNum <= 0) {
  45. util::fail('青铜等级的数量要大于0');
  46. }
  47. $byNum = $post['byNum'] ?? 0;
  48. if ($byNum <= $qtNum) {
  49. util::fail('白银等级的数量要大于青铜');
  50. }
  51. $hjNum = $post['hjNum'] ?? 0;
  52. if ($hjNum <= $byNum) {
  53. util::fail('黄金等级的数量要大于白银');
  54. }
  55. $zsNum = $post['zsNum'] ?? 0;
  56. if ($zsNum <= $hjNum) {
  57. util::fail('钻石等级的数量要大于黄金');
  58. }
  59. CustomLevelClass::updateById($id, $post);
  60. util::complete('修改成功');
  61. }
  62. }