Exemple #1
0
 public function createAction()
 {
     if (isset($_POST['ajax']) && isset($_POST['getshipping'])) {
         $shippings = Shipping::model()->cache()->findAllInArray();
         AF::setJsonHeaders('json');
         Message::echoJsonSuccess(array('message' => $shippings));
     }
     $model = new CampaignShipping();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['model']) && $_POST['model'] == 'Campship') {
         $model->fillFromArray($_POST);
         //$model->user_id_created = $this->user->user_id;
         //$model->user_id_updated = $this->user->user_id;
         //$model->updated = 'NOW():sql';
         //$model->created = 'NOW():sql';
         //$model->model_uset_id = $this->user->user_id;
         if (isset($_POST['ajax'])) {
             if ($model->save()) {
                 $link = AF::link(array('campship' => 'view'), array('campaign_id' => $model->campaign_id));
                 Message::echoJson('success', array('redirect' => $link));
             } else {
                 Message::echoJsonError(__('campship_not_created') . ' ' . $model->errors2string);
             }
             die;
         }
         $model->save();
         $this->redirect();
     }
     $this->addToPageTitle('Create Campaign Shipping');
     $this->render('create', array('model' => $model));
 }
 public function actionChngShiping()
 {
     $id = $_GET['id'];
     $carrier_id = $_GET['carrier_name'];
     $carrier_name = $_GET['carrier_id'];
     $Shipping = new Shipping();
     $item = $Shipping->GetShipping($id);
     if (!empty($item['carriers_id'])) {
         $carriers_id_arr = explode(', ', $item['carriers_id']);
         array_push($carriers_id_arr, $carrier_id);
         $res = array_unique($carriers_id_arr);
         $final_carriers_id = implode(', ', $res);
     } else {
         $final_carriers_id = $carrier_id;
     }
     if (!empty($item['carrier_name'])) {
         $carriers_name_arr = explode('|', $item['carrier_name']);
         array_push($carriers_name_arr, $carrier_id);
         $res = array_unique($carriers_name_arr);
         $final_carriers_name = implode('|', $res);
     } else {
         $final_carriers_name = $carrier_name;
     }
     $post = Shipping::model()->findByPk($id);
     $post->carriers_id = $final_carriers_id;
     $post->carrier_name = $final_carriers_name;
     // $Shipping->route = $item['route'];
     //  $Shipping->comment = $item['comment'];
     $r = $post->save();
     //  var_dump($post->errors);die;
 }
Exemple #3
0
 public function getShippingList()
 {
     $data = Shipping::model()->findAll();
     if (empty($data)) {
         return '';
     }
     $list = array();
     foreach ($data as $row) {
         $list[$row->id] = $row->getAttributes();
     }
     return $list;
 }
 public function actionDel()
 {
     $res = array('statusCode' => 200, 'message' => '删除成功!');
     try {
         if (empty($_REQUEST['id'])) {
             throw new Exception("数据错误,id不能为空!", 1);
         }
         $flag = Shipping::model()->deleteByPk($_REQUEST['id']);
         if (!$flag) {
             throw new exception('删除失败');
         }
     } catch (Exception $e) {
         $res['statusCode'] = 300;
         $res['message'] = '删除失败【' . $e->getMessage() . '】';
     }
     $res['callbackType'] = 'reloadTab';
     $res['forwardUrl'] = '/manage/shipping/index';
     $this->ajaxDwzReturn($res);
 }
