| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace addons\OperationCenter\api\services;
- use addons\OperationCenter\common\models\UserAffiliation;
- use addons\OperationCenter\common\models\UserCenter;
- use addons\OperationCenter\common\services\CenterService as ServicesCenterService;
- use Exception;
- use Yii;
- /**
- * CenterService
- * @package addons\OperationCenter\api\services
- */
- class CenterService extends ServicesCenterService
- {
- /**
- * 通过距离排序分页
- *
- * @param array $params
- * @return array
- */
- public function getPageListOrderByDistance(int $user_id, array $params = [])
- {
- $lat = $params['lat'];
- $lon = $params['lon'];
- $data = UserCenter::getPageList(
- $this->getPage($params), $this->getLimit($params), function ($query)
- use ($lat, $lon)
- {
- $query->select([
- 'id', 'center_name', 'province', 'city',
- 'district', 'town', 'operation_address', 'logo',
- UserCenter::getDistanceSql($lon, $lat)
- ]);
- $query->andWhere(['mall_id' => $this->mall_id]);
- }
- , 'distance ASC');
- // 当前
- $data['current'] = UserAffiliation::getUserAffiliationCenterByUserId($user_id, $lon, $lat);
- return $data;
- }
- /**
- * 选择运营中心
- *
- * @param integer $user_id
- * @param integer $operation_center_id
- * @return boolean
- */
- public function selectOperation(int $user_id, int $operation_center_id)
- {
- $t = Yii::$app->db->beginTransaction();
- try {
- $user_affiliation = UserAffiliation::getUserAffiliationByUserId($user_id);
- if (!empty($user_affiliation)) $user_affiliation->delSelect();
- UserAffiliation::addSelect($this->mall_id, $user_id, $operation_center_id);
- } catch (Exception $e) {
- $t->rollBack();
- return $this->error($e->getMessage());
- }
- $t->commit();
- return true;
- }
- /**
- * 当前选择的运营中心
- *
- * @param integer $user_id
- * @return array
- */
- public function currentOperation(int $user_id)
- {
- $user_affiliation = UserAffiliation::getUserAffiliationByUserId($user_id);
- if (empty($user_affiliation)) {
- return [];
- }
- $center = $user_affiliation->center;
- return empty($center) ? [] : [
- 'id' => $center->id,
- 'center_name' => $center->center_name,
- 'logo' => $center->logo,
- 'province' => $center->province,
- 'city' => $center->city,
- 'district' => $center->district,
- 'town' => $center->town,
- 'operation_address' => $center->operation_address,
- ];
- }
- /**
- * 是否强制运营中心
- *
- * @param integer $user_id
- * @return boolean
- */
- public function getOrderLimit(int $user_id)
- {
- if ($this->getSettingService()->getOrderLimit()) {
- $user_affiliation = UserAffiliation::getUserAffiliationByUserId($user_id);
- return empty($user_affiliation);
- }
- return false;
- }
- }
|