RateOut.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * RateOut.php UTF-8
  4. * 优惠折扣对外
  5. *
  6. * @date : 2019/4/24 17:29
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.5
  11. */
  12. namespace huoRate\controller;
  13. use huo\controller\common\Base;
  14. use huolib\status\RateStatus;
  15. use huoRate\model\AgentGameRateModel;
  16. class RateOut extends Base {
  17. /**
  18. * 添加渠道游戏优惠信息
  19. *
  20. * @param int $app_id 应用ID
  21. * @param int $agent_id 渠道ID
  22. *
  23. * @return array
  24. */
  25. public function addAgRate($app_id, $agent_id = 0) {
  26. $_rate_class = new Rate($app_id, $agent_id);
  27. $_rate_data = $_rate_class->getRate();
  28. $_rate_data['promote_switch'] = $_rate_class->getPromoteSwitch();
  29. $_rate_data['app_id'] = $app_id;
  30. $_rate_data['agent_id'] = $agent_id;
  31. $_rs = (new AgentGameRateModel())->addData($_rate_data);
  32. if (false !== $_rs) {
  33. $_code = RateStatus::NO_ERROR;
  34. return $this->huoSuccess($_code, RateStatus::getMsg($_code));
  35. }
  36. $_code = RateStatus::INNER_ERROR;
  37. return $this->huoSuccess($_code, RateStatus::getMsg($_code));
  38. }
  39. /**
  40. * 添加渠道游戏优惠信息
  41. *
  42. * @param array $data 数据
  43. * @param int $id ID
  44. *
  45. * @return array
  46. */
  47. public function editAgRate($data, $id) {
  48. if (empty($id)) {
  49. $_code = RateStatus::INVALID_PARAMS;
  50. return $this->huoSuccess($_code, RateStatus::getMsg($_code));
  51. }
  52. $_agr_model = new AgentGameRateModel();
  53. $_app_id = $_agr_model->getAppIdById($id);
  54. $_agent_id = $_agr_model->getAgentIdById($id);
  55. if (empty($_app_id) && empty($_agent_id)) {
  56. $_code = RateStatus::INVALID_PARAMS;
  57. return $this->huoError($_code, RateStatus::getMsg($_code).'1');
  58. }
  59. if ((isset($data['app_id']) && $data['app_id'] != $_app_id)
  60. || (isset($data['agent_id']) && $data['agent_id'] != $_agent_id)) {
  61. $_code = RateStatus::INVALID_PARAMS;
  62. return $this->huoError($_code, RateStatus::getMsg($_code).'2');
  63. }
  64. // $_rc_class = new RateCheck();
  65. // $_rdata = $_rc_class->checkParam($_app_id, $_agent_id, $data);
  66. // if (RateStatus::NO_ERROR != $_rdata['code']) {
  67. // return $this->huoReturn($_rdata);
  68. // }
  69. $_rs = $_agr_model->updateData($data, $id);
  70. if (false === $_rs) {
  71. $_code = RateStatus::INNER_ERROR;
  72. return $this->huoError($_code, RateStatus::getMsg($_code));
  73. }
  74. $_code = RateStatus::NO_ERROR;
  75. return $this->huoSuccess($_code, RateStatus::getMsg($_code));
  76. }
  77. }