Exemple #5
0
 function viewAction()
 {
     $this->filter();
     $pagination = new Pagination(array('action' => $this->action, 'controller' => $this->controller, 'params' => $this->params));
     $models = AFActiveDataProvider::models('CampaignProduct', $this->params, $pagination);
     $dataProvider = $models->getAll();
     $camprodModel = new CampaignProduct();
     $camprodModel->campaign_id = AF::get($this->params, 'campaign_id', 0);
     $productsUpsellsMain = $camprodModel->getUpsellProducts();
     //eg: Array ( [321] => Array ( [product_id] => 321 [yes_upsell_id] => 0 ) )
     //fb($productsUpsellsMain);
     $arr = array();
     foreach ($productsUpsellsMain as $upsellArray) {
         $arr[] = $upsellArray['yes_upsell_id'];
     }
     // $arr[0] = 0
     //$upsellModel = new Upsell();
     $productsUpsells = array();
     while (!empty($arr)) {
         $upsels = Upsells::getUpsellByArrayIDs($arr);
         $arr = array();
         foreach ($upsels as $item) {
             $productsUpsells[$item['upsell_id']] = $item;
             if ($item['yes_upsell_id'] && !isset($productsUpsells[$item['yes_upsell_id']])) {
                 $arr[] = $item['yes_upsell_id'];
             }
             if ($item['no_upsell_id'] && !isset($productsUpsells[$item['no_upsell_id']])) {
                 $arr[] = $item['no_upsell_id'];
             }
         }
     }
     $products = Product::model()->cache()->findAllInArray();
     $shippings = Shipping::model()->cache()->findAllInArray();
     Assets::js('jquery.form');
     $this->addToPageTitle('Campaigns Products');
     $this->render('view', array('dataProvider' => $dataProvider, 'pagination' => $pagination, 'models' => $models, 'productsUpsells' => $productsUpsells, 'productsUpsellsMain' => $productsUpsellsMain, 'products' => $products, 'shippings' => $shippings, 'campaign_id' => AF::get($this->params, 'campaign_id')));
 }
 public function actionThank()
 {
     $user_id = Yii::app()->user->id;
     //check the billing / shipping values coresponding to this user
     $chkBillExist = Billing::model()->find('user_id = :user_id', array(':user_id' => $user_id));
     //echo "<pre>";
     //print_r($chkBillExist);
     if (empty($chkBillExist)) {
         //redirect back to checkout page
         Yii::app()->user->setFlash('showMsg', 'Your billing details are empty.');
         $this->redirect(array('shoppingCart/checkout'));
     }
     $chkShipExist = Shipping::model()->find('user_id = :user_id', array(':user_id' => $user_id));
     if (empty($chkShipExist)) {
         Yii::app()->user->setFlash('showMsg', 'Please fill your shipping details.');
         $this->redirect(array('shoppingCart/checkout'));
     }
     //end
     $model = new Reward();
     $orderModel = new Order();
     //check the session exist
     //check billing/ shipping session exist
     //finally placed the order
     //insert the cart in order table
     if (count($_SESSION['items']) > 0) {
         //get billing/shipping ids of login user
         $chkBillExist = Billing::model()->find('user_id = :user_id', array(':user_id' => $user_id));
         if (empty($chkBillExist)) {
         } else {
             $billAddId = $chkBillExist['id'];
         }
         //get shipping ids of login user
         $chkShipExist = Shipping::model()->find('user_id = :user_id', array(':user_id' => $user_id));
         if (empty($chkShipExist)) {
         } else {
             $shipAddId = $chkShipExist['id'];
         }
         $insertOrders = Yii::app()->db->createCommand()->insert('shop_order', array('user_id' => $user_id, 'shipping_address_id' => $billAddId, 'billing_address_id' => $shipAddId, 'ordering_done' => 1, 'grandtotal' => $_SESSION['grandTotalFinal']));
         $order_id = Yii::app()->db->getLastInsertID();
         foreach ($_SESSION['items'] as $key => $data) {
             //insert into order detail table
             $insertOrders = Yii::app()->db->createCommand()->insert('shop_order_detail', array('order_id' => $order_id, 'reward_id' => $data['id'], 'quantity' => $data['quantity']));
             $productRewardId = $data['id'];
             //get the existing quantity from db and add the posted quanity in it
             $getQuantity = "SELECT instock from reward where id = {$productRewardId}";
             $getQtyValue = Yii::app()->db->createCommand($getQuantity)->queryRow();
             $finalQuantity = $getQtyValue['instock'] - $data['quantity'];
             //update the quantity of each product shop by user
             $getResult = Yii::app()->db->createCommand()->update('reward', array('instock' => $finalQuantity), 'id=' . $data['id']);
         }
         //send email to admin and user
         $this->sendEmailToAll($order_id, $user_id);
         //end
         if (isset($_SESSION['items'])) {
             unset($_SESSION['items']);
             unset($_SESSION['grandTotalFinal']);
         }
     } else {
         Yii::app()->user->setFlash('showMsg', 'Shopping cart is empty.');
         $this->redirect(array('shoppingCart/view'));
     }
     //echo  Yii::app()->db->lastInsertID;
     //echo "----";
     //echo $last_id = Yii::app()->db->getLastInsertID();
     $this->render('thank', array('model' => $orderModel));
 }
