Example #1
0
 public function getGoodsListAttribute()
 {
     //$goodsList=OrderGoods::with('goods')->where('order_id',$this->id)->get();
     $goodsList = OrderGoods::where('order_id', $this->id)->get();
     if ($goodsList == null) {
         return '';
     }
     return $goodsList->toArray();
 }
Example #2
0
 public function index(Request $request)
 {
     $start = $request->input('start', 0);
     $length = $request->input('length', 5);
     $draw = $request->input('draw', 1);
     $presell = $request->input('presell');
     if ($presell != 0) {
         $order = OrderGoods::join('orders', 'order_goods.order_id', '=', 'orders.id')->join('goods', 'order_goods.goods_id', '=', 'goods.id')->where('goods.is_presell', '=', 1)->orderBy('orders.is_remind', 'desc')->orderBy('orders.id', 'desc')->groupBy('order_goods.order_id')->select('orders.id', 'orders.out_trade_no', 'orders.user_id', 'orders.consignee', 'orders.shipping_address', 'orders.mobile', 'orders.total_fee', 'orders.status', 'orders.is_remind');
     } else {
         $order = Order::orderBy('orders.is_remind', 'desc')->orderBy('orders.id', 'desc')->select('orders.id', 'orders.out_trade_no', 'orders.user_id', 'orders.consignee', 'orders.shipping_address', 'orders.mobile', 'orders.total_fee', 'orders.status', 'orders.is_remind');
     }
     $out_trade_no = $request->input('number');
     if ($out_trade_no != null && $out_trade_no != '') {
         $order = $order->where('orders.out_trade_no', '=', $out_trade_no);
     }
     $status = $request->input('status');
     if ($status != -1) {
         if ($status == 5) {
             $order = $order->where(function ($query) {
                 $query->where('orders.status', '=', 5)->orWhere('orders.status', '=', 6);
             });
         } else {
             $order = $order->where('orders.status', '=', $status);
         }
     }
     $total = $order->count();
     $order = $order->skip($start)->take($length);
     $orders = $order->get();
     $arrOrdersList = [];
     foreach ($orders as $g) {
         $arrGoods['id'] = $g->id;
         $arrGoods['out_trade_no'] = $g->out_trade_no;
         $arrGoods['user_id'] = $g->user_id;
         $arrGoods['consignee'] = $g->consignee;
         $arrGoods['shipping_address'] = $g->shipping_address;
         $arrGoods['mobile'] = $g->mobile;
         $arrGoods['total_fee'] = $g->total_fee;
         $arrGoods['status'] = $g->status;
         $arrGoods['is_remind'] = $g->is_remind;
         //$arrGoods['express_fee']=$g->express_fee;
         $arrOrdersList[] = $arrGoods;
     }
     echo json_encode(array("draw" => intval($draw), "recordsTotal" => intval($total), "recordsFiltered" => intval($total), "data" => $arrOrdersList));
 }
Example #3
0
 public function delete($id)
 {
     //检查关联
     $banner = BannerGoods::where('goods_id', $id)->first();
     if ($banner != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到banner,对应id为' . $banner->banner_id;
         echo json_encode($ret);
         return;
     }
     $activity = ActivityClassificationGoods::where('goods_id', $id)->first();
     if ($activity != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到活动商品,对应id为' . $activity->activity_classification_id;
         echo json_encode($ret);
         return;
     }
     $conversion = ConversionGoods::where('goods_id', $id)->first();
     if ($conversion != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到爆品推荐,对应id为' . $conversion->id;
         echo json_encode($ret);
         return;
     }
     $free = FreePostGoods::where('goods_id', $id)->first();
     if ($free != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到包邮专区,对应id为' . $free->free_posts_id;
         echo json_encode($ret);
         return;
     }
     $home = HomeButtonGoods::where('goods_id', $id)->first();
     if ($home != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到首页按钮,对应id为' . $home->home_button_id;
         echo json_encode($ret);
         return;
     }
     $order = OrderGoods::where('goods_id', $id)->first();
     if ($order != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已加入用户订单';
         echo json_encode($ret);
         return;
     }
     $theme = ThemeGoods::where('goods_id', $id)->first();
     if ($theme != null) {
         $ret['meta']['code'] = 0;
         $ret['meta']['error'] = '删除失败,该商品已绑定到主题,对应id为' . $theme->theme_id;
         echo json_encode($ret);
         return;
     }
     Goods::find($id)->delete();
     $ret['meta']['code'] = 1;
     echo json_encode($ret);
 }
Example #4
0
 /**
  *
  * @SWG\Api(
  *   path="/orders/{out_trade_no}",
  *   @SWG\Operation(
  *     method="PUT", summary="更新订单状态", notes="更新订单状态",type="string",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="out_trade_no",
  *         description="订单号",
  *         paramType="path",
  *         required=true,
  *         type="string"
  *     ),
  *     @SWG\Parameter(
  *         name="status",
  *         description="状态 2:取消订单 4:确认收货",
  *         paramType="query",
  *         required=true,
  *         type="string"
  *     )
  *   )
  * )
  */
 public function update(Request $request, $out_trade_no)
 {
     DB::beginTransaction();
     $response = new BaseResponse();
     $status = $request->input('status');
     if ($out_trade_no == null) {
         $response->Code = BaseResponse::CODE_ERROR_CHECK;
         $response->Message = '缺少参数';
         return $response->toJson();
     }
     $order = Order::where('out_trade_no', $out_trade_no)->first();
     if ($order == null) {
         $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
         $response->Message = '未找到对应项目';
         return $response->toJson();
     }
     $order->status = $status;
     $order->save();
     if ($status == 2) {
         $goodsList = OrderGoods::where('order_id', $order->id)->get()->toArray();
         foreach ($goodsList as $g) {
             $goods = Goods::find($g['goods_id']);
             if ($goods == null) {
                 $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                 $response->Message = "商品不存在";
                 DB::rollback();
                 return $response->toJson();
             }
             $goods->num = $goods->num + $g['num'];
             $goods->save();
             //是否是新用户福利商品
             $homeButtonGoods = HomeButtonGoods::where('goods_id', $goods->id)->first();
             if ($homeButtonGoods != null) {
                 //判断是否购买过
                 $homeButtonGoodsBuyRecords = HomeButtonGoodsBuyRecords::where('home_button_goods_id', $homeButtonGoods->id)->first();
                 if ($homeButtonGoodsBuyRecords != null) {
                     $homeButtonGoodsBuyRecords->delete();
                 }
             }
         }
     }
     DB::commit();
     return $response->toJson();
 }