コード例 #1
0
ファイル: Goods.php プロジェクト: Lazybin/huisa
 public function getIsYuehuiAttribute()
 {
     if (ActivityClassificationGoods::where('goods_id', $this->id)->count() > 0 || FreePostGoods::where('goods_id', $this->id)->count() > 0 || ConversionGoods::where('goods_id', $this->id)->count() > 0 || HomeButtonGoods::where('goods_id', $this->id)->count() > 0) {
         return 1;
     } else {
         return 0;
     }
 }
コード例 #2
0
 /**
  *
  * @SWG\Api(
  *   path="/activity_classifications/{id}",
  *   @SWG\Operation(
  *     method="GET", summary="获得分类详情", notes="获得分类详情",
  *     type="array",
  *     @SWG\Items("ActivityClassificationGoods"),
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="id",
  *         description="分类id",
  *         paramType="path",
  *         required=true,
  *         allowMultiple=false,
  *         type="integer",
  *     ),@SWG\Parameter(
  *         name="PageNum",
  *         description="分页开始位置",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=1
  *     ),@SWG\Parameter(
  *         name="PerPage",
  *         description="取得长度",
  *         paramType="query",
  *         required=false,
  *         allowMultiple=false,
  *         type="integer",
  *         defaultValue=10
  *     )
  *
  *   )
  * )
  */
 public function show(Request $request, $id)
 {
     $start = $request->input('PageNum', 0);
     $length = $request->input('PerPage', 5);
     $start = ($start - 1) * $length;
     $response = new BaseResponse();
     $goods_list = ActivityClassificationGoods::where('activity_classification_id', $id);
     $total = $goods_list->count();
     $goods_list = $goods_list->skip($start)->take($length)->orderBy('id', 'desc');
     $response->rows = $goods_list->get();
     $response->total = $total;
     return $response->toJson();
 }
コード例 #3
0
ファイル: GoodsController.php プロジェクト: Lazybin/huisa
 public function update(Request $requests, $id)
 {
     $params = $requests->all();
     $goods = Goods::find($id);
     if ($goods != null) {
         $properties = [];
         foreach ($params as $k => $v) {
             $pos = strpos($k, 'property_');
             if ($pos !== false) {
                 $id = substr($k, strlen('property_'), strlen($k));
                 if (is_numeric($id)) {
                     $properties[$id] = $v;
                     unset($params[$k]);
                 }
             }
         }
         $params['category_id'] = $params['category'];
         unset($params['category']);
         unset($params['_token']);
         $images = $params['images'];
         unset($params['images']);
         unset($params['uploadImages']);
         if ($requests->hasFile('coverImage')) {
             $file = $requests->file('coverImage');
             $fileName = time() . '.' . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/upload', $fileName);
             $params['cover'] = '/upload/' . $fileName;
         }
         unset($params['coverImage']);
         if ($requests->hasFile('evaluationPersonImage')) {
             $file = $requests->file('evaluationPersonImage');
             $fileName = md5(uniqid()) . '.' . $file->getClientOriginalExtension();
             $file->move(base_path() . '/public/upload', $fileName);
             $params['evaluation_person_image'] = '/upload/' . $fileName;
         }
         unset($params['evaluationPersonImage']);
         $params['goods_description'] = $params['description'];
         unset($params['description']);
         $activityClassification = $params['activityClassification'];
         unset($params['activityClassification']);
         $freePost = $params['freePost'];
         unset($params['freePost']);
         foreach ($params as $n => $p) {
             $goods->{$n} = $p;
         }
         $goods->save();
         ActivityClassificationGoods::where('goods_id', $goods->id)->delete();
         if ($activityClassification != -1) {
             ActivityClassificationGoods::create(['activity_classification_id' => $activityClassification, 'goods_id' => $goods->id]);
         }
         FreePostGoods::where('goods_id', $goods->id)->delete();
         if ($freePost != -1) {
             FreePostGoods::create(['free_posts_id' => $freePost, 'goods_id' => $goods->id]);
         }
         GoodsCategoryProperty::where('goods_id', $goods->id)->delete();
         foreach ($properties as $key => $value) {
             $arr = explode(',', $value);
             foreach ($arr as $i) {
                 GoodsCategoryProperty::create(['category_property_id' => $key, 'goods_id' => $goods->id, 'value' => $i]);
             }
         }
         GoodsImages::where('goods_id', $goods->id)->delete();
         $len = strlen($images);
         if ($len > 0) {
             $images = substr($images, 0, $len - 1);
             $images = explode(',', $images);
             foreach ($images as $i) {
                 $goodsImage = new GoodsImages();
                 $goodsImage->goods_id = $goods->id;
                 $goodsImage->image_id = $i;
                 $goodsImage->save();
             }
         }
     }
     return redirect()->action('Admin\\GoodsController@show');
 }
コード例 #4
0
 public function delete($id)
 {
     ActivityClassificationGoods::find($id)->delete();
     $ret['meta']['code'] = 1;
     echo json_encode($ret);
 }