Exemple #7
0
 /**
  * Returns the static model of the specified AR class.
  * Please note that you should have this exact method in all your AFActiveRecord descendants!
  * @param string $className active record class name.
  * @return FullShipping the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Shipping::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionChngShiping()
 {
     $id = $_GET['id'];
     $carrier_name = $_GET['carrier_name'];
     $carrier_id = $_GET['carrier_id'];
     $route = $_GET['route'];
     $Shipping = new Shipping();
     $items = $Shipping->GetShipping($id);
     $item = $items[0];
     if (!empty($item['carriers_id'])) {
         $carriers_id_arr = explode(', ', $item['carriers_id']);
         array_push($carriers_id_arr, $carrier_id);
         $result = array_unique($carriers_id_arr);
         $final_carriers_id = implode(', ', $result);
     } else {
         $final_carriers_id = $carrier_id;
     }
     if (!empty($item['carrier_name'])) {
         $carriers_name_arr = explode('|', $item['carrier_name']);
         array_push($carriers_name_arr, $carrier_name);
         $res = array_unique($carriers_name_arr);
         $final_carriers_name = implode('|', $res);
     } else {
         $final_carriers_name = $carrier_name;
     }
     $post = Shipping::model()->findByPk($id);
     $post->carriers_id = $final_carriers_id;
     $post->carrier_name = $final_carriers_name;
     $post->save();
     if ($post->save()) {
         $car = $Shipping->getCarrier($carrier_id);
         $carrier = $car[0];
         if (!empty($carrier['Direction'])) {
             $carriers_Direction_arr = explode(' | ', $carrier['Direction']);
             array_push($carriers_Direction_arr, $route);
             $carr = array_unique($carriers_Direction_arr);
             $final_route = implode(' | ', $carr);
         } else {
             $final_route = $route;
         }
         if (!empty($carrier['Direction_id'])) {
             $carriers_Direction_id_arr = explode(', ', $carrier['Direction_id']);
             array_push($carriers_Direction_id_arr, $id);
             $carrid = array_unique($carriers_Direction_id_arr);
             $final_id = implode(', ', $carrid);
         } else {
             $final_id = $id;
         }
         $Carrier = Carrier::model()->findByPk($carrier_id);
         $Carrier->Direction = $final_route;
         $Carrier->Direction_id = $final_id;
         $Carrier->save();
         // var_dump($Carrier->errors);die;
         $this->redirect(array('view', 'id' => $post->id));
     }
 }
Exemple #10
0
 /**
  *【用户中心】获取订单详情【用户中心订单展示】.
  * @param $userId
  * @param $order_sn
  */
 public function getUserOrderInfoBySn($userId, $order_sn)
 {
     if (empty($order_sn)) {
         throw new exception('订单号不能为空', 302);
     }
     $oInfo = Order::model()->findByAttributes(array('order_sn' => $order_sn));
     if (empty($oInfo)) {
         throw new exception('订单不存在', 302);
     }
     if ($userId != $oInfo->user_id) {
         throw new exception('订单和数据部匹配', 302);
     }
     $oInfo = $oInfo->getAttributes();
     $oInfo['order_status_txt'] = $this->getOrderStatus($oInfo['order_status']);
     $addressData = array($oInfo['province'], $oInfo['city'], $oInfo['district']);
     $addData = Region::model()->getRegionInfoByIds($addressData);
     if (!empty($addData)) {
         $oInfo['province_name'] = isset($addData[$oInfo['province']]) ? $addData[$oInfo['province']]['region_name'] : '';
         $oInfo['city_name'] = isset($addData[$oInfo['city']]) ? $addData[$oInfo['city']]['region_name'] : '';
         $oInfo['district_name'] = isset($addData[$oInfo['district']]) ? $addData[$oInfo['district']]['region_name'] : '';
     } else {
         $oInfo['province_name'] = '';
         $oInfo['city_name'] = '';
         $oInfo['district_name'] = '';
     }
     if ($oInfo['shipping_id']) {
         $shippingInfo = Shipping::model()->findByPk($oInfo['shipping_id']);
         $oInfo['shipping_name'] = empty($shippingInfo) ? '暂无快递信息' : $shippingInfo->shipping_name;
     }
     if ($oInfo['pay_id']) {
         $payInfo = Payment::model()->findByPk($oInfo['pay_id']);
         $oInfo['payment_name'] = empty($payInfo) ? '暂无快递信息' : $payInfo->pay_name;
     }
     $oInfo['need_pay_amount'] = $oInfo['product_amount'] + $oInfo['shipping_fee'] - $oInfo['coupon_amount'] - $oInfo['discount'] - $oInfo['pay_amount'];
     return $oInfo;
 }
