| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace addons\OperationCenter\common\services;
- use addons\OperationCenter\common\models\ApplyList;
- use addons\OperationCenter\common\models\Level;
- use addons\OperationCenter\common\models\MallUser;
- use addons\OperationCenter\common\models\UpgradeLog;
- use addons\OperationCenter\common\models\UserCenter;
- use common\helpers\map\QqMapHelper;
- use Exception;
- use Yii;
- /**
- * ReviewService
- * @package addons\OperationCenter\common\services
- */
- class ReviewService extends BaseService
- {
- /**
- * 获取审核分页列表
- *
- * @param array $params
- * @return array
- */
- public function getPageList(array $params = [])
- {
- $mall_id = $this->mall_id;
- $name = $params['name'] ?? '';
- $mobile = $params['mobile'] ?? '';
- $status = $params['status'] ?? '';
- $user_id = $params['user_id'] ?? '';
- $user_keyword = $params['user_keyword'] ?? '';
- return ApplyList::getPageList(
- $this->getPage($params), $this->getLimit($params), function ($query)
- use ($mall_id, $user_keyword, $name, $mobile, $user_id, $status)
- {
- // 商场ID
- $query->andWhere(['mall_id' => $mall_id]);
- // 会员ID
- if (!empty($user_id)) {
- $query->andWhere(['user_id' => $user_id]);
- }
- // 会员名称
- if (!empty($name)) {
- $query->andWhere(['name' => $name]);
- }
- // 联系电话
- if (!empty($mobile)) {
- $query->andWhere(['mobile' => $mobile]);
- }
- // 状态
- if (!empty($status)) {
- $query->andWhere(['status' => $status]);
- }
- // 会员信息查询
- if (!empty($user_keyword)) {
- $query->andWhere(['user_id' => MallUser::getUserIdByUserKeyWord($this->mall_id, $user_keyword)]);
- }
- $query->with(['user' => function ($query) {
- $query->select(['id', 'nickname', 'username', 'mobile', 'avatar_url']);
- }]);
- }
- );
- }
- /**
- * 通过审核
- *
- * @param integer $id
- * @param integer $idlevel_id
- * @return boolean
- */
- public function pass(int $id, int $level_id)
- {
- // 申请记录
- $apply = ApplyList::getApplyingById($this->mall_id, $id);
- if (empty($apply)) return $this->error('申请记录不存在');
- // 等级
- $level = Level::getLevelDetail($this->mall_id, $level_id);
- if (empty($level)) return $this->error('等级不存在');
- // 转换经纬度
- $geocoder = QqMapHelper::Geocoder($apply->getOperationAddress());
- if ($geocoder['status'] != 0) return $this->error('地址转换失败');
- // 经纬度
- if (empty($geocoder['result']['location'])) return $this->error('地址转换失败2');
- $location = array_values($geocoder['result']['location']);
- list($lon, $lat) = $location;
- $t = Yii::$app->db->beginTransaction();
- try {
- // 添加用户中心
- UserCenter::addUserByApply($apply, $level, $lon, $lat);
- // 升级记录
- UpgradeLog::addUpgradeLog(
- $this->mall_id,
- $apply->user_id,
- $level->level,
- UpgradeLog::APPLY
- );
- // 通过审核
- $apply->pass($level);
- } catch (Exception $e) {
- $t->rollBack();
- return $this->error($e->getMessage());
- }
- $t->commit();
- return true;
- }
- /**
- * 驳回审核
- *
- * @param integer $id
- * @param string $content
- * @return boolean
- */
- public function reject(int $id, string $content = '')
- {
- $apply = ApplyList::getApplyingById($this->mall_id, $id);
- if (empty($apply)) return $this->error('申请记录不存在');
- return $apply->reject($content);
- }
- }
|