當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Order::generateOrderSn方法代碼示例

本文整理匯總了PHP中common\models\Order::generateOrderSn方法的典型用法代碼示例。如果您正苦於以下問題:PHP Order::generateOrderSn方法的具體用法?PHP Order::generateOrderSn怎麽用?PHP Order::generateOrderSn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在common\models\Order的用法示例。


在下文中一共展示了Order::generateOrderSn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: create

 /**
  * 創建訂單
  * 
  * @param string $runValidation
  * @throws \Exception
  * @return boolean
  */
 public function create($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     if ($this->_store->status === Store::STATUS_REST) {
         throw new \Exception('該店鋪休息中…');
     }
     $volume = Yii::$app->user->identity->getCartGoodsRealVolume($this->_store->id);
     if ($this->_store->has_least && $this->_store->least_val > $volume) {
         throw new \Exception('購物車商品未滿起送價!');
     }
     if (empty($this->_cartGoodsList)) {
         throw new \Exception('當前購物車為空!');
     }
     foreach ($this->_cartGoodsList as $cartGoods) {
         if ($cartGoods->isExpired) {
             throw new \Exception('商品“' . $cartGoods->goods->name . '”已失效!請您刪除該商品然後繼續。');
         }
         if ($cartGoods->isTooMuch) {
             throw new \Exception('商品“' . $cartGoods->goods->name . '”數量已超出庫存數量!請返回購物車中修改。');
         }
     }
     $transaction = Yii::$app->db->beginTransaction();
     try {
         $order = new Order();
         $order->generateOrderSn();
         $order->user_id = Yii::$app->user->id;
         $order->store_id = $this->_store->id;
         $order->school_id = $this->_store->school_id;
         $order->status = $this->payment === Order::PAYMENT_OFFLINE ? Order::STATUS_UNSHIPPED : Order::STATUS_UNPAID;
         $order->payment = $this->payment;
         $order->fee = $volume;
         $order->preferential = $this->preferential;
         $order->down_val = null;
         $order->gift_val = null;
         $order->new_down_val = null;
         $order->book_time = $this->bookTime == 0 ? null : $this->bookTime;
         $order->remark = $this->remark;
         $order->cancelled_msg = null;
         // 判斷優惠類型
         switch ($this->preferential) {
             case Order::PREFERENTIAL_DOWN:
                 if ($this->_store->has_down && $order->fee >= $this->_store->down_upper) {
                     $order->real_fee = bcsub($order->fee, $this->_store->down_val, 2);
                     $order->down_val = $this->_store->down_val;
                 }
                 break;
             case Order::PREFERENTIAL_GIFT:
                 if ($this->_store->has_gift && $order->fee >= $this->_store->gift_upper) {
                     $order->real_fee = $order->fee;
                     $order->gift_val = $this->_store->gift_val;
                 }
                 break;
             case Order::PREFERENTIAL_NONE:
                 $order->real_fee = $order->fee;
                 break;
             default:
                 throw new \Exception('優惠選擇錯誤!');
         }
         // 新用戶立減優惠
         if (Yii::$app->params['enableNewDown'] && $this->newDown && $order->fee >= Yii::$app->params['newDownUpper'] && Yii::$app->user->identity->has_new_down) {
             $order->new_down_val = Yii::$app->params['newDownVal'];
             $order->real_fee = bcsub($order->real_fee, $order->new_down_val, 2);
             Yii::$app->user->identity->has_new_down = 0;
             if (!Yii::$app->user->identity->save(false)) {
                 throw new \Exception('用戶錯誤!');
             }
             if ($order->real_fee < 0) {
                 $order->real_fee = 0;
                 $order->status = ORDER::STATUS_UNSHIPPED;
             }
         }
         if (!$order->save(false)) {
             throw new \Exception('訂單錯誤!');
         }
         $this->_order = $order;
         $address = OrderAddress::createDuplicate($this->addressId);
         $address->order_id = $order->id;
         if (!$address->save(false)) {
             throw new \Exception('收貨地址錯誤!');
         }
         foreach ($this->_cartGoodsList as $cartGoods) {
             $goods = OrderGoods::createDuplicate($cartGoods->goods_id);
             $goods->order_id = $order->id;
             $goods->count = $cartGoods->count;
             if (!$goods->save(false)) {
                 throw new \Exception('訂單商品錯誤!');
             }
             if (!$cartGoods->goods->moveSurplus(-$goods->count, "創建訂單:{$order->order_sn}。")) {
                 throw new \Exception('商品錯誤!');
             }
         }
//.........這裏部分代碼省略.........
開發者ID:daixianceng,項目名稱:xiaoego.com,代碼行數:101,代碼來源:CreateOrderForm.php


注:本文中的common\models\Order::generateOrderSn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。