Exemple #11
0
 /**
  * 订单发货【普通的订单发货】
  */
 public function actionSendOrder()
 {
     if (empty($_POST)) {
         $oInfo = Order::model()->findByPk($_REQUEST['id']);
         $shippingList = Shipping::model()->getShippingList();
         $viewData = array();
         $viewData['oInfo'] = $oInfo;
         $viewData['shippingList'] = $shippingList;
         $this->render('sendOrder', $viewData);
         exit;
     }
     $res = array('statusCode' => 200, 'message' => '发货成功!');
     try {
         $oInfo = Order::model()->findByPk($_REQUEST['id']);
         if (empty($oInfo)) {
             throw new exception('订单不存在!');
         } elseif (!in_array($oInfo['order_status'], array(1, 2, 4))) {
             throw new exception('订单状态错误!');
         }
         //保存发货信息到订单中
         $oInfo->shipping_id = intval($_REQUEST['shipping_id']);
         $oInfo->shipping_sn = intval($_REQUEST['shipping_sn']);
         $oInfo->shipping_time = time();
         $oInfo->order_status = 5;
         //已发货
         $oInfo->shipping_status = 1;
         //已发货
         $flag = $oInfo->save();
         if (empty($flag)) {
             throw new exception('保存运单信息到订单错误!', 500);
         }
         //保存订单的发货信息
         $m = new OrderShipping();
         $m->order_id = $_REQUEST['order_id'];
         $m->shipping_id = $_REQUEST['shipping_id'];
         $m->shipping_sn = $_REQUEST['shipping_sn'];
         $m->shipping_fee = $_REQUEST['shipping_fee'];
         $m->weight = $_REQUEST['weight'];
         $m->remark = $_REQUEST['remark'];
         $m->add_time = time();
         $flag = $m->save();
         if (empty($flag)) {
             throw new exception('保存运单信息错误!', 500);
         }
         $logData = array();
         $logData['order_id'] = $oInfo->id;
         $logData['type'] = 'AdminSend';
         $logData['msg'] = $_REQUEST['remark'];
         OrderLog::model()->addOrderLog($logData);
     } catch (exception $e) {
         $res['statusCode'] = 300;
         $res['message'] = '发货失败!【' . $e->getMessage() . '】';
     }
     $res['navTabId'] = 'orderList';
     $res['callbackType'] = 'closeCurrent';
     $res['forwardUrl'] = '/manage/order/index';
     $this->ajaxDwzReturn($res);
 }