コード例 #5
0
ファイル: OrdersController.php プロジェクト: Lazybin/huisa
 /**
  *
  * @SWG\Api(
  *   path="/orders",
  *   @SWG\Operation(
  *     method="POST", summary="生成订单", notes="生成订单",type="Order",
  *     @SWG\ResponseMessage(code=0, message="成功"),
  *     @SWG\Parameter(
  *         name="order_info",
  *         description="提交的订单信息",
  *         paramType="body",
  *         required=true,
  *         type="newOrderParams"
  *     )
  *   )
  * )
  */
 public function store(Request $request)
 {
     DB::beginTransaction();
     $response = new BaseResponse();
     $content = json_decode($request->getContent(false));
     $accessToken = $content->accessToken;
     $goodsList = $content->goodsList;
     $total_fee = 0;
     $coupon_total = 0;
     foreach ($goodsList as $g) {
         $goods = Goods::find($g->goods_id);
         if ($goods != null) {
             //检查是否购买过新用户福利(0元福利)
             //是否是新用户福利商品
             $homeButtonGoods = HomeButtonGoods::where('goods_id', $goods->id)->first();
             if ($homeButtonGoods != null) {
                 //判断是否购买过
                 $homeButtonGoodsBuyRecords = HomeButtonGoodsBuyRecords::where('home_button_goods_id', $homeButtonGoods->id)->where('user_id', $content->user_id)->first();
                 if ($homeButtonGoodsBuyRecords != null) {
                     $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                     $response->Message = "商品" . $goods->name . "为新用户福利,只能购买一次,您已经购买过了";
                     DB::rollback();
                     return $response->toJson();
                 } else {
                     $newHomeButtonGoodsRecords = new HomeButtonGoodsBuyRecords();
                     $newHomeButtonGoodsRecords->user_id = $content->user_id;
                     $newHomeButtonGoodsRecords->home_button_goods_id = $homeButtonGoods->id;
                     $newHomeButtonGoodsRecords->save();
                 }
             }
             //如果在约惠列表里,不减去优惠金额 要扣券
             if (ActivityClassificationGoods::where('goods_id', $goods->id)->count() > 0 || FreePostGoods::where('goods_id', $goods->id)->count() > 0 || ConversionGoods::where('goods_id', $goods->id)->count() > 0) {
                 $total_fee = $total_fee + $goods->price * $g->num;
                 $coupon_total = $coupon_total + $goods->coupon_amount * $g->num;
                 $goods->num = $goods->num - $g->num;
                 if ($goods->num < 0) {
                     $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                     $response->Message = "商品库存不够";
                     DB::rollback();
                     return $response->toJson();
                 }
                 $goods->save();
                 continue;
             }
             if ($g->use_coupon == 1) {
                 $total_fee = $total_fee + $goods->price * $g->num - $goods->coupon_amount * $g->num;
                 $coupon_total = $coupon_total + $goods->coupon_amount * $g->num;
             } else {
                 $total_fee = $total_fee + $goods->price * $g->num;
             }
             $goods->num = $goods->num - $g->num;
             if ($goods->num < 0) {
                 $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
                 $response->Message = "商品库存不够";
                 DB::rollback();
                 return $response->toJson();
             }
             $goods->save();
         } else {
             $response->Code = BaseResponse::CODE_ERROR_BUSINESS;
             $response->Message = "get goods failed!";
             DB::rollback();
             return $response->toJson();
         }
     }
     unset($content->goodsList);
     //        DB::rollback();s
     //        echo $coupon_total;exit;
     //检测礼券充足
     $apiParam = ['accessToken' => $accessToken, 'coupon' => $coupon_total];
     $res = $this->post('/zhmf/member/consumerCoupon/isCouponEnough', $apiParam);
     $res = json_decode($res);
     if ($res->Code == 0 && $res->Data->enough == false) {
         $response->Code = -1;
         $response->Message = "礼券不足";
         DB::rollback();
         return $response->toJson();
     }
     if ($total_fee <= 0) {
         $total_fee = 0;
     }
     $content->total_fee = $total_fee;
     $content->shipping_fee = 10;
     //总运费
     $content->out_trade_no = $this->buildOrderNo();
     if ($total_fee == 0) {
         $content->status = 1;
     }
     $order = Order::create((array) $content);
     $useCouponRecords = new UseCouponRecords();
     $useCouponRecords->user_id = $content->user_id;
     $useCouponRecords->order_id = $order->id;
     $useCouponRecords->access_token = $accessToken;
     $useCouponRecords->coupon = $coupon_total;
     if ($total_fee == 0) {
         $useCouponRecords->status = 2;
         $apiParam = ['accessToken' => $useCouponRecords->access_token, 'coupon' => $useCouponRecords->coupon, 'orderId' => $content->out_trade_no];
         $res = $this->post('/zhmf/member/consumerCoupon/useCoupon', $apiParam);
         $res = json_decode($res);
         if ($res->Code == 0) {
             $useCouponRecords->status = 1;
         }
     } else {
         $useCouponRecords->status = 0;
     }
     $useCouponRecords->save();
     foreach ($goodsList as $v) {
         $orderGoods = new OrderGoods();
         $orderGoods->order_id = $order->id;
         $orderGoods->goods_id = $v->goods_id;
         $orderGoods->num = $v->num;
         $orderGoods->properties = json_encode($v->properties);
         if (isset($v->message)) {
             $orderGoods->message = $v->message;
         }
         $orderGoods->save();
     }
     $response->Data = $order;
     DB::commit();
     return $response->toJson();
     //var_dump($content);
     //echo $this->sign_request(['array'],'../config/rsa_private_key.pem');
 }