123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- <?php
- namespace App\Http\Controllers\Admin;
- use app\Lib\Pagination;
- use app\Lib\Utils;
- use App\Lib\Weidian\weidianApi;
- use App\Lib\Youzan\YouzanApi;
- use App\Model\admin\GoodModel;
- use App\Model\admin\SupplyModel;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Input;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Validation\Rules\In;
- use \View;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Redirect;
- use GuzzleHttp;
- use Cache;
- class SupplyController extends Controller
- {
- public function __construct()
- {
- if (!Auth::check()) {
- return Redirect::to("admin-login");
- }
- }
- public function addAction(Request $request)
- {
- if ($request->isMethod('post')) {
- $validate = \Validator::make($request->input(), [
- 'supplyname' => "required",
- 'supplykey' => "required",
- 'merchant_id' => "required",
- 'apihost' => "required",
- ], [
- 'required' => ":attribute必填项不能为空",
- ], [
- 'supplyname' => '供应商名',
- 'supplykey' => '密钥',
- 'merchant_id' => '商户ID',
- 'apihost' => '接口主机',
- ]);
- if ($validate->fails()) {
- return \redirect()->back()->withErrors($validate)->withInput();
- }
- $supply = new SupplyModel();
- $supply->supplyname = Input::get('supplyname');
- $supply->supplykey = Input::get('supplykey');
- $supply->merchant_id = Input::get('merchant_id');
- $supply->apihost = Input::get('apihost');
- $supply->createtime = time();
- if ($supply->save()) {
- return Redirect::to('supply-list')->with('message', '操作成功!');
- } else {
- return \redirect()->back()->with('message', '添加失败!');
- }
- }
- return View::make("admin.supplyform")->with('message', '添加成功!');
- }
- public function listAction()
- {
- $supply = SupplyModel::paginate(20);
- return View::make("admin.supply", ['list' => $supply]);
- }
- public function updateAction(Request $request, $id)
- {
- $supply = SupplyModel::find($id);
- if ($request->isMethod('post')) {
- $supply->supplyname = Input::get('supplyname');
- $supply->supplykey = Input::get('supplykey');
- $supply->merchant_id = Input::get('merchant_id');
- $supply->apihost = Input::get('apihost');
- if ($supply->save()) {
- return Redirect::to('supply-list')->with('message', '操作成功!');
- } else {
- return \redirect()->back()->with('message', '添加失败!');
- }
- }
- return View::make("admin.supplyform", ['supply' => $supply]);
- }
- /*
- * 获取渠道列表以及对应的分类
- * */
- public function sourceAction()
- {
- $supplies = SupplyModel::all();
- foreach ($supplies as $s) {
- if ($s->type == 1) {
- $data = ['opcode' => 'get_category_list', 'merchant_id' => $s->merchant_id]; //获取类别
- ksort($data);
- $string = Utils::createLinkstring($data);
- $data['sign'] = md5($string . $s->supplykey);
- $data['sign_type'] = 'MD5';
- $s->apihost = Utils::endWith($s->apihost, '/') ? $s->apihost : $s->apihost . "/";
- $url = $s->apihost . 'api/service/business';
- $res = Utils::curlRequest($url, json_encode($data));
- $list = json_decode($res);
- Cache::put("goods_cat_cid" . $s->id, serialize($s));
- }
- }
- if (!isset($list->category_list)) {
- return isset($list->ret_msg) ?: dd($list);
- }
- $category_list = json_decode($list->category_list);
- return View::make("admin.supplies", ['supplies' => $supplies, 'list' => $category_list]);
- }
- public function goodsViewsAction(Request $request)
- {
- $settings = \DB::table('settings')->get();
- $settingArray = array();
- if ($settings) {
- foreach ($settings as $v) {
- $settingArray[$v->skey] = $v->svalue;
- }
- }
- $success = $fail = 0 ;
- $message = "";
- if ($request->isMethod('post')) {
- $shops = \DB::table('shop')->find(Input::get('shop'));
- if ($shops) {
- foreach (Input::get('skuid') as $key) {
- $stock = Input::get('sku_stock_num_show')[$key];
- $isImport = \DB::table('goods')->where(['shopid' => $shops->id, 'sku_id' => $key])->first(); //是否已经导入过
- $imgs = $skus = array();
- $price = Input::get('sku_price')[$key] / 100;
- if (Input::get('addprice') == 'add_price') {
- $price = $skus[0]['price'] = ceil($price + $settingArray['cf_price']);
- } elseif (Input::get('addprice') == 'cf_price') {
- $skus[0]['price'] = $price = ceil($price * $settingArray['cf_price']);
- }
- $good = new GoodModel();
- $good->shopid = $shops->id;
- $good->type = $shops->type;
- $good->sku_id = $key;//Input::get('skuid')[$key];
- $good->sku_name = Input::get('sku_name')[$key];
- $good->sku_stock_num_show = $stock;
- $good->sku_price = $price;
- $good->brand_name = Input::get('brand_name')[$key];
- $good->country_name = Input::get('country_name')[$key];
- $good->sku_weight = Input::get('sku_weight')[$key];
- $good->sku_weight_unit = Input::get('sku_weight_unit')[$key];
- $good->trade_id = Input::get('trade_id')[$key];
- $good->country_logo = Input::get('country_logo')[$key];
- $good->sku_detail = Input::get('sku_detail')[$key];
- $good->country_map = Input::get('country_map')[$key];
- $good->model_type = Input::get('model_type')[$key];
- $good->gstatus = 0;
- if (isset(Input::get('quality_start_date')[$key]) && !empty(Input::get('quality_start_date')[$key])) {
- $good->quality_start_date = Input::get('quality_start_date')[$key];
- $good->quality_end_date = Input::get('quality_end_date')[$key];
- }
- if (Input::get('trade_id')[$key] == 2) {
- $trade = ' 直邮商品';
- } elseif (Input::get('trade_id')[$key] == 1) {
- $trade = '保税商品';
- } elseif (Input::get('trade_id')[$key] == 3) {
- $trade = '完税商品';
- } else {
- $trade = '售后商品';
- }
- $item_comment = Input::get('sku_name')[$key] . "\n品牌:" . Input::get('brand_name')[$key] . "\n产地:" . Input::get('country_name')[$key] . "\n重量:"
- . Input::get('sku_weight')[$key] . Input::get('sku_weight_unit')[$key] . "\n贸易类型:" . $trade;
- if (!empty(Input::get('quality_start_date')[$key])) {
- $item_comment .= "\n保质期:" . Input::get('quality_start_date')[$key] . ' - ' . Input::get('quality_end_date')[$key];
- }
- if ($shops->type == 1) { //处理有赞
- $yzApi = YouzanApi::getInstance($shops->app_id, $shops->app_secret);
- //更新商品库存信息。
- if ($isImport && Input::get('updateStock')) {
- $getParams = ['num_iid' => $isImport->item_id];
- $productInfo = $yzApi->getProduct($getParams);
- if ($productInfo['code'] == 200 && isset($productInfo['response'])) { //商品存在
- $skusInfo = $productInfo['response']['item']['skus'];
- $skuParams = [
- 'num_iid' => $skusInfo[0]['num_iid'],
- 'sku_id' => $skusInfo[0]['sku_id'],
- 'quantity' => $stock,
- 'price' => $price,
- 'outer_id' => $key,
- ];
- $result = $yzApi->updateSkuInfos($skuParams);
- if ($result['code'] == 200 && isset($result['response'])) {
- \DB::table('goods')->where(['shopid' => $shops->id, 'item_id' => $isImport->item_id])
- ->update(['sku_stock_num_show' => $stock, 'gstatus' => 1, 'sku_price' => $price]);
- $success++;
- } else {
- $fail++;
- }
- }
- continue;
- }
- $params = [
- 'title' => Input::get('sku_name')[$key],
- 'price' => $price,
- 'post_fee' => '0',
- 'outer_id' => $key,
- 'quantity' => Input::get('sku_stock_num_show')[$key],
- 'delivery_template_id' => $shops->delivery_template_id ? $shops->delivery_template_id : $settingArray['yz_template'],
- 'is_display' => 0
- ];
- $skus_with_json = [];
- $skus_with_json[0]['sku_property'] = ['贸易类型' => $trade];
- $skus_with_json[0]['sku_price'] = $price;
- $skus_with_json[0]['sku_quantity'] = Input::get('sku_stock_num_show')[$key];
- $skus_with_json[0]['sku_outer_id'] = $key;
- $params['skus_with_json'] = json_encode($skus_with_json);
- if (!is_dir(storage_path() . '/product')) {
- mkdir(storage_path() . '/product');
- }
- if (!is_dir(storage_path('product/') . $key)) {
- mkdir(storage_path('product/') . $key);
- }
- $file = Utils::downloadImage(Input::get('sku_pic')[$key], md5(Input::get('sku_pic')[$key]), storage_path('product/' . $key));
- if (!$file) throw new Exception('没有商品主图');
- $files = [
- [
- 'url' => $file['saveDir'] . '/' . $file['fileName'],
- 'field' => 'images[]',
- ],
- ];
- $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
- preg_match_all($pattern, Input::get('sku_detail')[$key], $match);
- $params['desc'] = '<p>' . str_replace("\n", "<br/>", $item_comment) . "</p>";
- foreach ($match[1] as $img) {
- if ($shops->savePic) {
- $file = Utils::downloadImage($img, md5(Input::get('sku_pic')[$key]), storage_path('product/' . $key));
- if (!$file) continue;
- $files[] = ['url' => $file['saveDir'] . '/' . $file['fileName'], 'field' => 'images[]'];
- } else {
- $params['desc'] .= '<img src="' . $img . '" />';
- }
- }
- $params['desc'] .= '</p>';
- $result = $yzApi->addProduct($params, $files);
- if ($result['code'] == 200 && isset($result['response'])) {
- $good->item_id = $result['response']['item']['num_iid'];
- $good->sku_pic = $result['response']['item']['pic_url'];
- $good->save();
- $success++;
- } else {
- $fail++;
- }
- } else if ($shops->type == 2) { //处理微店
- $accessToken = weidianApi::get_accesstoken($shops->app_id, $shops->app_secret);
- \DB::table('shop')->where('id', $shops->id)->update(['access_token' => $accessToken]);
- $wdProductApi = new \ProductClientApi($accessToken);
- if ($isImport && Input::get('updateStock')) {
- $result = $wdProductApi->getProduct($isImport->item_id)->getDataAsObject();
- if ($result->status->status_code == 0) { //检索商品成功!
- $items = $result->result->skus;
- $skus_update_items = [];
- foreach ($items as $item) {
- $skus_update_items [] = ['item_id' => $isImport->item_id, 'item_sku_id' => $item->id, 'stock' => $stock];
- }
- $res = $wdProductApi->updateStock($skus_update_items);
- if ($res) {
- $success++;
- } else {
- $fail++;
- }
- continue;
- }
- }
- $imgUlr = $wdProductApi->uploadProductImage("@" . Input::get('sku_pic')[$key])->data;
- $imgUlr = json_decode($imgUlr);
- $skus[0]['img'] = $imgUlr->result;
- $saveImage = $imgUlr->result;
- $imgs[] = $imgUlr->result;
- $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
- preg_match_all($pattern, Input::get('sku_detail')[$key], $match);
- foreach ($match[1] as $img) {
- $imgUlr = $wdProductApi->uploadProductImage("@" . $img)->data;
- $imgUlr = json_decode($imgUlr);
- $imgs[] = $imgUlr->result;
- }
- if (Input::get('addprice') == 'add_price') {
- $price = $skus[0]['price'] = ceil($price + $settingArray['cf_price']);
- } elseif (Input::get('addprice') == 'cf_price') {
- $skus[0]['price'] = $price = ceil($price * $settingArray['cf_price']);
- }
- $skus[0]['title'] = Input::get('sku_name')[$key];
- $skus[0]['stock'] = Input::get('sku_stock_num_show')[$key];
- $skus[0]['sku_merchant_code'] = $key;
- $merchant_code = $key;
- $item_name = trim(Input::get('sku_name')[$key]);
- $free_delivery = 1; //是否包邮
- $remote_free_delivery = 0;
- if (Input::get('model_type') == 2 || Input::get('model_type') == 1) {
- $free_delivery = 0; //包邮
- if (Input::get('model_type') == 2) { //部分包邮
- $remote_free_delivery = 0;
- } else {
- $remote_free_delivery = 1; //偏远地区是否包邮:1包邮,0不包邮只有在free_delivery为1时候有效,当free_delivery为0时无论传入何值都不包邮
- }
- }
- //添加商品
- $response = $wdProductApi->addProduct($item_name, $price, [], $stock, $item_comment, $merchant_code, $imgs, $free_delivery, 2, $skus, $remote_free_delivery);
- if (!$response->getDataAsObject()) {
- Log::info("导入 " . $key . " 失败");
- $fail++;
- continue;
- }
- $add_item_id = $response->getDataAsObject()->result->item_id;
- $good->item_id = $add_item_id;
- $good->sku_pic = $saveImage;
- $good->save();
- $success++;
- }
- }
- $message = $success . '条操作成功,' . $fail . '条操作失败';
- } else {
- $message = '选择的店铺不存在!';
- }
- \redirect()->refresh();
- }
- $supply = SupplyModel::where('id', Input::get('sid'))->first();
- if ($supply) {
- $page = intval(Input::get('page')) ?: 1;
- $limit = intval(Input::get('limit')) ?: 10;
- $data = ['opcode' => 'get_goods_list', 'merchant_id' => $supply->merchant_id,
- 'category_id' => Input::get('cid'), 'page_size' => $limit, 'page_index' => $page - 1]; //获取产品列表gi
- ksort($data);
- $string = Utils::createLinkstring($data);
- $data['sign'] = md5($string . $supply->supplykey);
- $data['sign_type'] = 'MD5';
- $supply->apihost = Utils::endWith($supply->apihost, '/') ? $supply->apihost : $supply->apihost . "/";
- $url = $supply->apihost . 'api/service/business';
- $res = Utils::curlRequest($url, json_encode($data));
- $list = json_decode($res);
- if (Input::get('debug') == 1 || !$list) dd($list);
- $total = intval($list->total);
- $markup = "";
- if ($total > $limit) {
- $url = route("goodsview", ['sid' => Input::get('sid'), 'cid' => Input::get('cid'), 'cat_name' => Input::get('cat_name')]);
- $params = array(
- 'total_rows' => intval($total), #(必须)
- 'method' => 'html', #(必须)
- 'parameter' => $url . "&page=@",//url()->current()."?" , //'xxx.com/20-0-0-0-40-?.html', #(必须)
- 'now_page' => $page, #(必须)
- 'list_rows' => $limit, #(可选) 默认为15
- );
- $pagination = new Pagination($params);
- $markup = $pagination->show(2);
- }
- $shops = \DB::table('shop')->get();
- return View::make('admin.goodsList', ['list' => $list, 'shops' => $shops, 'supply' => $supply,
- 'markup' => $markup, 'settings' => $settingArray,'message'=>$message, 'cat' => urldecode(Input::get('cat_name'))]);
- }
- }
- public function storeGoodsAction(Request $request)
- {
- $settings = \DB::table('settings')->get();
- $settingArray = array();
- if ($settings) {
- foreach ($settings as $v) {
- $settingArray[$v->skey] = $v->svalue;
- }
- }
- $shops = \DB::table('shop')->find(Input::get('shop'));
- if ($shops) {
- $success = $fail = 0;
- foreach (Input::get('skuid') as $key) {
- $stock = Input::get('sku_stock_num_show')[$key];
- $isImport = \DB::table('goods')->where(['shopid' => $shops->id, 'sku_id' => $key])->first(); //是否已经导入过
- $imgs = $skus = array();
- $price = Input::get('sku_price')[$key] / 100;
- if (Input::get('addprice') == 'add_price') {
- $price = $skus[0]['price'] = ceil($price + $settingArray['cf_price']);
- } elseif (Input::get('addprice') == 'cf_price') {
- $skus[0]['price'] = $price = ceil($price * $settingArray['cf_price']);
- }
- $good = new GoodModel();
- $good->shopid = $shops->id;
- $good->type = $shops->type;
- $good->sku_id = $key;//Input::get('skuid')[$key];
- $good->sku_name = Input::get('sku_name')[$key];
- $good->sku_stock_num_show = $stock;
- $good->sku_price = $price;
- $good->brand_name = Input::get('brand_name')[$key];
- $good->country_name = Input::get('country_name')[$key];
- $good->sku_weight = Input::get('sku_weight')[$key];
- $good->sku_weight_unit = Input::get('sku_weight_unit')[$key];
- $good->trade_id = Input::get('trade_id')[$key];
- $good->country_logo = Input::get('country_logo')[$key];
- $good->sku_detail = Input::get('sku_detail')[$key];
- $good->country_map = Input::get('country_map')[$key];
- $good->model_type = Input::get('model_type')[$key];
- $good->gstatus = 0;
- $quality_start_date = Input::get('quality_start_date');
- if (isset($quality_start_date) && !empty($quality_start_date)) {
- $good->quality_start_date = Input::get('quality_start_date')[$key];
- $good->quality_end_date = Input::get('quality_end_date')[$key];
- }
- if (Input::get('trade_id')[$key] == 2) {
- $trade = ' 直邮商品';
- } elseif (Input::get('trade_id')[$key] == 1) {
- $trade = '保税商品';
- } elseif (Input::get('trade_id')[$key] == 3) {
- $trade = '完税商品';
- } else {
- $trade = '售后商品';
- }
- $item_comment = Input::get('sku_name')[$key] . "\n品牌:" . Input::get('brand_name')[$key] . "\n产地:" . Input::get('country_name')[$key] . "\n重量:"
- . Input::get('sku_weight')[$key] . Input::get('sku_weight_unit')[$key] . "\n贸易类型:" . $trade;
- if (!empty(Input::get('quality_start_date')[$key])) {
- $item_comment .= "\n保质期:" . Input::get('quality_start_date')[$key] . ' - ' . Input::get('quality_end_date')[$key];
- }
- if ($shops->type == 1) { //处理有赞
- $yzApi = YouzanApi::getInstance($shops->app_id, $shops->app_secret);
- //更新商品库存信息。
- if ($isImport && Input::get('updateStock')) {
- $getParams = ['num_iid' => $isImport->item_id];
- $productInfo = $yzApi->getProduct($getParams);
- if ($productInfo['code'] == 200 && isset($productInfo['response'])) { //商品存在
- $skusInfo = $productInfo['response']['item']['skus'];
- $skuParams = [
- 'num_iid' => $skusInfo[0]->item_id,
- 'sku_id' => $skusInfo[0]->sku_id,
- 'quantity' => $stock,
- 'price' => $price,
- 'outer_id' => $key,
- ];
- $result = $yzApi->updateSkuInfos($skuParams);
- if ($result['code'] == 200 && isset($result['response'])) {
- \DB::table('goods')->where(['shopid' => $shops->id, 'item_id' => $isImport->item_id])
- ->update(['sku_stock_num_show' => $stock, 'gstatus' => 1, 'sku_price' => $price]);
- $success++;
- } else {
- $fail++;
- }
- }
- continue;
- }
- $params = [
- 'title' => Input::get('sku_name')[$key],
- 'price' => $price,
- 'post_fee' => '0',
- 'outer_id' => $key,
- 'quantity' => Input::get('sku_stock_num_show')[$key],
- 'delivery_template_id' => $shops->delivery_template_id ? $shops->delivery_template_id : $settingArray['yz_template'],
- 'is_display' => 0
- ];
- $skus_with_json = [];
- $skus_with_json[0]['sku_property'] = ['贸易类型' => $trade];
- $skus_with_json[0]['sku_price'] = $price;
- $skus_with_json[0]['sku_quantity'] = Input::get('sku_stock_num_show')[$key];
- $skus_with_json[0]['sku_outer_id'] = $key;
- $params['skus_with_json'] = json_encode($skus_with_json);
- if (!is_dir(storage_path() . '/product')) {
- mkdir(storage_path() . '/product');
- }
- if (!is_dir(storage_path('product/') . $key)) {
- mkdir(storage_path('product/') . $key);
- }
- $file = Utils::downloadImage(Input::get('sku_pic')[$key], md5(Input::get('sku_pic')[$key]), storage_path('product/' . $key));
- if (!$file) throw new Exception('没有商品主图');
- $files = [
- [
- 'url' => $file['saveDir'] . '/' . $file['fileName'],
- 'field' => 'images[]',
- ],
- ];
- $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
- preg_match_all($pattern, Input::get('sku_detail')[$key], $match);
- $params['desc'] = '<p>' . str_replace("\n", "<br/>", $item_comment) . "</p>";
- foreach ($match[1] as $img) {
- if ($shops->savePic) {
- $file = Utils::downloadImage($img, md5(Input::get('sku_pic')[$key]), storage_path('product/' . $key));
- if (!$file) continue;
- $files[] = ['url' => $file['saveDir'] . '/' . $file['fileName'], 'field' => 'images[]'];
- } else {
- $params['desc'] .= '<img src="' . $img . '" />';
- }
- }
- $params['desc'] .= '</p>';
- $result = $yzApi->addProduct($params, $files);
- if ($result['code'] == 200 && isset($result['response'])) {
- $good->item_id = $result['response']['item']['num_iid'];
- $good->sku_pic = $result['response']['item']['pic_url'];
- $good->save();
- $success++;
- } else {
- $fail++;
- }
- } else if ($shops->type == 2) { //处理微店
- $accessToken = weidianApi::get_accesstoken($shops->app_id, $shops->app_secret);
- \DB::table('shop')->where('id', $shops->id)->update(['access_token' => $accessToken]);
- $wdProductApi = new \ProductClientApi($accessToken);
- if ($isImport && Input::get('updateStock')) {
- $result = $wdProductApi->getProduct($isImport->item_id)->getDataAsObject();
- if ($result->status->status_code == 0) { //检索商品成功!
- $items = $result->result->skus;
- $skus_update_items = [];
- foreach ($items as $item) {
- $skus_update_items [] = ['item_id' => $isImport->item_id, 'item_sku_id' => $item->id, 'stock' => $stock];
- }
- $res = $wdProductApi->updateStock($skus_update_items);
- if ($res) {
- $success++;
- } else {
- $fail++;
- }
- continue;
- }
- }
- $imgUlr = $wdProductApi->uploadProductImage("@" . Input::get('sku_pic')[$key])->data;
- $imgUlr = json_decode($imgUlr);
- $skus[0]['img'] = $imgUlr->result;
- $saveImage = $imgUlr->result;
- $imgs[] = $imgUlr->result;
- $pattern = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
- preg_match_all($pattern, Input::get('sku_detail')[$key], $match);
- foreach ($match[1] as $img) {
- $imgUlr = $wdProductApi->uploadProductImage("@" . $img)->data;
- $imgUlr = json_decode($imgUlr);
- $imgs[] = $imgUlr->result;
- }
- if (Input::get('addprice') == 'add_price') {
- $price = $skus[0]['price'] = ceil($price + $settingArray['cf_price']);
- } elseif (Input::get('addprice') == 'cf_price') {
- $skus[0]['price'] = $price = ceil($price * $settingArray['cf_price']);
- }
- $skus[0]['title'] = Input::get('sku_name')[$key];
- $skus[0]['stock'] = Input::get('sku_stock_num_show')[$key];
- $skus[0]['sku_merchant_code'] = $key;
- $merchant_code = $key;
- $item_name = trim(Input::get('sku_name')[$key]);
- $free_delivery = 1; //是否包邮
- $remote_free_delivery = 0;
- if (Input::get('model_type') == 2 || Input::get('model_type') == 1) {
- $free_delivery = 0; //包邮
- if (Input::get('model_type') == 2) { //部分包邮
- $remote_free_delivery = 0;
- } else {
- $remote_free_delivery = 1; //偏远地区是否包邮:1包邮,0不包邮只有在free_delivery为1时候有效,当free_delivery为0时无论传入何值都不包邮
- }
- }
- //添加商品
- $response = $wdProductApi->addProduct($item_name, $price, [], $stock, $item_comment, $merchant_code, $imgs, $free_delivery, 2, $skus, $remote_free_delivery);
- if (!$response->getDataAsObject()) {
- Log::info("导入 " . $key . " 失败");
- $fail++;
- continue;
- }
- $add_item_id = $response->getDataAsObject()->result->item_id;
- $good->item_id = $add_item_id;
- $good->sku_pic = $saveImage;
- $good->save();
- $success++;
- }
- }
- $request->session()->flash('message', $success . '条操作成功,' . $fail . '条操作失败');
- $request->session()->flash('do', 1);
- } else {
- $request->session()->flash('message', '选择的店铺不存在!');
- }
- Redirect::back();
- }
- }
|