/** * 订单列表 * @author Hanxiang * TODO */ public function index() { $user = Auth::user(); if ($user->role != User::ROLE_ADMIN) { return; //TODO } $orders = Order::where('id', '>', 0); $input = Input::all(); if (isset($input['status']) && $input['status'] > 0) { $orders = $orders->where('status', $input['status']); $status = $input['status']; } else { $status = -1; } $orders = $orders->orderBy('updated_at', 'desc')->paginate(20); foreach ($orders as $order) { $shop = $order->shop; $seller = Shop::find($shop->id)->seller; $wxUser = $seller->wxUser; $order->shopObj = $shop; $order->seller = $seller; $order->sellerWxUser = $wxUser; $order->buyer = Buyer::find($order->buyer_id); $order->buyerWx = $order->buyer->wxUser; // address $address = BuyerAddress::find($order->receiver_address_id)->addresses; $order->address = $address->getFather(); } return view('admin.orders.index')->with('status', $status)->with('orders', $orders); }
/** * 重新支付 * @return string * @author zhengqian@dajiayao.cc */ public function rePay() { $buyerId = $this->buyerId; $wxUser = Buyer::find($buyerId)->wxUser; if (!$wxUser) { return RestHelp::encodeResult(24000, "user illegality"); } $inputData = $this->inputData->all(); $validator = Validator::make($inputData, ['orderNumber' => 'required']); if ($validator->fails()) { return RestHelp::parametersIllegal($validator->messages()->first()); } $objOrder = Order::where('order_number', $inputData['orderNumber'])->first(); $objShop = Shop::find($objOrder->shop_id); if (!$objShop) { return RestHelp::encodeResult(21000, sprintf("shop short id %s not found in db", $objOrder->shop_id)); } //查找价格 $itemTotal = $objOrder->item_total; $grandTotal = $objOrder->grand_total; $payment = new Payment(); $payment->serial_number = OrderHelper::getPaymentSerialNumber(1); $payment->payment_number = ''; $payment->order_id = $objOrder->id; $payment->order_number = $inputData['orderNumber']; $payment->buyer_id = $buyerId; $payment->amount = $itemTotal; $payment->channel = Payment::PAYMENT_CHANNEL_PXX; $payment->type = Payment::PAYMENT_TYPE_WX; $payment->status = Order::PAY_STATUS_NO; $payment->save(); $subject = ''; //32 $body = ''; //128 foreach ($objOrder->orderItems as $orderItem) { $subject .= $orderItem->items->title . "*" . $orderItem->items->spec . "*" . $orderItem->quantity . ","; $body .= $orderItem->items->title . $orderItem->items->spec . $orderItem->quantity; } try { \Pingpp\Pingpp::setApiKey('sk_live_3dKEivmziedjzitFhaHL7gYF'); $ch = \Pingpp\Charge::create(array('order_no' => $payment->serial_number, 'app' => array('id' => 'app_XTOW5SXTWLGCGKef'), 'channel' => 'wx_pub', 'amount' => $grandTotal * 100, 'client_ip' => $this->inputData->ip(), 'currency' => 'cny', 'subject' => mb_substr($subject, 0, 32), 'body' => mb_substr($body, 0, 128), 'extra' => array('open_id' => $wxUser->openid))); } catch (\Exception $e) { return RestHelp::encodeResult(22003, $e->getMessage(), ['orderNum' => $inputData['orderNumber']]); } //写入paytmentLOg $paymentLog = new PaymentLog(); $paymentLog->payment_id = $payment->id; $paymentLog->channel = Payment::PAYMENT_CHANNEL_PXX; $paymentLog->request_data = $ch; $paymentLog->respond_data = ''; $paymentLog->save(); //保存支付流水号 $payment->payment_number = json_decode($ch)->id; $payment->save(); return RestHelp::success(['orderNumber' => $inputData['orderNumber'], 'paymentNumber' => $payment->serial_number, 'charge' => json_decode($ch, true)]); }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); // $this->call('UserTableSeeder'); DB::table('users')->truncate(); User::create(['id' => 1, 'username' => 'admin', 'email' => '*****@*****.**', 'password' => \Hash::make('11431143'), 'role' => User::ROLE_ADMIN, 'status' => User::STATUS_NORMAL]); DB::table('suppliers')->truncate(); Supplier::create(['id' => 1, 'username' => 'nanpufood', 'email' => '*****@*****.**', 'title' => '南浦集团', 'description' => '快速消费品综合代理和营销集团', 'service_phone' => '021-61923399', 'status' => 1]); //店铺 DB::table('shops')->truncate(); Shop::create(['id' => 1, 'short_id' => "yayao", 'province_id' => 310000, 'city_id' => 310100, 'county_id' => 310110, 'type' => 2, 'name' => '丫摇官方直营店', 'seller_id' => 1, 'thumbnail' => '', 'title' => '丫摇小店', 'subtitle' => '丫摇官方直营店', 'is_direct_sale' => Shop::IS_DIRECT_SALE_YES, 'banner' => '/images/banner_7.jpg', 'thumbnail' => '/images/logo_160.png']); //卖家 DB::table('sellers')->truncate(); \Dajiayao\Model\Seller::create(['id' => 1, 'wx_user_id' => 1, 'mobile' => '15995420354', 'parent_id' => 0, 'realname' => '丫摇官方店主']); \Dajiayao\Model\Seller::create(['id' => 2, 'wx_user_id' => 2, 'mobile' => '13800138000', 'parent_id' => 0, 'realname' => '测试店主']); //微信user DB::table('wx_users')->truncate(); \Dajiayao\Model\WxUser::create(['id' => 1, 'subscribe' => 1, 'openid' => 'oVtn9t9nmKQodGDQHLHfbHE_CDPI', 'nickname' => '小明', 'sex' => 1, 'city' => '苏州', 'country' => '中国', 'province' => '江苏', 'language' => 'zh_CN', 'role' => 2, 'headimgurl' => 'http://wx.qlogo.cn/mmopen/NWsF4EmJMsG8AeztibfdK5NWzAN6oX6PEwUOzeia9gzTvKW753aV0icuqTetiap4Tgf7q5sEdIaEstoa9hvvdlesuw/0']); \Dajiayao\Model\WxUser::create(['id' => 2, 'subscribe' => 1, 'openid' => 'oVtn9t9nmKQodGDQHLHfbHE_CDPI', 'nickname' => '小明2', 'sex' => 1, 'city' => '苏州', 'country' => '中国', 'province' => '江苏', 'language' => 'zh_CN', 'role' => 2, 'headimgurl' => 'http://wx.qlogo.cn/mmopen/NWsF4EmJMsG8AeztibfdK5NWzAN6oX6PEwUOzeia9gzTvKW753aV0icuqTetiap4Tgf7q5sEdIaEstoa9hvvdlesuw/0']); DB::table('items')->truncate(); Item::create(['id' => 1, 'name' => '星巴克 星冰乐咖啡', 'title' => '星巴克 星冰乐咖啡', 'code' => '1234', 'barcode' => '678952135', 'type_id' => 1, 'supplier_id' => 1, 'spec' => '摩卡味 281ml', 'weight' => 281, 'volume' => 281, 'price' => 18, 'market_price' => 28, 'stock' => 10000, 'shelf_status' => 1, 'sale_status' => 1, 'comment' => '真便宜啊', 'postage_type' => 2]); Item::create(['id' => 2, 'name' => '星巴克 星冰乐咖啡', 'title' => '星巴克 星冰乐 香草味 咖啡饮料 281ml*6美国进口', 'code' => '1235', 'barcode' => '678952185', 'type_id' => 1, 'supplier_id' => 1, 'spec' => '摩卡味 281ml * 6', 'weight' => 1686, 'volume' => 1686, 'price' => 108, 'market_price' => 168, 'stock' => 10000, 'shelf_status' => 1, 'sale_status' => 1, 'comment' => '真的很便宜啊', 'postage_type' => 2]); Item::create(['id' => 3, 'name' => '星巴克 星冰乐咖啡', 'title' => '星巴克 星冰乐 摩卡 咖啡饮料 281ml*6美国进口', 'code' => '1236', 'barcode' => '678952165', 'type_id' => 1, 'supplier_id' => 1, 'spec' => '摩卡味 281ml * 6', 'weight' => 1686, 'volume' => 1686, 'price' => 108, 'market_price' => 168, 'stock' => 10000, 'shelf_status' => 1, 'sale_status' => 1, 'comment' => '买买买啊', 'postage_type' => 2]); DB::table('shop_items')->truncate(); \Dajiayao\Model\ShopItem::create(["shop_id" => 1, "item_id" => 1, "stock" => 1000, "sort" => 1, "is_single" => 1]); \Dajiayao\Model\ShopItem::create(["shop_id" => 1, "item_id" => 2, "stock" => 1000, "sort" => 1, "is_single" => 1]); \Dajiayao\Model\ShopItem::create(["shop_id" => 1, "item_id" => 3, "stock" => 1000, "sort" => 1, "is_single" => 1]); DB::table('images')->truncate(); \Dajiayao\Model\Image::create(['url' => '/images/product.jpg', 'name' => '星巴克', 'type' => 1]); DB::table('item_images')->truncate(); \Dajiayao\Model\ItemImage::create(['item_id' => 1, 'image_id' => 1]); \Dajiayao\Model\ItemImage::create(['item_id' => 2, 'image_id' => 1]); \Dajiayao\Model\ItemImage::create(['item_id' => 3, 'image_id' => 1]); DB::table('item_type')->truncate(); ItemType::create(['id' => 1, 'name' => '饮料', 'sort' => 1]); ItemType::create(['id' => 2, 'name' => '酒类', 'sort' => 2]); ItemType::create(['id' => 3, 'name' => '坚果', 'sort' => 3]); DB::table('expresses')->truncate(); \Dajiayao\Model\Express::create(['name' => '圆通', 'code' => 'yuantong', 'website' => 'http://www.yto.net.cn', 'phone' => '95554']); \Dajiayao\Model\Express::create(['name' => '申通', 'code' => 'shentong', 'website' => 'http://www.sto.cn', 'phone' => '95543']); \Dajiayao\Model\Express::create(['name' => '韵达', 'code' => 'yunda', 'website' => 'http://www.yundaex.com', 'phone' => '400-821-6789']); \Dajiayao\Model\Express::create(['name' => '顺丰', 'code' => 'shunfeng', 'website' => 'http://www.sf-express.com', 'phone' => '95338']); DB::table('settings')->truncate(); \Dajiayao\Model\Setting::create(['key' => 'commissions:rate', 'name' => '佣金比例', 'value' => '0.1', 'description' => '佣金 = 实际成交价 x 佣金比例', 'parent_id' => 0]); \Dajiayao\Model\Setting::create(['key' => 'order:payment:duration', 'name' => '订单最晚支付时间', 'value' => '1', 'parent_id' => 0]); \Dajiayao\Model\Setting::create(['key' => 'order:auto:receive:duration', 'name' => '发货后自动收货时间', 'value' => '36', 'parent_id' => 0]); \Dajiayao\Model\Setting::create(['key' => 'order:postage', 'name' => '统一邮费', 'value' => '10', 'parent_id' => 0]); DB::table('buyers')->truncate(); \Dajiayao\Model\Buyer::create(['id' => 2, 'wx_user_id' => 2, 'mobile' => '18600186000', 'subscribe_status' => 1]); DB::table('buyer_addresses')->truncate(); \Dajiayao\Model\BuyerAddress::create(['buyer_id' => 2, 'address_id' => 320507, 'address' => '相城区元和街道', 'postcode' => 215000, 'receiver' => 'zzq', 'mobile' => 159987548, 'default' => 1]); }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Start to create a shop, please wait...'); $shop = Shop::where('seller_id', 1)->first(); if (count($shop) > 0) { $this->info('A shop exist, seller_id = 1'); return; } $seller = Seller::find(1); $shopService = new ShopService(); $shopService->createShop($seller, 1, 1, '测试小店', '测试小店', 'test', 'http://mmbiz.qpic.cn/mmbiz/4atXZMyxUkdTkThhj8icicfHpd07oaflgJpwwLficHRaLZQzYU8C7A3gWpua4dogmUefNln5K4ChSU9LeCanib6vEw/0?wx_fmt=png'); $this->info('Finished'); return; }
/** * @param $shortId * @return string * @author zhengqian@dajiayao.cc */ public function index($shortId) { if (!$shortId) { return "shop id is required"; } $shop = Shop::where("short_id", $shortId)->first(); if (!$shop) { return "shop is not found"; } try { $jsFileHash = ['vendor' => hash_file('md2', public_path('assets/scripts/vendor.js')), 'shop' => hash_file('md2', public_path('assets/scripts/shop.js')), 'shop_css' => hash_file('md2', public_path('assets/stylesheets/shop.css')), 'app' => hash_file('md2', public_path('assets/stylesheets/app.css'))]; } catch (\Exception $e) { $jsFileHash = []; } return view('shop.index')->with('shop_short_id', $shortId)->with('hash_file', $jsFileHash); }
/** * 收藏与取消收藏 * @param $id * @return string * @author zhengqian@dajiayao.cc */ public function favorite() { $inputdata = $this->inputData->only('shopShortId', 'flag'); $validator = \Validator::make($inputdata, ['shopShortId' => 'required', 'flag' => 'required|boolean']); if ($validator->fails()) { return RestHelp::parametersIllegal($validator->messages()->first()); } $objShop = Shop::getShopByShort($inputdata['shopShortId']); if (!$objShop) { return RestHelp::encodeResult(21001, "shop not found in db"); } $buyerId = is_null($this->buyerId) ? 0 : $this->buyerId; if ($inputdata['flag'] == false) { FavoriteShop::where('buyer_id', $buyerId)->where('shop_id', $objShop->id)->delete(); } elseif ($inputdata['flag'] == true) { $favorite = new FavoriteShop(); $favorite->buyer_id = $buyerId; $favorite->shop_id = $objShop->id; $favorite->save(); } else { return RestHelp::encodeResult(21001, 'flag is only 0 or 1'); } return RestHelp::success(); }
/** * 核实订单,库存 * @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]); }
public function getShopById($id) { return Shop::getById($id); }
/** * 上传店铺的图片 logo banner * @author Hanxiang * TODO */ public function setImagePost() { $input = Input::all(); $validator = Validator::make($input, ['shop_id' => 'required', 'media_id' => 'required', 'type' => 'required']); if ($validator->fails()) { return $this->sendResponse(20201, $validator->messages()->first()); } if (!in_array($input['type'], ['logo', 'banner'])) { return $this->sendResponse(20204, 'Invalid type'); } $sellerService = new SellerService(); $mediaPath = $sellerService->downloadMedia($input['media_id'], $input['type']); if ($mediaPath == false) { return $this->sendResponse(20202, 'Invalid media_id'); } $shop = Shop::find($input['shop_id']); if (!$shop) { return $this->sendResponse(20203, 'Invalid shop_id'); } $shop->thumbnail = $mediaPath; $shop->save(); return $this->sendResponse(10000, 'success', ['url' => url($mediaPath)]); }
/** * 店铺详情 * @param $id * @return string * @author zhengqian@dajiayao.cc */ public function detail($short_id) { if (!$short_id) { return RestHelp::parametersIllegal("shop id is requird"); } $objShop = Shop::where('short_id', $short_id)->first(); if (!$objShop) { return RestHelp::encodeResult(21000, "shop is not found in db"); } $buyerId = $this->buyerId; $favShop = FavoriteShop::where("shop_id", $objShop->id)->where("buyer_id", $buyerId)->first(); $favorite = $favShop ? 1 : 0; $seller = $objShop->seller; $arrSeller = array(); $arrSeller['id'] = $seller->id; $arrSeller['name'] = $seller->wxUser ? $seller->wxUser->nickname : $seller->realname; $arrSeller['mobile'] = $seller->mobile; $banner = ""; $arrShop = array(); $arrShop['shortId'] = $objShop->short_id; $arrShop['name'] = $objShop->subtitle; $arrShop['banner'] = $banner; $arrShop['ad'] = "/1.png"; $arrShop['avatar'] = $objShop->thumbnail; $arrShop['type'] = $objShop->type; $arrShop['banner'] = $objShop->banner ? ImageUtil::getRuleImgSize($objShop->banner, 750, 246) : ''; $arrShop['region']['provinceId'] = $objShop->province_id; $arrShop['region']['cityId'] = $objShop->city_id; $arrShop['region']['countyId'] = $objShop->county_id; $items = array_values($objShop->getItemsOnShelf()); $arrItem = array(); foreach ($items as $k => $item) { $arrItem[$k]['id'] = $item->id; $arrItem[$k]['title'] = $item->title; $arrItem[$k]['name'] = $item->name; $objImage = $item->image->first(); $imagUrl = $objImage ? ImageUtil::getRuleImgSize($objImage->url, 260, 260) : ""; $arrItem[$k]['image'] = $imagUrl; $arrItem[$k]['code'] = $item->code; $arrItem[$k]['supplier'] = $item->supplier->title; $arrItem[$k]['spec'] = $item->spec; $arrItem[$k]['weight'] = $item->weight; $arrItem[$k]['volume'] = $item->volume; $arrItem[$k]['price'] = $item->price; $arrItem[$k]['marketPrice'] = $item->market_price; //总计售出 $sellsCount = $this->redis->get("dajiayao:mall:item:sellcount:" . $item->id); $arrItem[$k]['sales'] = $sellsCount ? (int) $sellsCount : 0; $arrItem[$k]['comment'] = $item->comment; //以前购买人数 $arrRedisBuyers = $this->redis->smembers("dajiayao:mall:item:buyers:" . $item->id); $arrBuyers = array(); foreach ($arrRedisBuyers as $b => $buyers) { if ($b < 4) { //最多五个 array_push($arrBuyers, json_decode($buyers)); } } $arrItem[$k]['buyers'] = $arrBuyers; } //TODO 支付方式 $arrPayment = ['alipay']; //TODO 广告位,推广 $arrPromotions = [["title" => "星巴克", "link" => "#", "image" => ImageUtil::getRuleImgSize("/shopimages/starbucks_promotion.jpg", 1176, 210)]]; return RestHelp::success(['favorite' => $favorite, 'shop' => $arrShop, 'promotions' => $arrPromotions, 'owner' => $arrSeller, "availablePayments" => $arrPayment, 'items' => $arrItem, 'visitorCount' => rand(100000, 105000)]); }