/var/www/vhosts/nabawater/api/modules/v1/models
Edit: /var/www/vhosts/nabawater/api/modules/v1/models/VendorOrder.php (13925B)
function (self $model) {
$modelBranch = Branch::findOne($model->branch_id);
return $modelBranch !== null ? $modelBranch->branch_key : null;
},
'customer_id' => 'user_id',
'shop_logo' => function (self $model) {
$modelVendor = VendorLang::findOne([
'vendor_id' => $model->vendor_id,
'language_code' => Yii::$app->language
]);
$path = null;
if ($modelVendor !== null) {
$path = $modelVendor->vendor_image_path;
}
return UploadHelper::getInstance()->get($path);
},
'order_datetime' => function (self $model) {
$dtHelper = DateTimeHelper::getInstance();
return $dtHelper->format($model->order_date_time, $dtHelper::MYSQL_DATETIME_FORMAT);
},
'order_key',
'order_number',
'order_total',
'rejected_reason',
'currency_code' => function (self $model) {
return $model->currency_code !== null ? $model->currency_code : '';
},
'first_name' => 'customer_first_name',
'last_name' => 'customer_last_name',
'email' => 'customer_email',
'mobile_number' => 'customer_mobile_number',
'promocode' => function (self $model) {
$modelCoupon = OrderCoupon::findOne(['order_id' => $model->order_id]);
if ($modelCoupon !== null) {
return $modelCoupon->coupon_code;
}
return '';
},
'promocode_amount' => 'coupon_offer_value',
'tax' => function (self $model) {
$tax = [];
$tax['service_tax'] = $model->service_tax;
$tax['vat'] = $model->vat;
$taxvalues[] = $tax;
return $taxvalues;
},
'sub_total' => 'item_total',
'pickup_date' => function (self $model) {
return $this->isNull($model->pickup_date);
},
'pickup_time' => function (self $model) {
return $this->isNull($model->pickup_time);
},
'dining_date' => function (self $model) {
return $this->isNull($model->dining_date);
},
'dining_time' => function (self $model) {
return $this->isNull($model->dining_time);
},
'member_count'=> function (self $model) {
return $this->isNull($model->member_count);
},
'product_id'=> function (self $model) {
return $this->isNull($model->product_id);
},
'delivery_fee',
'delivery_boy_tip',
'delivery_city' => function (self $model) {
if ((int)$model->order_type === $model::ORDER_TYPE_DELIVERY) {
$modelAddress = self::getUserAddress();
return ($modelAddress != null) ? $modelAddress->city : '' ;
}
return '';
},
'delivery_area' => function (self $model) {
if ((int)$model->order_type === $model::ORDER_TYPE_DELIVERY) {
$modelAddress = self::getUserAddress();
return ($modelAddress != null) ? $modelAddress->area : '' ;
}
return '';
},
'flat_no' => function (self $model){
if ((int)$model->order_type === $model::ORDER_TYPE_DELIVERY) {
$modelAddress = self::getUserAddress();
return ($modelAddress != null) ? $modelAddress->flat_no : '' ;
}
return '';
},
'apartment' => function (self $model) {
if ((int)$model->order_type === $model::ORDER_TYPE_DELIVERY) {
$modelAddress = self::getUserAddress();
return ($modelAddress != null) ? $modelAddress->apartment : '' ;
}
return '';
},
'delivery_instruction' => function (self $model) {
return '';
},
'message' => function (self $model) {
return $this->isNull($model->order_message);
},
'alternate_contact' => function (self $model) {
return '';
},
'landmark' => function (self $model) {
if ((int)$model->order_type === $model::ORDER_TYPE_DELIVERY) {
$modelAddress = self::getUserAddress();
return ($modelAddress != null) ? $modelAddress->landmark : '' ;
}
return '';
},
'payment_status' =>function (self $model) {
return $model->payment_status;
},
'payment_type' => function (self $model) {
return $model->payment_option;
},
'delivery_status' => function (self $model) {
$label = $this->getDeliveryStatus((int)$model->order_status);
if((int)$model->order_status === $model::ORDER_STATUS_READY_TO_PICKUP) {
if ((int)$model->order_type === $model::ORDER_TYPE_PICKUP) {
return 'Ready To Pickup';
} else {
return 'Ready To Delivery';
}
}
return $this->getDeliveryStatus((int)$model->order_status);
},
'delivery_status_label' => function (self $model) {
$label = $this->getDeliveryStatus((int)$model->order_status);
if((int)$model->order_status === $model::ORDER_STATUS_READY_TO_PICKUP) {
if ((int)$model->order_type === $model::ORDER_TYPE_PICKUP) {
return 'Ready To Pickup';
} else {
return 'Ready To Delivery';
}
}
return $this->getDeliveryStatus((int)$model->order_status);
},
'delivery_type' => 'delivery_option',
'delivery_type_label' => function (self $model) {
return $this->getDeliveryType((int)$model->delivery_option);
},
'order_type' => function (self $model) {
return $model->order_type;
},
'order_type_label' => function (self $model) {
return $this->getOrderType((int)$model->order_type);
},
'postal_code' => function (self $model) {
return $this->isNull($model->postal_code);
},
'package_price' => function (self $model) {
$price = $model->package_price;
return empty($price) ? 0 : $price;
},
'cgst_amount' => function (self $model) {
$vat_cgst = $model->vat_cgst;
return empty($vat_cgst) ? 0 : $vat_cgst;
},
'sgst_amount' => function (self $model) {
$vat_sgst = $model->vat_sgst;
return empty($vat_sgst) ? 0 : $vat_sgst;
},
'igst_amount' => function (self $model) {
$vat_igst = $model->vat_igst;
return empty($vat_igst) ? 0 : $vat_igst;
},
'order_id',
'delivery_timing' => 'delivery_option',
'later_datetime' => 'pickup_delivery_date_time',
'delivery_minutes' => function (self $model) {
return $this->isNull($model->delivery_minutes);
},
'product_details' => function (self $model) {
$modelItemName = $model->getOrderItemName();
return $modelItemName;
},
'products',
'product_price' => function (self $model) {
return [];
},
'product_total_price' => function (self $model) {
return [];
},
'product_quantity' => function (self $model) {
return OrderItem::find()->where(['order_id' => $model->order_id])->count();
}
];
}
public function getUserAddress()
{
$address = UserAddress::find()->select(['UAL.*','UA.latitude','UA.longitude'])
->alias('UA')
->leftJoin(['UAL' => UserAddressLang::tableName()],'UA.user_address_id = UAL.user_address_id')
->where(['UA.user_address_id' => $this->user_address_id])
->one();
return $address;
}
/**
*
* @return type
*/
public function getOrderItemName()
{
$orderItemName = VendorOrderItem::find()->alias('OI')
->select(['OI.quantity', 'OI.item_total_price','OI.item_price','OI.special_instructions', 'OIM.item_image_path', 'OI.order_item_id','IL.item_name'])
->leftJoin(['OIM' => OrderItemImage::tableName()], 'OIM.order_item_id = OI.order_item_id')
->leftJoin(['IL' => ItemLang::tableName()], 'IL.item_id = OI.item_id')
->where(['OI.order_id' => $this->order_id]);
//Item::selectTranslation($orderItemName);
return $orderItemName->all();
}
/**
*
* @param type $index
* @return $array
*/
public function getDeliveryType($index = '')
{
$deliveryTypeData = [
1 => Yii::t('backend', 'ASAP'),
2 => Yii::t('backend', 'Later'),
];
($index == '') ? ($deliveryTypeData = $deliveryTypeData) : ($deliveryTypeData = ArrayHelper::getValue($deliveryTypeData, $index));
return $deliveryTypeData;
}
/**
* @param $status
* @return string
*/
public function getDeliveryStatus($status)
{
$statusLabel = '';
switch ($status) {
case self::ORDER_STATUS_DELIVERYBOY_ACCEPTED:
$statusLabel = 'Confirmed';
break;
case self::ORDER_STATUS_DELIVERYBOY_ASSIGNED:
$statusLabel = 'Confirmed';
break;
case self::ORDER_STATUS_PENDING:
$statusLabel = 'Pending';
break;
case self::ORDER_STATUS_ACCEPTED:
$statusLabel = 'Confirmed';
break;
case self::ORDER_STATUS_PREPARED:
$statusLabel = 'Preparation';
break;
case self::ORDER_STATUS_DELIVERED:
$statusLabel = 'Delivered';
break;
case self::ORDER_STATUS_REJECTED:
$statusLabel = 'Cancelled';
break;
case self::ORDER_STATUS_READY_TO_PICKUP:
$statusLabel = 'Ready To Pickup';
break;
case self::ORDER_STATUS_ONTHEWAY:
$statusLabel = 'Order on its way';
break;
case self::ORDER_STATUS_DELIVERYBOY_REQUESTED:
$statusLabel = 'Confirmed';
break;
}
return $statusLabel;
}
public function getNextDeliveryStatus($status,$order_type) {
$statusLabel = '';
switch ($status) {
case self::ORDER_STATUS_DELIVERYBOY_ACCEPTED:
$statusLabel = 'Confirm';
break;
case self::ORDER_STATUS_DELIVERYBOY_ASSIGNED:
$statusLabel = 'Confirm';
break;
case self::ORDER_STATUS_ACCEPTED:
$statusLabel = 'Preparation';
break;
case self::ORDER_STATUS_PREPARED:
if($order_type == Order::ORDER_TYPE_DELIVERY) {
$statusLabel = 'Ready to pickup';
} else {
$statusLabel = 'Delivered';
}
break;
}
return $statusLabel;
}
public function getOrderType($type) {
$type_label = '';
if($type == Order::ORDER_TYPE_DELIVERY) {
$type_label = yii::t('api','Delivery');
} else if($type == Order::ORDER_TYPE_PICKUP) {
$type_label = yii::t('api','Pickup');
} else {
$type_label = Yii::t('api', 'Other');
}
return $type_label;
}
/**
* @param $value
* @return string
*/
private function isNull($value)
{
return $value === null ? '' : $value;
}
}