| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- namespace addons\Community\common\service;
- use addons\Community\common\models\CommunityHead;
- use common\enums\StatusEnum;
- use common\models\common\Region;
- use yii\helpers\Json;
- class HeadService
- {
- public function update(int $mall_id, array $params, int $user_id)
- {
- $data = CommunityHead::getOne([
- ['mall_id' => $mall_id],
- ['user_id' => $user_id],
- ['status' => StatusEnum::ENABLED]
- ]);
- if (empty($data)) return '您还没有入驻';
- $data->mobile = "{$params['contact_phone']}";
- $data->desc = $params['intro'];
- $data->name = $params['name'];
- $data->logo = $params['logo'];
- $data->license_img = $params['license_img'];
- $data->idcard_img = Json::encode($params['id_card_img']);
- $data->province_id = $params['province_id'];
- $data->city_id = $params['city_id'];
- $data->district_id = $params['district_id'];
- $data->longitude = "{$params['lng']}";
- $data->latitude = "{$params['lat']}";
- $data->address = $params['street'];
- if (!$data->save()) {
- \Yii::error($data->getErrorMessage());
- return '修改失败';
- }
- return true;
- }
- /**
- * @param int $mall_id
- * @param int $user_id
- * @return array|mixed
- */
- public function detail(int $mall_id, int $user_id)
- {
- $data = CommunityHead::getOne([
- ['mall_id' => $mall_id],
- ['user_id' => $user_id],
- ['status' => StatusEnum::ENABLED]
- ], true, [], null, 'id, created_at, contacts, mobile, name, desc, logo, license_img, idcard_img, province_id,
- city_id, district_id, address, longitude, latitude');
- if (!empty($data)) {
- $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
- $data['contact_name'] = $data['contacts'];
- $data['contact_phone'] = $data['mobile'];
- $data['intro'] = $data['desc'];
- $data['id_card_img'] = Json::decode($data['idcard_img']);
- $data['street'] = $data['address'];
- $data['lng'] = $data['longitude'];
- $data['lat'] = $data['latitude'];
- unset($data['contacts'], $data['mobile'], $data['desc'], $data['address'], $data['idcard_img'], $data['longitude'], $data['latitude']);
- }
- return $data;
- }
- /**
- * @param int $mall_id
- * @param int $user_id
- * @return int
- */
- public function existByUserId(int $mall_id, int $user_id): int
- {
- $cnt = CommunityHead::find()->where(['mall_id' => $mall_id])
- ->andWhere(['user_id' => $user_id])
- ->andWhere(['status' => StatusEnum::ENABLED])
- ->count();
- return $cnt > 0 ? StatusEnum::ENABLED : StatusEnum::DISABLED;
- }
- /**
- * 获取团长信息
- * @param int $mall_id
- * @param int $head_id
- * @return mixed|null
- */
- public function pickupInfo(int $mall_id, int $head_id)
- {
- return CommunityHead::getOne([
- ['mall_id' => $mall_id],
- ['id' => $head_id],
- ['status' => StatusEnum::ENABLED],
- ['check_status' => StatusEnum::ENABLED]
- ], true, [], false, 'address, contacts as contact_name, mobile as contact_phone, name, logo, longitude as lng, latitude as lat');
- }
- /**
- * 订单详情获取团长信息
- * @param int $mall_id
- * @param int $head_id
- * @return mixed|null
- */
- public function pickupInfoOrder(int $mall_id, int $head_id)
- {
- return CommunityHead::getOne([
- ['mall_id' => $mall_id],
- ['id' => $head_id],
- ['check_status' => StatusEnum::ENABLED]
- ], true, [], false, 'address, contacts as contact_name, mobile as contact_phone, name, logo, longitude as lng, latitude as lat');
- }
- /**
- * 获取自提点信息
- * @param int $mall_id
- * @param int $head_id
- * @return mixed|null
- */
- public function getHeadInfo(int $mall_id, int $head_id)
- {
- $head = CommunityHead::getOne([
- ['mall_id' => $mall_id],
- ['id' => $head_id],
- ['status' => StatusEnum::ENABLED],
- ['check_status' => StatusEnum::ENABLED]
- ], true, [], false, 'province_id, city_id, district_id, address');
- if (!empty($head)) {
- $head['province'] = Region::find()->where(['id' => $head['province_id']])->select('name')->scalar() ?? '';
- $head['city'] = Region::find()->where(['id' => $head['city_id']])->select('name')->scalar() ?? '';
- $head['district'] = Region::find()->where(['id' => $head['district_id']])->select('name')->scalar() ?? '';
- }
- return $head;
- }
- /**
- * @param int $mall_id
- * @param int $head_id
- * @return bool
- */
- public static function validHeadExist(int $mall_id, int $head_id)
- {
- return !empty(CommunityHead::find()->where(['mall_id' => $mall_id])
- ->andWhere(['id' => $head_id])
- ->andWhere(['status' => StatusEnum::ENABLED])
- ->andWhere(['check_status' => StatusEnum::ENABLED])
- ->one());
- }
- }
|