ReviewService.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace addons\OperationCenter\common\services;
  3. use addons\OperationCenter\common\models\ApplyList;
  4. use addons\OperationCenter\common\models\Level;
  5. use addons\OperationCenter\common\models\MallUser;
  6. use addons\OperationCenter\common\models\UpgradeLog;
  7. use addons\OperationCenter\common\models\UserCenter;
  8. use common\helpers\map\QqMapHelper;
  9. use Exception;
  10. use Yii;
  11. /**
  12. * ReviewService
  13. * @package addons\OperationCenter\common\services
  14. */
  15. class ReviewService extends BaseService
  16. {
  17. /**
  18. * 获取审核分页列表
  19. *
  20. * @param array $params
  21. * @return array
  22. */
  23. public function getPageList(array $params = [])
  24. {
  25. $mall_id = $this->mall_id;
  26. $name = $params['name'] ?? '';
  27. $mobile = $params['mobile'] ?? '';
  28. $status = $params['status'] ?? '';
  29. $user_id = $params['user_id'] ?? '';
  30. $user_keyword = $params['user_keyword'] ?? '';
  31. return ApplyList::getPageList(
  32. $this->getPage($params), $this->getLimit($params), function ($query)
  33. use ($mall_id, $user_keyword, $name, $mobile, $user_id, $status)
  34. {
  35. // 商场ID
  36. $query->andWhere(['mall_id' => $mall_id]);
  37. // 会员ID
  38. if (!empty($user_id)) {
  39. $query->andWhere(['user_id' => $user_id]);
  40. }
  41. // 会员名称
  42. if (!empty($name)) {
  43. $query->andWhere(['name' => $name]);
  44. }
  45. // 联系电话
  46. if (!empty($mobile)) {
  47. $query->andWhere(['mobile' => $mobile]);
  48. }
  49. // 状态
  50. if (!empty($status)) {
  51. $query->andWhere(['status' => $status]);
  52. }
  53. // 会员信息查询
  54. if (!empty($user_keyword)) {
  55. $query->andWhere(['user_id' => MallUser::getUserIdByUserKeyWord($this->mall_id, $user_keyword)]);
  56. }
  57. $query->with(['user' => function ($query) {
  58. $query->select(['id', 'nickname', 'username', 'mobile', 'avatar_url']);
  59. }]);
  60. }
  61. );
  62. }
  63. /**
  64. * 通过审核
  65. *
  66. * @param integer $id
  67. * @param integer $idlevel_id
  68. * @return boolean
  69. */
  70. public function pass(int $id, int $level_id)
  71. {
  72. // 申请记录
  73. $apply = ApplyList::getApplyingById($this->mall_id, $id);
  74. if (empty($apply)) return $this->error('申请记录不存在');
  75. // 等级
  76. $level = Level::getLevelDetail($this->mall_id, $level_id);
  77. if (empty($level)) return $this->error('等级不存在');
  78. // 转换经纬度
  79. $geocoder = QqMapHelper::Geocoder($apply->getOperationAddress());
  80. if ($geocoder['status'] != 0) return $this->error('地址转换失败');
  81. // 经纬度
  82. if (empty($geocoder['result']['location'])) return $this->error('地址转换失败2');
  83. $location = array_values($geocoder['result']['location']);
  84. list($lon, $lat) = $location;
  85. $t = Yii::$app->db->beginTransaction();
  86. try {
  87. // 添加用户中心
  88. UserCenter::addUserByApply($apply, $level, $lon, $lat);
  89. // 升级记录
  90. UpgradeLog::addUpgradeLog(
  91. $this->mall_id,
  92. $apply->user_id,
  93. $level->level,
  94. UpgradeLog::APPLY
  95. );
  96. // 通过审核
  97. $apply->pass($level);
  98. } catch (Exception $e) {
  99. $t->rollBack();
  100. return $this->error($e->getMessage());
  101. }
  102. $t->commit();
  103. return true;
  104. }
  105. /**
  106. * 驳回审核
  107. *
  108. * @param integer $id
  109. * @param string $content
  110. * @return boolean
  111. */
  112. public function reject(int $id, string $content = '')
  113. {
  114. $apply = ApplyList::getApplyingById($this->mall_id, $id);
  115. if (empty($apply)) return $this->error('申请记录不存在');
  116. return $apply->reject($content);
  117. }
  118. }