/var/www/vhosts/nabawater/backend/models
Edit: /var/www/vhosts/nabawater/backend/models/Vendor.php (22248B)
[
self::SCENARIO_CREATE
]
],
[
[
'vendor_status', 'vendor_email', 'vendor_contact_number',
'user_name', 'vendor_status', 'vendor_address', 'vendor_latitude', 'vendor_longitude', 'city_id', 'area_id', 'delivery_minutes', 'order_type', 'vendor_type', 'first_name',
'commision_type', 'minimum_cart_value','cgst', 'payment_option'
],
'required',
'on' => [
self::SCENARIO_UPDATE
]
],
[
[
'GST', 'vendor_policy', 'service_tax' , 'is_featured','stripe_account_id'
],
'safe',
'on' => [
self::SCENARIO_CREATE, self::SCENARIO_UPDATE
]
],
['vendor_email', 'email'],
['is_featured', 'safe'],
['password','string', 'min' => 6],
[['commission', 'vendor_contact_number'], 'number'],
[['vendor_email', 'user_name', 'vendor_contact_number'], 'unique'],
[
['vendor_contact_number'],
'match',
'pattern' => '/^[0-9]{7,15}$/',
'message' => Yii::t('backend', 'Mobile accept only 7 to 15 digit numbers'),
'skipOnEmpty' => true,
'skipOnError' => true
],
[
'confirm_password',
'compare',
'compareAttribute' => 'password',
'skipOnEmpty' => false,
'skipOnError' => false,
'message' => "Oops, That's not the same password as the first one",
'on' => [self::SCENARIO_CREATE]
],
['is_featured', 'validateFeatureResturant'],
[
[
'first_name',
'last_name',
'user_name',
'user_type',
'vendor_email',
],
'required',
'on' => [self::SCENARIO_PROFILE_UPDATE]
],
[
'commission',
'required',
'whenClient' => "function(attribute, value) {
return ($('input:radio[name=\"Vendor[commision_type]\"]:checked').val() == 1) ? true : false;
}",
],
[
'commision_percent',
'required',
'whenClient' => "function(attribute, value) {
return ($('input:radio[name=\"Vendor[commision_type]\"]:checked').val() == 2) ? true : false;
}",
],
];
return $rules;
//return ArrayHelper::merge(parent::rules(), $rules);
}
/**
* @return string
*/
public function validateNumber()
{
/* $phoneNumber = $this->vendor_contact_number;
$phoneNumUtil = PhoneNumberUtil::getInstance();
$parsedPhoneNum = $phoneNumUtil->parse($phoneNumber, "MY");
$isValid = $phoneNumUtil->isValidNumber($parsedPhoneNum);
if (!$isValid) {
$this->addError('vendor_contact_number', 'Please Enter Valid Number');
}*/
}
public function validateFeatureResturant()
{
$Countquery = self::find()->where(["is_featured" => self::FEATURED_RESTAURANT])->count();
if($Countquery >= self::MAX_FEATURED_RESTAURANT && $this->is_featured == self::FEATURED_RESTAURANT) {
if($this->getScenario() == self::SCENARIO_UPDATE) {
if($this->getOldAttributes()['is_featured'] == self::FEATURED_RESTAURANT || $this->is_featured == self::NON_FEATURED_RESTAURANT) {
return;
}
}
$this->addError('is_featured', 'Maximum 3 feature Restaurants Allowed');
}
}
/**
*
* @param type $branch_id
* @return array
*/
public static function gettotalVendor()
{
$query = Vendor::find()->alias('V')
->select([
'V.vendor_id',
'V.is_featured',
'V.vendor_key',
'V.vendor_email',
'V.vendor_contact_number',
'V.user_name',
'V.commission',
'V.commision_percent',
'V.vendor_address',
'V.GST',
'V.service_tax',
'V.order_type',
'V.vendor_type',
'V.payment_option',
'V.city_id',
'V.area_id',
'V.vendor_latitude',
'V.vendor_longitude',
'V.delivery_minutes',
'V.out_of_service',
'V.approval_status',
'V.created_at',
'V.vendor_status',
'B.branch_id',
'BL.branch_name',
'V.city_id',
'V.area_id'
])
->leftJoin(['B' => Branch::tableName()], 'B.vendor_id = V.vendor_id')
->leftJoin(['BL' => BranchLang::tableName()], 'BL.branch_id = B.branch_id')
->leftJoin(['CL' => CityLang::tableName()], 'CL.city_id = V.city_id')
->leftJoin(['AL' => AreaLang::tableName()], 'AL.area_id = V.area_id')
->where(['<>', 'V.vendor_status', Vendor::DELETE])
->groupBy('V.vendor_id');
Vendor::selectTranslation($query);
$vcount = $query->count();
$vencount = $vcount;
return $vencount;
}
/**
*
* @return array
*/
public function attributeLabels()
{
return [
'vendor_image_path' => Yii::t('backend','Vendor Image'),
'vendor_id' => Yii::t('backend','Vendor Name'),
'city_id' => Yii::t('backend','City'),
'area_id' => Yii::t('backend','Area'),
'GST' => Yii::t('backend','VAT'),
'sort_no' => Yii::t('backend','Sort Order'),
'created_at' => Yii::t('backend', 'Create Date'),
'vendor_name' => Yii::t('backend', 'Vendor Name'),
'vendor_email' => Yii::t('backend', 'Vendor Email'),
'city' => Yii::t('backend', 'City'),
'vendor_contact_number' => Yii::t('backend', 'Vendor Contact Number'),
'area' => Yii::t('backend', 'Area'),
'vendor_status' => Yii::t('backend', 'Vendor Status'),
'out_of_service' => Yii::t('backend', 'Out Of Service'),
'commission' => Yii::t('backend', 'Commission Value'),
'vendor_type' => Yii::t('backend', 'Food Type'),
'fb_link' => Yii::t('backend', 'Facebook Link'),
'twitter_link' => Yii::t('backend', 'Twitter Link'),
'instagram_link' => Yii::t('backend', 'Instagram Link'),
'personal_link' => Yii::t('backend', 'Personal Website Link'),
'cgst' => Yii::t('backend', 'GST'),
'sgst' => Yii::t('backend', 'SGST'),
'igst' => Yii::t('backend', 'IGST'),
'is_featured' => yii::t('backend','Is Future Vendor')
];
}
/**
*
* @return array
*/
public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios[self::SCENARIO_CREATE] = [
'vendor_status', 'vendor_email', 'vendor_contact_number', 'sort_no',
'user_name', 'password', 'confirm_password', 'commission', 'vendor_status', 'minimum_cart_value', 'vendor_address', 'vendor_latitude', 'vendor_longitude', 'city_id', 'area_id', 'commision_percent', 'delivery_minutes', 'GST', 'vendor_policy', 'service_tax', 'order_type', 'vendor_type','is_featured' ,'first_name','last_name','payment_option','fb_link','twitter_link','instagram_link','personal_link','commision_type','cgst','sgst','igst'
];
$scenarios[self::SCENARIO_UPDATE] = [
'vendor_status', 'vendor_email', 'vendor_contact_number', 'sort_no',
'user_name', 'commission', 'vendor_status', 'minimum_cart_value', 'vendor_address', 'vendor_latitude', 'vendor_longitude', 'city_id', 'area_id', 'commision_percent', 'delivery_minutes', 'GST', 'vendor_policy', 'service_tax', 'order_type', 'vendor_type', 'is_featured' ,'first_name','last_name','payment_option','fb_link','twitter_link','instagram_link','personal_link','commision_type','cgst','sgst','igst'
];
$scenarios[self::SCENARIO_PROFILE_UPDATE] = [
'first_name', 'user_name', 'user_type', 'vendor_email','last_name','vendor_contact_number','minimum_cart_value','GST','service_tax','vendor_type'
];
return $scenarios;
}
public static function getOrderType($value='')
{
return [
Order::ORDER_TYPE_DELIVERY => 'Delivery',
Order::ORDER_TYPE_PICKUP => 'Pickup',
Order::ORDER_TYPE_OTHERS => 'Both',
];
}
public static function getVendorType($value='')
{
return [
self::VENDOR_TYPE_VEG => Yii::t('backend', 'Veg'),
self::VENDOR_TYPE_NONVEG => Yii::t('backend', 'Non Veg'),
self::VENDOR_TYPE_BOTH => Yii::t('backend', 'Both'),
];
}
public function getCommisionType()
{
return [
self::COMMISSION_TYPE_VALUE => 'Value based',
self::COMMISSION_TYPE_PERCENT => 'Percent based',
];
}
/**
*
* @param type $index
* @return array
*/
public function getVendorData()
{
$vendorData = Vendor::find()
->alias('V')
->select([
'V.vendor_id',
'VL.vendor_name'
])
->innerJoin(['VL' => VendorLang::tableName()], 'VL.vendor_id = V.vendor_id')
->where(['V.vendor_status' => Vendor::ACTIVE]);
if(AdminUser::isVendor() || AdminUser::isBranch()){
$vendorData = $vendorData->andWhere(['V.vendor_id' => Yii::$app->getUser()->getIdentity()->vendor_id]);
}
$vendorData = $vendorData->orderBy(['VL.vendor_name' => SORT_ASC])->asArray()
->all();
if (!empty($vendorData)) {
return ArrayHelper::map($vendorData,'vendor_id','vendor_name');
} else {
return [];
}
}
/**
*
* @param type $index
* @return array
*/
public function getBranchData()
{
$vendorData = Branch::find()
->alias('B')
->select([
'B.branch_id',
'BL.branch_name'
])
->innerJoin(['BL' => BranchLang::tableName()], 'BL.branch_id = B.branch_id')
->where(['B.branch_status' => Branch::ACTIVE]);
if(AdminUser::isVendor() || AdminUser::isBranch()){
$vendorData = $vendorData->andWhere(['B.branch_id' => Yii::$app->getUser()->getIdentity()->branch_id]);
}
$vendorData = $vendorData->orderBy(['BL.branch_name' => SORT_ASC])->asArray()
->all();
if (!empty($vendorData)) {
return ArrayHelper::map($vendorData,'branch_id','branch_name');
} else {
return [];
}
}
/**
* Finds an identity by the given ID.
* @param string|int $id the ID to be looked for
* @return IdentityInterface the identity object that matches the given ID.
* Null should be returned if such an identity cannot be found
* or the identity is not in an active state (disabled, deleted, etc.)
*/
public static function findIdentity($id)
{
$vendor = self::findOne(['vendor_id' => $id, 'vendor_status' => self::ACTIVE]);
return $vendor;
}
/**
* Finds an identity by the given token.
* @param mixed $token the token to be looked for
* @param mixed $type the type of the token. The value of this parameter depends on the implementation.
* For example, [[\yii\filters\auth\HttpBearerAuth]] will set this parameter to be `yii\filters\auth\HttpBearerAuth`.
* @return IdentityInterface the identity object that matches the given token.
* @throws \OutOfBoundsException
* @throws \BadMethodCallException
* Null should be returned if such an identity cannot be found
* or the identity is not in an active state (disabled, deleted, etc.)
*/
public static function findIdentityByAccessToken($token, $type = null)
{
$id = null;
$jwtObj = Jwt::getInstance();
if( $jwtObj->isValid($token) ){
$id = $jwtObj->getPrivateClaim($token);
}
return self::findOne($id);
}
/**
* Finds user by user_name
*
* @param string $user_name
* @return static|null
*/
/**
* @param $user_name
* @return array|null|\yii\db\ActiveRecord
*/
public static function findByUsername($user_name)
{
return static::find()
->where(['OR', ['user_name' => $user_name], ['vendor_email' => $user_name]])
->andWhere(['vendor_status' => self::ACTIVE])
->one();
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'vendor_status' => self::ACTIVE,
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* Returns a key that can be used to check the validity of a given identity ID.
*
* The key should be unique for each individual user, and should be persistent
* so that it can be used to check the validity of the user identity.
*
* The space of such keys should be big enough to defeat potential identity attacks.
*
* This is required if [[AdminUser::enableAutoLogin]] is enabled.
* @return string a key that is used to check the validity of a given identity ID.
* @see validateAuthKey()
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* Returns an ID that can uniquely identify a user identity.
* @return string|int an ID that uniquely identifies a user identity.
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* Validates the given auth key.
*
* This is required if [[AdminUser::enableAutoLogin]] is enabled.
* @param string $authKey the given auth key
* @return bool whether the given auth key is valid.
* @see getAuthKey()
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
* @throws \yii\base\InvalidParamException
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
* @throws \yii\base\Exception
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates new password reset token
* @throws \yii\base\Exception
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
public static function getfeaturedlist()
{
$query = Vendor::find()
->select(['COUNT(is_featured)'])
->where("is_featured = 1")
->asArray()
->all();
return $query;
}
public function getfeaturedlistupdate()
{
$query = Vendor::find()
->select(['COUNT(is_featured)'])
->where("is_featured = 1")
->asArray()
->all();
$query = [$query, 'max' => 4];
return $query;
}
/**
* @param $event \yii\web\User
* @throws \MongoDB\Driver\Exception\InvalidArgumentException
* @throws \yii\base\InvalidParamException
*/
protected static function afterLogin($event)
{
/* @var $model self */
$model = $event->identity;
/* $model->last_login = date('Y-m-d H:i:s');
$model->save();*/
$permission_json = '[]';
$modelRole = Role::findOne($model->user_type);
// print_r($modelRole);die;
if ($modelRole != null) {
$permission_json = $modelRole->backend_role_json;
}
if ( $permission_json === null ) {
$permission_json = '[]';
}
Com::setSession(ACCESS_RULE, $permission_json);
}
public function getBranchName($id)
{
$model = Branch::find()
->alias('B')
->select(['BR.branch_name'])
->leftJoin(['BR' => BranchLang::tableName()], 'BR.branch_id = B.branch_id')
->leftJoin(['V' => Vendor::tableName()], 'V.vendor_id = B.vendor_id')
->where(['V.vendor_key' => $id])
->one();
return $model;
}
public function getCity($id)
{
$modelCity = CityLang::find()
->select(['city_id', 'city_name'])
->where(['city_id' => $id])
->andWhere(['language_code' => Yii::$app->language])
->one();
return $modelCity;
}
public function getArea($id)
{
$modelArea = AreaLang::find()
->select(['area_id', 'area_name'])
->where(['area_id' => $id])
->andWhere(['language_code' => Yii::$app->language])
->one();
return $modelArea;
}
public static function getVendorName($id)
{
$modelVendor = VendorLang::find()
->select(['vendor_id', 'vendor_name'])
->where(['vendor_id' => $id])
->andWhere(['language_code' => Yii::$app->language])
->one();
return $modelVendor;
}
public function getCityName($id)
{
$modelCity = CityLang::find()
->select(['city_id', 'city_name'])
->where(['city_id' => $id])
->andWhere(['language_code' => Yii::$app->language])
->one();
return $modelCity;
}
public function getAreaName($id)
{
$modelCity = AreaLang::find()
->select(['area_id', 'area_name'])
->where(['area_id' => $id])
->andWhere(['language_code' => Yii::$app->language])
->one();
return $modelCity;
}
/**
* @return array
* @author Thenmozhi S
*/
public static function getPaymentOption()
{
return [
self::VENDOR_PAYMENT_COD => Yii::t('backend', 'COD'),
self::VENDOR_PAYMENT_ONLINE => Yii::t('backend', 'Online'),
self::VENDOR_PAYMENT_WALLET => Yii::t('backend', 'Wallet'),
];
}
}