Exemplo n.º 1
0
 /**
  * 商品上/下架
  * @author Hanxiang
  * @param $id item_id
  * @param $to status
  * @return view
  */
 public function changeShelfStatus($id)
 {
     $item = Item::find($id);
     if (!$item) {
         abort(404);
     }
     //Begin modify by minco
     if ($item->shelf_status == Item::SHELF_STATUS_YES) {
         $item->shelf_status = Item::SHELF_STATUS_NO;
     } else {
         $item->shelf_status = Item::SHELF_STATUS_YES;
     }
     //End modify
     $item->save();
     // TODO:与商品关联的其他状态
     return redirect()->route('adminItems')->with('success_tips', "操作成功");
 }
Exemplo n.º 2
0
 /**
  * 核实订单,库存
  * @return string
  * @author zhengqian@dajiayao.cc
  */
 public function check()
 {
     $inputData = $this->inputData->only('items', 'shopShortId');
     $items = $inputData['items'];
     if (!is_array($items)) {
         return RestHelp::encodeResult(22000, 'item must be array');
     }
     $arrRet = array();
     $postageFlag = 0;
     $totalPrice = 0;
     $objShop = Shop::getShopByShort($inputData['shopShortId']);
     if (!$objShop) {
         return RestHelp::encodeResult(21000, "shop not found");
     }
     $shelfItems = $objShop->getItemsOnShelf();
     $resultFlag = true;
     $warning = '';
     foreach ($items as $k => $item) {
         $arrRet[$k]['result'] = true;
         $arrRet[$k]['id'] = $item['id'];
         $objItem = Item::find($item['id']);
         if ($objItem->sale_status == Item::SALE_STATUS_NO) {
             $arrRet[$k]['result'] = false;
             $resultFlag = false;
             $warning = sprintf("%s 已停售", $objItem->name);
             break;
         }
         if ($objItem->shelf_status == Item::SHELF_STATUS_NO or !array_key_exists($objItem->id, $shelfItems)) {
             $arrRet[$k]['result'] = false;
             $resultFlag = false;
             $warning = sprintf("%s 已下架", $objItem->name);
             break;
         }
         if ($objItem->stock < $item['count']) {
             $arrRet[$k]['result'] = false;
             $resultFlag = false;
             $warning = sprintf("%s 库存不够", $objItem->name);
             break;
         }
         if ($objItem->postage_type == Item::POSTAGE_TYPE_BUYER) {
             $postageFlag++;
         }
         $totalPrice += $objItem->price * $item['count'];
     }
     $postage = $postageFlag ? $this->settingService->getSettingByKey(Setting::KEY_ORDER_POSTAGE)->value : 0;
     $grandTotal = $totalPrice + $postage;
     //检查合法后将价格,总价放入DB,后期用于检查
     if ($resultFlag) {
         $user = Buyer::find($this->buyerId)->wxUser;
         WxUserKv::setValue($user->id, WxUserKv::BUYER_CHECK_PRICE, $grandTotal);
     }
     return RestHelp::success(['result' => $resultFlag, 'postage' => $postage, 'grandTotal' => $grandTotal, 'warning' => $warning, 'detail' => $arrRet]);
 }
Exemplo n.º 3
0
 /**
  * 订单详情
  * @author Hanxiang
  * @param $number 订单号
  * @return view
  */
 public function detail($number)
 {
     $order = Order::where('order_number', $number)->first();
     if (count($order) == 0) {
         abort(404);
     }
     // Buyer Info
     $buyer = Buyer::find($order->buyer_id);
     if (count($buyer) == 0) {
         $buyer = new \stdClass();
         //TODO
         $wxUser = new \stdClass();
         //TODO
     } else {
         $wxUser = $buyer->wxUser;
     }
     $total = 0;
     $quantity = 0;
     $orderItems = OrderItem::where('order_id', $order->id)->get();
     foreach ($orderItems as $oi) {
         $total += $oi->item_total;
         $quantity += $oi->quantity;
         $supplier = Item::find($oi->item_id)->supplier;
         $oi->supplier = $supplier;
     }
     $order->totalPrice = $total;
     $order->totalQuantity = $quantity;
     $expresses = Express::where('status', 1)->orderBy('sort')->get();
     $express = Express::find($order->express_id);
     if (count($express) == 0) {
         $express = new \stdClass();
         $express->name = '';
     }
     $order->expressObj = $express;
     $commission = $order->commission;
     if (!$commission) {
         $commission = new \stdClass();
         $commission->amount = 0;
         $order->commission = $commission;
     }
     return view('admin.orders.detail')->with('order', $order)->with('buyer', $buyer)->with('wxUser', $wxUser)->with('orderItems', $orderItems)->with('expresses', $expresses);
 }