ProductController.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\ProductStock;
  4. use App\Http\Requests\ProductRequest;
  5. use Illuminate\Http\Request;
  6. use App\Models\Product;
  7. use App\Models\ProductTranslation;
  8. use App\Models\Category;
  9. use App\Models\User;
  10. use App\Models\Upload;
  11. use App\Models\ProductTax;
  12. use App\Models\AttributeValue;
  13. use App\Models\Cart;
  14. use Carbon\Carbon;
  15. use Combinations;
  16. use CoreComponentRepository;
  17. use Artisan;
  18. use Cache;
  19. use Auth;
  20. use Str;
  21. use App\Services\ProductService;
  22. use App\Services\ProductTaxService;
  23. use App\Services\ProductFlashDealService;
  24. use App\Services\ProductStockService;
  25. class ProductController extends Controller
  26. {
  27. protected $productService;
  28. protected $productTaxService;
  29. protected $productFlashDealService;
  30. protected $productStockService;
  31. public function __construct(
  32. ProductService $productService,
  33. ProductTaxService $productTaxService,
  34. ProductFlashDealService $productFlashDealService,
  35. ProductStockService $productStockService
  36. ) {
  37. $this->productService = $productService;
  38. $this->productTaxService = $productTaxService;
  39. $this->productFlashDealService = $productFlashDealService;
  40. $this->productStockService = $productStockService;
  41. }
  42. public function apicat( Request $request )
  43. {
  44. $categories = Category::get();
  45. $all = $categories->toArray();
  46. #echo "<PRE>";print_r( $all );exit;
  47. $all_cat = [];
  48. foreach( $all as $k => $v )
  49. {
  50. $ar = [];
  51. $ar['id'] = $v['id'];
  52. $ar['parent_id'] = $v['parent_id'];
  53. $ar['name'] = $v['name'];
  54. $ar['slug'] = $v['slug'];
  55. if( isset( $v['category_translations']))
  56. {
  57. foreach ( $v['category_translations'] as $kk => $v )
  58. {
  59. $ar['name'.($kk+1)] = $v['name'];
  60. }
  61. }
  62. $all_cat[] = $ar;
  63. }
  64. echo json_encode( $all_cat);
  65. exit;
  66. }
  67. public function apicj( Request $request )
  68. {
  69. error_reporting(0);
  70. file_put_contents(dirname(__FILE__) . '/apicj_input2.txt', file_get_contents("php://input"));
  71. $json = file_get_contents("php://input");
  72. if ( empty($json) )
  73. {
  74. exit('data error');
  75. }
  76. $pr = json_decode($json, true);
  77. if ( $pr['key'] != get_setting('caiji_key') )
  78. {
  79. exit('Key Error');
  80. }
  81. echo 'ok';
  82. }
  83. public function caiji(Request $request )
  84. {
  85. error_reporting( 0 );
  86. file_put_contents( dirname( __FILE__ ).'/tog_post.txt', var_export($_POST, true), FILE_APPEND );
  87. file_put_contents( dirname( __FILE__ ).'/tog_get.txt', var_export($_GET, true), FILE_APPEND );
  88. file_put_contents( dirname( __FILE__ ).'/tog_input.txt', file_get_contents("php://input"), FILE_APPEND );
  89. $json = file_get_contents("php://input");
  90. if( empty($json))
  91. {
  92. // exit('data error');
  93. }
  94. $pr = json_decode($json,true );
  95. $user_id = $pr['uid'];
  96. // $seller = Seller::where('user_id',$user_id)->first();
  97. if( empty($seller))
  98. {
  99. // exit('seller is not exists');
  100. }
  101. $seller_id = 0;
  102. $product = new Product;
  103. $product->name = $pr['name'];
  104. $product->category_id = $pr['cat_id'];
  105. $product->brand_id = 0;
  106. $product->barcode = 0;
  107. $product->unit = 1;
  108. #$product->cb_price = $request->cb_price;
  109. #$product->xn_salenum = $request->xn_salenum;
  110. $product->min_qty = 1;
  111. $product->current_stock = 1000;
  112. $product->low_stock_quantity = 1;
  113. $product->stock_visibility_state = 1;
  114. $product->external_link = '';
  115. $product->external_link_btn ='';
  116. $mid = time().mt_rand(100,499);
  117. if( isset( $pr['photos'] ) )
  118. {
  119. foreach( $pr['photos'] as $img )
  120. {
  121. $upload = new Upload;
  122. $upload->user_id = Auth::user()->id;
  123. $upload->file_size = 8888;
  124. $upload->extension = 'jpg';
  125. $upload->type = 'image';
  126. $upload->file_original_name = $upload->file_name = $img;
  127. $upload->mid = $mid;
  128. $upload->save();
  129. #echo $img;
  130. }
  131. }
  132. $thm_id = 0;
  133. $upload = new Upload;
  134. $all = $upload->where(['mid'=> $mid])->get()->toArray();;
  135. $ids = '';
  136. foreach( $all as $a => $v )
  137. { if( $a == 0 )
  138. {
  139. $thm_id = $v['id'];
  140. }
  141. $ids .= $v['id'].',';
  142. }
  143. $ids = rtrim( $ids,',');
  144. $product->tags = '';
  145. $product->video_provider = '';
  146. $product->video_link = '';
  147. $product->unit_price =$pr['price'];
  148. $product->discount = 0;
  149. $product->discount_type = 'amount';
  150. if($pr['cprice']>0) {
  151. $product->purchase_price =$pr['price']+($pr['price']*$pr['cprice']/100);
  152. }
  153. $mid2 = time().mt_rand(500,999);
  154. $upload = new Upload;
  155. $upload->user_id = Auth::user()->id;
  156. $upload->file_size = 8888;
  157. $upload->extension = 'jpg';
  158. $upload->type = 'image';
  159. $upload->file_original_name = $upload->file_name = $pr['thumbnail_img'];
  160. $upload->mid = $mid2;
  161. $upload->save();
  162. $thm_id = $upload->where(['mid'=> $mid2])->first()->id;
  163. $product->thumbnail_img = $thm_id;
  164. if($ids == ''){
  165. $ids = $thm_id;
  166. }
  167. $product->photos = $ids;
  168. $product->shipping_type = 'free';
  169. $product->est_shipping_days = 1;
  170. $product->meta_title = $pr['name'];
  171. $product->meta_description = strip_tags($product->description);
  172. $product->meta_img = $product->thumbnail_img;
  173. $product->description = ($pr['description']);
  174. $product->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', strtolower( $pr['name']))).'-'.md5(microtime());
  175. if(Product::where('slug', $product->slug)->count() > 0){
  176. exit('Another product exists with same slug. Please change the slug!');
  177. }
  178. $colors = array();
  179. $product->colors = json_encode($colors);
  180. $choice_options = array();
  181. $product->attributes = json_encode(array());
  182. $product->choice_options = json_encode($choice_options, JSON_UNESCAPED_UNICODE);
  183. $product->published = 1;
  184. $product->cash_on_delivery = 0;
  185. //$variations = array();
  186. $product->published = 1;
  187. if($pr['cpk'] == 1) {
  188. $product->in_storehouse = $pr['cpk'];
  189. $product->added_by = 'admin';
  190. $product->user_id = 1;
  191. } else {
  192. $product->added_by = 'seller';
  193. $product->user_id = $pr['user_id'];
  194. $product->in_storehouse = 0;
  195. }
  196. $product->reviews_url = $pr['purl'];
  197. $product->save();
  198. // Product Translations
  199. $product_translation = ProductTranslation::firstOrNew(['lang' => env('DEFAULT_LANGUAGE'), 'product_id' => $product->id]);
  200. $product_translation->name = $pr['name'];
  201. $product_translation->unit = '';
  202. $product_translation->description = $pr['description'];
  203. $product_translation->save();
  204. //$product_stock = ProductStock::where('product_id', $id)->get()->toArray(); use App\Models\ProductStock;
  205. $product_stock = ProductStock::where('product_id', $product->id)->first();
  206. if($product_stock == null){
  207. $product_stock = new ProductStock;
  208. $product_stock->product_id = $product->id;
  209. }
  210. $product_stock->price = $pr['price'];
  211. $product_stock->sku = '';
  212. if( $pr['knum'] > 0){
  213. $product_stock->qty = $pr['knum'];
  214. } else {
  215. $product_stock->qty = 1000;
  216. }
  217. $product_stock->save();
  218. echo 'ok';exit;
  219. echo "<PRE>";
  220. print_r( $arr );
  221. exit;
  222. }
  223. public function api( Request $request ) {
  224. error_reporting(0);
  225. file_put_contents(dirname(__FILE__) . '/tog_post2.txt', var_export($_POST, true), FILE_APPEND);
  226. file_put_contents(dirname(__FILE__) . '/tog_get2.txt', var_export($_GET, true), FILE_APPEND);
  227. file_put_contents(dirname(__FILE__) . '/tog_input2.txt', file_get_contents("php://input"), FILE_APPEND);
  228. $json = file_get_contents("php://input");
  229. if ( empty($json) )
  230. {
  231. exit('data error');
  232. }
  233. $pr = json_decode($json, true);
  234. if ( $pr['key'] != get_setting('caiji_key') )
  235. {
  236. exit('Key Error');
  237. }
  238. $product = new Product;
  239. $product->name = $pr['name'];
  240. $product->added_by = 'admin';
  241. $product->user_id = User::where('user_type', 'admin')->first()->id;
  242. $product->category_id = 0;
  243. $product->brand_id = 0;
  244. $product->barcode = 0;
  245. $product->unit = 'pc';
  246. #$product->cb_price = $request->cb_price;
  247. #$product->xn_salenum = $request->xn_salenum;
  248. $product->min_qty = 1;
  249. $product->current_stock = 1000;
  250. $product->low_stock_quantity = 1;
  251. $product->stock_visibility_state = 1;
  252. $product->external_link = '';
  253. $product->external_link_btn = '';
  254. $mid = time() . mt_rand(100, 499);
  255. if ( isset($pr['photos']) )
  256. {
  257. foreach ( $pr['photos'] as $img )
  258. {
  259. $upload = new Upload;
  260. $upload->user_id = Auth::user()->id;
  261. $upload->file_size = 8888;
  262. $upload->extension = 'jpg';
  263. $upload->type = 'image';
  264. $upload->file_original_name = $upload->file_name = $img;
  265. $upload->mid = $mid;
  266. $upload->save();
  267. #echo $img;
  268. }
  269. }
  270. $thm_id = 0;
  271. $upload = new Upload;
  272. $all = $upload->where([ 'mid' => $mid ])->get()->toArray();;
  273. $ids = '';
  274. foreach ( $all as $a => $v )
  275. {
  276. if ( $a == 0 )
  277. {
  278. $thm_id = $v['id'];
  279. }
  280. $ids .= $v['id'] . ',';
  281. }
  282. $ids = rtrim($ids, ',');
  283. preg_match( '/([0-9|.]+)/',$pr['price'],$ppp );
  284. $pr['price'] = $ppp[1];
  285. $product->tags = '';
  286. $product->description = $pr['description'];
  287. $product->video_provider = '';
  288. $product->video_link = '';
  289. $product->unit_price = $pr['price'];
  290. $product->discount = 0;
  291. $product->discount_type = 'amount';
  292. $mid2 = time() . mt_rand(500, 999);
  293. $upload = new Upload;
  294. $upload->user_id = Auth::user()->id;
  295. $upload->file_size = 8888;
  296. $upload->extension = 'jpg';
  297. $upload->type = 'image';
  298. $upload->file_original_name = $upload->file_name = $pr['thumbnail_img'];
  299. $upload->mid = $mid2;
  300. $upload->save();
  301. $thm_id = $upload->where([ 'mid' => $mid2 ])->first()->id;
  302. $product->thumbnail_img = $thm_id;
  303. $product->photos = $ids;
  304. $product->shipping_type = 'free';
  305. $product->est_shipping_days = 1;
  306. $product->meta_title = $pr['name'];
  307. $product->meta_description = strip_tags($product->description);
  308. $product->meta_img = $product->thumbnail_img;
  309. $product->slug = preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', strtolower($pr['name'])));
  310. if ( Product::where('slug', $product->slug)->count() > 0 )
  311. {
  312. exit('Another product exists with same slug. Please change the slug!');
  313. }
  314. $colors = [];
  315. $product->colors = json_encode($colors);
  316. $choice_options = [];
  317. $product->attributes = json_encode([]);
  318. $product->choice_options = json_encode($choice_options, JSON_UNESCAPED_UNICODE);
  319. $product->published = 1;
  320. $product->cash_on_delivery = 0;
  321. //$variations = array();
  322. $product->save();
  323. // Product Translations
  324. $product_translation = ProductTranslation::firstOrNew([ 'lang' => env('DEFAULT_LANGUAGE'), 'product_id' => $product->id ]);
  325. $product_translation->name = $pr['name'];
  326. $product_translation->unit = 'pc';
  327. $product_translation->description = $pr['description'];
  328. $product_translation->save();
  329. echo 'ok';
  330. exit;
  331. echo "<PRE>";
  332. print_r($arr);
  333. exit;
  334. }
  335. /**
  336. * Display a listing of the resource.
  337. *
  338. * @return \Illuminate\Http\Response
  339. */
  340. public function admin_products( Request $request ) {
  341. CoreComponentRepository::instantiateShopRepository();
  342. $type = 'In House';
  343. $col_name = NULL;
  344. $query = NULL;
  345. $sort_search = NULL;
  346. $products = Product::where('added_by', 'admin')->where('auction_product', 0)->where('wholesale_product', 0);
  347. if ( $request->type != NULL )
  348. {
  349. $var = explode(",", $request->type);
  350. $col_name = $var[0];
  351. $query = $var[1];
  352. $products = $products->orderBy($col_name, $query);
  353. $sort_type = $request->type;
  354. }
  355. if ( $request->search != NULL )
  356. {
  357. $sort_search = $request->search;
  358. $products = $products
  359. ->where('name', 'like', '%' . $sort_search . '%')
  360. ->orWhereHas('stocks', function ( $q ) use ( $sort_search )
  361. {
  362. $q->where('sku', 'like', '%' . $sort_search . '%');
  363. });
  364. }
  365. $products = $products->where('digital', 0)->orderBy('created_at', 'desc')->paginate(15);
  366. return view('backend.product.products.index', compact('products', 'type', 'col_name', 'query', 'sort_search'));
  367. }
  368. /**
  369. * Display a listing of the resource.
  370. *
  371. * @return \Illuminate\Http\Response
  372. */
  373. public function seller_products( Request $request ) {
  374. $col_name = NULL;
  375. $query = NULL;
  376. $seller_id = NULL;
  377. $sort_search = NULL;
  378. $products = Product::where('added_by', 'seller')->where('auction_product', 0)->where('wholesale_product', 0);
  379. if ( $request->has('user_id') && $request->user_id != NULL )
  380. {
  381. $products = $products->where('user_id', $request->user_id);
  382. $seller_id = $request->user_id;
  383. }
  384. if ( $request->search != NULL )
  385. {
  386. $products = $products
  387. ->where('name', 'like', '%' . $request->search . '%');
  388. $sort_search = $request->search;
  389. }
  390. if ( $request->type != NULL )
  391. {
  392. $var = explode(",", $request->type);
  393. $col_name = $var[0];
  394. $query = $var[1];
  395. $products = $products->orderBy($col_name, $query);
  396. $sort_type = $request->type;
  397. }
  398. $products = $products->where('digital', 0)->orderBy('created_at', 'desc')->paginate(15);
  399. $type = 'Seller';
  400. return view('backend.product.products.index', compact('products', 'type', 'col_name', 'query', 'seller_id', 'sort_search'));
  401. }
  402. public function all_products( Request $request ) {
  403. $col_name = NULL;
  404. $query = NULL;
  405. $seller_id = NULL;
  406. $sort_search = NULL;
  407. $products = Product::orderBy('created_at', 'desc')->where('auction_product', 0)->where('wholesale_product', 0);
  408. if ( $request->has('user_id') && $request->user_id != NULL )
  409. {
  410. $products = $products->where('user_id', $request->user_id);
  411. $seller_id = $request->user_id;
  412. }
  413. if ( $request->search != NULL )
  414. {
  415. $sort_search = $request->search;
  416. $products = $products
  417. ->where('name', 'like', '%' . $sort_search . '%')
  418. ->orWhereHas('stocks', function ( $q ) use ( $sort_search )
  419. {
  420. $q->where('sku', 'like', '%' . $sort_search . '%');
  421. });
  422. }
  423. if ( $request->type != NULL )
  424. {
  425. $var = explode(",", $request->type);
  426. $col_name = $var[0];
  427. $query = $var[1];
  428. $products = $products->orderBy($col_name, $query);
  429. $sort_type = $request->type;
  430. }
  431. $products = $products->paginate(15);
  432. $type = 'All';
  433. return view('backend.product.products.index', compact('products', 'type', 'col_name', 'query', 'seller_id', 'sort_search'));
  434. }
  435. /**
  436. * Show the form for creating a new resource.
  437. *
  438. * @return \Illuminate\Http\Response
  439. */
  440. public function create() {
  441. CoreComponentRepository::initializeCache();
  442. $categories = Category::where('parent_id', 0)
  443. ->where('digital', 0)
  444. ->with('childrenCategories')
  445. ->get();
  446. return view('backend.product.products.create', compact('categories'));
  447. }
  448. public function gather() {
  449. $arrContextOptions = [
  450. 'ssl' => [
  451. 'verify_peer' => false,
  452. 'verify_peer_name' => false,
  453. ]
  454. ];
  455. $tw_cat = Cache::get('tw_cat');
  456. if($tw_cat){
  457. $tw_cat = $lists =Cache::get('tw_cat');
  458. } else {
  459. $xiapi = file_get_contents("https://xiapi.xiapibuy.com/api/v4/pages/get_homepage_category_list", false, stream_context_create($arrContextOptions));
  460. $tw_cat= json_decode($xiapi,1); //列表
  461. Cache::set('tw_cat',$tw_cat);
  462. }
  463. $category_list_tw=$tw_cat['data']['category_list'];
  464. $en_cat = Cache::get('en_cat');
  465. if($en_cat){
  466. $en_cat= Cache::get('en_cat');
  467. } else {
  468. $xiapi = file_get_contents("https://shopee.sg/api/v4/pages/get_homepage_category_list", false, stream_context_create($arrContextOptions));
  469. $en_cat= json_decode($xiapi,1); //列表
  470. Cache::set('en_cat',$en_cat);
  471. }
  472. $category_list_en=$en_cat['data']['category_list'];
  473. $th_cat = Cache::get('th_cat');
  474. if($th_cat){
  475. $th_cat=Cache::get('th_cat');
  476. } else {
  477. $xiapi = file_get_contents("https://shopee.co.th/api/v4/pages/get_homepage_category_list", false, stream_context_create($arrContextOptions));
  478. $th_cat= json_decode($xiapi,1); //列表
  479. Cache::set('th_cat',$th_cat);
  480. }
  481. $category_list_th=$en_cat['data']['category_list'];
  482. $categories = Category::where('parent_id', 0)->get();
  483. $user =User::where('user_type', 'seller')->get();
  484. //dump($user);die;
  485. return view('backend.product.products.gather', compact('category_list_tw','category_list_en','category_list_th','categories','user'));
  486. }
  487. public function twcaiji(Request $request){
  488. $num = ($request->num)+1;
  489. $cid = $request->xiapi_cai_id;
  490. $by = $request->by;
  491. $price_max = $request->price_max;
  492. $price_min= $request->price_min;
  493. if($num < 0 || $cid < 0){exit;}
  494. $arrContextOptions = [
  495. 'ssl' => [
  496. 'verify_peer' => false,
  497. 'verify_peer_name' => false,
  498. ]
  499. ];
  500. $context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
  501. $item = Cache::get($cid.'-list');
  502. if($item){
  503. $item = $lists = Cache::get($cid.'-list');
  504. } else {
  505. $url = "https://xiapi.xiapibuy.com/api/v4/recommend/recommend?bundle=category_landing_page&cat_level=1&catid=$cid&limit=$num&offset=0&order=desc&page_type=search&by=$by&price_max=$price_max&price_min=$price_min";
  506. $list = file_get_contents($url, FALSE, $context); //商品列表
  507. $lists= json_decode($list,1); //商品列表
  508. $item = $lists['data']['sections'][0]['data']['item'] ;//商品列表
  509. Cache::set($cid.'-list',$item);
  510. }
  511. $count = count($item)-1;
  512. $numbers=Cache::get($cid.'_nums');
  513. if(!isset($numbers)){
  514. $numbers = 0;
  515. }
  516. $next = $numbers ;
  517. if(count($item)<1){
  518. $msg['error'] = 1;
  519. $msg['txt'] = '虾皮网产品分类ID不正确';
  520. Cache::del($cid.'_nums');
  521. Cache::del($cid.'-list');
  522. echo json_encode($msg);exit;
  523. }
  524. if($count == $next){
  525. $msg['error'] = 111;
  526. $msg['txt'] = '采集已结束';
  527. Cache::del($cid.'_nums');
  528. Cache::del($cid.'-list');
  529. echo json_encode($msg);exit;
  530. }
  531. if(''==$item[$next]['name']){
  532. $msg['error'] = 111;
  533. $msg['txt'] = '采集已结束';
  534. Cache::del($cid.'_nums');
  535. Cache::del($cid.'-list');
  536. echo json_encode($msg);exit;
  537. }
  538. $itemid = $item[$next]['itemid'];
  539. $shopid = $item[$next]['shopid'];
  540. $bundle_deal_id= $item[$next]['bundle_deal_id'];
  541. $info_url = "https://shopee.tw/api/v2/item/get_ratings?filter=0&flag=1&itemid=$itemid&limit=6&offset=0&shopid=$shopid&type=0";
  542. $info_content = file_get_contents($info_url );
  543. $info_contents = json_decode($info_content,1); //商品详情
  544. $str = "";
  545. $thumbnail_img = '';
  546. $photos = array();
  547. $arr = $item[$next]['images'];
  548. $data=[];
  549. $data['description']='';
  550. if($arr){
  551. foreach ($arr as $kk=>$vv){
  552. $PATH = $_SERVER['DOCUMENT_ROOT'].'/';
  553. $photos[] = "https://s-cf-tw.shopeesz.com/file/".$vv;
  554. $data['description'].="<p> <img src='https://s-cf-tw.shopeesz.com/file/".$vv."'> </p>";
  555. }
  556. }
  557. $msg['error'] = 0;
  558. $msg['num'] = $next+1;
  559. $msg['txt'] ='标题:'.$item[$next]['name'].'&nbsp;&nbsp;价格:'.$item[$next]['price']/100000;
  560. $data['name'] = $item[$next]['name']; //标题
  561. $data['photos'] = $photos;//相册
  562. $data['meta_title'] = $item[$next]['name'];//标题
  563. $data['thumbnail_img'] = "https://s-cf-tw.shopeesz.com/file/".$item[$next]['image'];//封面
  564. $data['meta_description'] =$item[$next]['name'];
  565. $data['price'] = $item[$next]['price']/100000;
  566. $data['skuimg'] = array();
  567. $data['size_name'] = array();
  568. $data['brand'] = '';
  569. $data['url'] = '';
  570. $data['uid'] = 24;
  571. $data['cprice'] = $request->cprice;
  572. $data['knum'] = $request->knum;
  573. $data['cat_id'] = $request->web_cat_id;
  574. $data['cpk'] = $request->cpk;
  575. $data['user_id'] = $request->user_id;
  576. $data['purl'] = "https://xiapi.xiapibuy.com/api/v2/item/get_ratings?filter=0&flag=1&itemid=$itemid&offset=0&shopid=$shopid&type=0";
  577. $insert_url = 'https://'.$_SERVER['SERVER_NAME'].'/caiji';
  578. $res = $this->get_url($insert_url,json_encode($data));
  579. $msg['txt20'] = $res;
  580. Cache::set($cid.'_nums',$numbers+1);
  581. echo json_encode($msg);exit;
  582. }
  583. public function encaiji(Request $request){
  584. $num = $request->num+1;
  585. $cid = $request->xiapi_cai_id_en;
  586. $by = $request->by;
  587. $price_max = $request->price_max;
  588. $price_min= $request->price_min;
  589. if($num < 0 || $cid < 0){exit;}
  590. $arrContextOptions = [
  591. 'ssl' => [
  592. 'verify_peer' => false,
  593. 'verify_peer_name' => false,
  594. ]
  595. ];
  596. $item = Cache::get($cid.'-list');
  597. if($item){
  598. $item = $lists = Cache::get($cid.'-list');
  599. } else {
  600. $url ="https://shopee.sg/api/v4/recommend/recommend?bundle=category_landing_page&cat_level=2&catid=$cid&limit=$num&price_max=$price_max&price_min=$price_min";
  601. $list = file_get_contents($url, false, stream_context_create($arrContextOptions)); //商品列表
  602. $lists= json_decode($list,1); //商品列表
  603. $item = $lists['data']['sections'][0]['data']['item'] ;//商品列表
  604. Cache::set($cid.'-list',$item);
  605. }
  606. $count = count($item)-1;
  607. $numbers=Cache::get($cid.'_nums');
  608. if(!isset($numbers)){
  609. $numbers = 0;
  610. }
  611. $next = $numbers ;
  612. if(count($item)<1){
  613. $msg['error'] = 1;
  614. $msg['txt'] = '虾皮网产品分类ID不正确';
  615. Cache::del($cid.'_nums');
  616. Cache::del($cid.'-list');
  617. echo json_encode($msg);exit;
  618. }
  619. if($count == $next){
  620. $msg['error'] = 111;
  621. $msg['txt'] = '采集已结束';
  622. Cache::del($cid.'_nums');
  623. Cache::del($cid.'-list');
  624. echo json_encode($msg);exit;
  625. }
  626. if(''==$item[$next]['name']){
  627. $msg['error'] = 111;
  628. $msg['txt'] = '采集已结束';
  629. Cache::del($cid.'_nums');
  630. Cache::del($cid.'-list');
  631. echo json_encode($msg);exit;
  632. }
  633. $itemid = $item[$next]['itemid'];
  634. $shopid = $item[$next]['shopid'];
  635. $bundle_deal_id= $item[$next]['bundle_deal_id'];
  636. $str = "";
  637. $thumbnail_img = '';
  638. $photos = array();
  639. $arr = $item[$next]['images'];
  640. $data=[];
  641. $data['description']='';
  642. if($arr){
  643. foreach ($arr as $kk=>$vv){
  644. $PATH = $_SERVER['DOCUMENT_ROOT'].'/';
  645. $photos[] = "https://s-cf-tw.shopeesz.com/file/".$vv;
  646. $data['description'].="<p> <img src='https://s-cf-tw.shopeesz.com/file/".$vv."'> </p>";
  647. }
  648. }
  649. $msg['error'] = 0;
  650. $msg['num'] = $next+1;
  651. $msg['txt'] ='标题:'.$item[$next]['name'].'&nbsp;&nbsp;价格:'.$item[$next]['price']/100000;
  652. $data['name'] = $item[$next]['name']; //标题
  653. $data['photos'] = $photos;//相册
  654. $data['meta_title'] = $item[$next]['name'];//标题
  655. $data['thumbnail_img'] = "https://s-cf-tw.shopeesz.com/file/".$item[$next]['image'];//封面
  656. $data['meta_description'] =$item[$next]['name'];
  657. $data['price'] = $item[$next]['price']/100000;
  658. $data['skuimg'] = array();
  659. $data['size_name'] = array();
  660. $data['brand'] = '';
  661. $data['url'] = '';
  662. $data['uid'] = 24;
  663. $data['cprice'] = $request->cprice;
  664. $data['knum'] = $request->knum;
  665. $data['cat_id'] = $request->web_cat_id;
  666. $data['cpk'] = $request->cpk;
  667. $data['user_id'] = $request->user_id;
  668. $data['purl'] = "https://shopee.sg/api/v2/item/get_ratings?filter=0&flag=1&itemid=$itemid&offset=0&shopid=$shopid&type=0";
  669. $insert_url = 'https://'.$_SERVER['SERVER_NAME'].'/caiji';
  670. $res = $this->get_url($insert_url,json_encode($data));
  671. $msg['txt20'] = $res;
  672. Cache::set($cid.'_nums',$numbers+1);
  673. echo json_encode($msg);exit;
  674. }
  675. public function thcaiji(Request $request){
  676. $num = $request->num+1;
  677. $cid = $request->xiapi_cai_id_th;
  678. $by = $request->by;
  679. $price_max =$request->price_max;
  680. $price_min= $request->price_min;
  681. if($num < 0 || $cid < 0){exit;}
  682. $arrContextOptions = [
  683. 'ssl' => [
  684. 'verify_peer' => false,
  685. 'verify_peer_name' => false,
  686. ]
  687. ];
  688. $item = Cache::get($cid.'-list');
  689. if($item){
  690. $item = $lists = Cache::get($cid.'-list');
  691. } else {
  692. //$url ="https://shopee.co.th/api/v4/search/search_items?by=$by&limit=$num&match_id=$cid&newest=0&order=desc&page_type=search&price_max=$price_max&price_min=$price_min&scenario=PAGE_CATEGORY&version=2";
  693. $url ="https://shopee.co.th/api/v4/recommend/recommend?bundle=category_landing_page&cat_level=1&catid=$cid&limit=$num&offset=0&by=$by&order=desc&page_type=search&price_max=$price_max&price_min=$price_min";
  694. $list = file_get_contents($url, false, stream_context_create($arrContextOptions)); //商品列表
  695. $lists= json_decode($list,1); //商品列表
  696. $item = $lists['data']['sections'][0]['data']['item'] ;//商品列表
  697. Cache::set($cid.'-list',$item);
  698. }
  699. $count = count($item)-1;
  700. $numbers=Cache::get($cid.'_nums');
  701. if(!isset($numbers)){
  702. $numbers = 0;
  703. }
  704. $next = $numbers ;
  705. if(count($item)<1){
  706. $msg['error'] = 1;
  707. $msg['txt'] = '虾皮网产品分类ID不正确';
  708. Cache::del($cid.'_nums');
  709. Cache::del($cid.'-list');
  710. echo json_encode($msg);exit;
  711. }
  712. if($count == $next){
  713. $msg['error'] = 111;
  714. $msg['txt'] = '采集已结束';
  715. Cache::del($cid.'_nums');
  716. Cache::del($cid.'-list');
  717. echo json_encode($msg);exit;
  718. }
  719. if(''==$item[$next]['name']){
  720. $msg['error'] = 111;
  721. $msg['txt'] = '采集已结束';
  722. Cache::del($cid.'_nums');
  723. Cache::del($cid.'-list');
  724. echo json_encode($msg);exit;
  725. }
  726. $itemid = $item[$next]['itemid'];
  727. $shopid = $item[$next]['shopid'];
  728. $bundle_deal_id= $item[$next]['bundle_deal_id'];
  729. $str = "";
  730. $thumbnail_img = '';
  731. $photos = array();
  732. $arr = $item[$next]['images'];
  733. $data=[];
  734. $data['description']='';
  735. if($arr){
  736. foreach ($arr as $kk=>$vv){
  737. $PATH = $_SERVER['DOCUMENT_ROOT'].'/';
  738. $photos[] = "https://s-cf-tw.shopeesz.com/file/".$vv;
  739. $data['description'].="<p> <img src='https://s-cf-tw.shopeesz.com/file/".$vv."'> </p>";
  740. }
  741. }
  742. $msg['error'] = 0;
  743. $msg['num'] = $next+1;
  744. $msg['txt'] ='标题:'.$item[$next]['name'].'&nbsp;&nbsp;价格:'.$item[$next]['price']/100000;
  745. $data['name'] = $item[$next]['name']; //标题
  746. $data['photos'] = $photos;//相册
  747. $data['meta_title'] = $item[$next]['name'];//标题
  748. $data['thumbnail_img'] = "https://s-cf-tw.shopeesz.com/file/".$item[$next]['image'];//封面
  749. $data['meta_description'] =$item[$next]['name'];
  750. $data['price'] = $item[$next]['price']/100000;
  751. $data['skuimg'] = array();
  752. $data['size_name'] = array();
  753. $data['brand'] = '';
  754. $data['url'] = '';
  755. $data['uid'] = 24;
  756. $data['cprice'] = $request->cprice;
  757. $data['knum'] = $request->knum;
  758. $data['cat_id'] = $request->web_cat_id;
  759. $data['cpk'] = $request->cpk;
  760. $data['user_id'] = $request->user_id;
  761. $data['purl'] = "https://shopee.co.th/api/v2/item/get_ratings?filter=0&flag=1&itemid=$itemid&offset=0&shopid=$shopid&type=0";
  762. $insert_url = 'https://'.$_SERVER['SERVER_NAME'].'/caiji';
  763. $res = $this->get_url($insert_url,json_encode($data));
  764. $msg['txt20'] = $res;
  765. Cache::set($cid.'_nums',$numbers+1);
  766. echo json_encode($msg);exit;
  767. }
  768. public function get_url($url, $fields = array(), $UserAgent = null, $vfSSL = false) {
  769. $SSL = substr($url, 0, 8) == "https://" ? true : false;
  770. $ch = curl_init();
  771. if ($UserAgent) { // 在HTTP请求中包含一个"User-Agent: "头的字符串。
  772. curl_setopt($ch, CURLOPT_USERAGENT, $UserAgent);
  773. } else {
  774. curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
  775. }
  776. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); // 在发起连接前等待的时间,如果设置为0,则无限等待
  777. curl_setopt($ch, CURLOPT_TIMEOUT, 90); // 设置cURL允许执行的最长秒数
  778. curl_setopt($ch, CURLOPT_URL, $url); // 设置请求地址
  779. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
  780. // SSL验证
  781. if ($SSL) {
  782. if ($vfSSL) {
  783. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  784. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  785. curl_setopt($ch, CURLOPT_CAINFO, CORE_PATH . '/cacert.pem');
  786. } else {
  787. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
  788. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 不检查证书中是否设置域名
  789. }
  790. }
  791. // 数据字段
  792. if ($fields) {
  793. curl_setopt($ch, CURLOPT_POST, true);
  794. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  795. }
  796. $output = curl_exec($ch);
  797. if (curl_errno($ch)) {
  798. error('请求远程地址错误:' . curl_error($ch));
  799. }
  800. curl_close($ch);
  801. return $output;
  802. }
  803. public function add_more_choice_option( Request $request ) {
  804. $all_attribute_values = AttributeValue::with('attribute')->where('attribute_id', $request->attribute_id)->get();
  805. $html = '';
  806. foreach ( $all_attribute_values as $row )
  807. {
  808. $html .= '<option value="' . $row->value . '">' . $row->value . '</option>';
  809. }
  810. echo json_encode($html);
  811. }
  812. /**
  813. * Store a newly created resource in storage.
  814. *
  815. * @param \Illuminate\Http\Request $request
  816. *
  817. * @return \Illuminate\Http\Response
  818. */
  819. public function store( ProductRequest $request ) {
  820. $product = $this->productService->store($request->except([
  821. '_token', 'sku', 'choice', 'tax_id', 'tax', 'tax_type', 'flash_deal_id', 'flash_discount', 'flash_discount_type',
  822. ]));
  823. $request->merge([ 'product_id' => $product->id ]);
  824. //VAT & Tax
  825. if ( $request->tax_id )
  826. {
  827. $this->productTaxService->store($request->only([
  828. 'tax_id', 'tax', 'tax_type', 'product_id',
  829. ]));
  830. }
  831. //Flash Deal
  832. $this->productFlashDealService->store($request->only([
  833. 'flash_deal_id', 'flash_discount', 'flash_discount_type',
  834. ]), $product);
  835. //Product Stock
  836. $this->productStockService->store($request->only([
  837. 'colors_active', 'colors', 'choice_no', 'unit_price', 'sku', 'current_stock', 'product_id',
  838. ]), $product);
  839. // Product Translations
  840. $request->merge([ 'lang' => env('DEFAULT_LANGUAGE') ]);
  841. ProductTranslation::create($request->only([
  842. 'lang', 'name', 'unit', 'description', 'product_id',
  843. ]));
  844. flash(translate('Product has been inserted successfully'))->success();
  845. Artisan::call('view:clear');
  846. Artisan::call('cache:clear');
  847. return redirect()->route('products.admin');
  848. }
  849. /**
  850. * Display the specified resource.
  851. *
  852. * @param int $id
  853. *
  854. * @return \Illuminate\Http\Response
  855. */
  856. public function show( $id ) {
  857. //
  858. }
  859. /**
  860. * Show the form for editing the specified resource.
  861. *
  862. * @param int $id
  863. *
  864. * @return \Illuminate\Http\Response
  865. */
  866. public function admin_product_edit( Request $request, $id ) {
  867. CoreComponentRepository::initializeCache();
  868. $product = Product::findOrFail($id);
  869. if ( $product->digital == 1 )
  870. {
  871. return redirect('admin/digitalproducts/' . $id . '/edit');
  872. }
  873. $lang = $request->lang;
  874. $tags = json_decode($product->tags);
  875. $categories = Category::where('parent_id', 0)
  876. ->where('digital', 0)
  877. ->with('childrenCategories')
  878. ->get();
  879. return view('backend.product.products.edit', compact('product', 'categories', 'tags', 'lang'));
  880. }
  881. /**
  882. * Show the form for editing the specified resource.
  883. *
  884. * @param int $id
  885. *
  886. * @return \Illuminate\Http\Response
  887. */
  888. public function seller_product_edit( Request $request, $id ) {
  889. $product = Product::findOrFail($id);
  890. if ( $product->digital == 1 )
  891. {
  892. return redirect('digitalproducts/' . $id . '/edit');
  893. }
  894. $lang = $request->lang;
  895. $tags = json_decode($product->tags);
  896. // $categories = Category::all();
  897. $categories = Category::where('parent_id', 0)
  898. ->where('digital', 0)
  899. ->with('childrenCategories')
  900. ->get();
  901. return view('backend.product.products.edit', compact('product', 'categories', 'tags', 'lang'));
  902. }
  903. /**
  904. * Update the specified resource in storage.
  905. *
  906. * @param \Illuminate\Http\Request $request
  907. * @param int $id
  908. *
  909. * @return \Illuminate\Http\Response
  910. */
  911. public function update( ProductRequest $request, Product $product ) {
  912. //Product
  913. $product = $this->productService->update($request->except([
  914. '_token', 'sku', 'choice', 'tax_id', 'tax', 'tax_type', 'flash_deal_id', 'flash_discount', 'flash_discount_type',
  915. ]), $product);
  916. //Product Stock
  917. foreach ( $product->stocks as $key => $stock )
  918. {
  919. $stock->delete();
  920. }
  921. $request->merge([ 'product_id' => $product->id ]);
  922. $this->productStockService->store($request->only([
  923. 'colors_active', 'colors', 'choice_no', 'unit_price', 'sku', 'current_stock', 'product_id',
  924. ]), $product);
  925. //Flash Deal
  926. $this->productFlashDealService->store($request->only([
  927. 'flash_deal_id', 'flash_discount', 'flash_discount_type',
  928. ]), $product);
  929. //VAT & Tax
  930. if ( $request->tax_id )
  931. {
  932. ProductTax::where('product_id', $product->id)->delete();
  933. $request->merge([ 'product_id' => $product->id ]);
  934. $this->productTaxService->store($request->only([
  935. 'tax_id', 'tax', 'tax_type', 'product_id',
  936. ]));
  937. }
  938. // Product Translations
  939. ProductTranslation::updateOrCreate(
  940. $request->only([
  941. 'lang', 'product_id',
  942. ]),
  943. $request->only([
  944. 'name', 'unit', 'description',
  945. ])
  946. );
  947. flash(translate('Product has been updated successfully'))->success();
  948. Artisan::call('view:clear');
  949. Artisan::call('cache:clear');
  950. return back();
  951. }
  952. /**
  953. * Remove the specified resource from storage.
  954. *
  955. * @param int $id
  956. *
  957. * @return \Illuminate\Http\Response
  958. */
  959. public function destroy( $id ) {
  960. $product = Product::findOrFail($id);
  961. $product->product_translations()->delete();
  962. $product->stocks()->delete();
  963. $product->taxes()->delete();
  964. if ( Product::destroy($id) )
  965. {
  966. Cart::where('product_id', $id)->delete();
  967. flash(translate('Product has been deleted successfully'))->success();
  968. Artisan::call('view:clear');
  969. Artisan::call('cache:clear');
  970. return back();
  971. }
  972. else
  973. {
  974. flash(translate('Something went wrong'))->error();
  975. return back();
  976. }
  977. }
  978. public function bulk_product_delete( Request $request ) {
  979. if ( $request->id )
  980. {
  981. foreach ( $request->id as $product_id )
  982. {
  983. $this->destroy($product_id);
  984. }
  985. }
  986. return 1;
  987. }
  988. /**
  989. * Duplicates the specified resource from storage.
  990. *
  991. * @param int $id
  992. *
  993. * @return \Illuminate\Http\Response
  994. */
  995. public function duplicate( Request $request, $id ) {
  996. $product = Product::find($id);
  997. $product_new = $product->replicate();
  998. $product_new->slug = $product_new->slug . '-' . Str::random(5);
  999. $product_new->save();
  1000. //Product Stock
  1001. $this->productStockService->product_duplicate_store($product->stocks, $product_new);
  1002. //VAT & Tax
  1003. $this->productTaxService->product_duplicate_store($product->taxes, $product_new);
  1004. flash(translate('Product has been duplicated successfully'))->success();
  1005. if ( $request->type == 'In House' )
  1006. return redirect()->route('products.admin');
  1007. else if ( $request->type == 'Seller' )
  1008. return redirect()->route('products.seller');
  1009. else if ( $request->type == 'All' )
  1010. return redirect()->route('products.all');
  1011. }
  1012. public function get_products_by_brand( Request $request ) {
  1013. $products = Product::where('brand_id', $request->brand_id)->get();
  1014. return view('partials.product_select', compact('products'));
  1015. }
  1016. public function updateTodaysDeal( Request $request ) {
  1017. $product = Product::findOrFail($request->id);
  1018. $product->todays_deal = $request->status;
  1019. $product->save();
  1020. Cache::forget('todays_deal_products');
  1021. return 1;
  1022. }
  1023. public function updatePublished( Request $request ) {
  1024. $product = Product::findOrFail($request->id);
  1025. $product->published = $request->status;
  1026. if ( $product->added_by == 'seller' && addon_is_activated('seller_subscription') && $request->status == 1 )
  1027. {
  1028. $shop = $product->user->shop;
  1029. if (
  1030. $shop->package_invalid_at == NULL
  1031. || Carbon::now()->diffInDays(Carbon::parse($shop->package_invalid_at), false) < 0
  1032. || $shop->product_upload_limit <= $shop->user->products()->where('published', 1)->count()
  1033. )
  1034. {
  1035. return 0;
  1036. }
  1037. }
  1038. $product->save();
  1039. Artisan::call('view:clear');
  1040. Artisan::call('cache:clear');
  1041. return 1;
  1042. }
  1043. public function updateProductApproval( Request $request ) {
  1044. $product = Product::findOrFail($request->id);
  1045. $product->approved = $request->approved;
  1046. if ( $product->added_by == 'seller' && addon_is_activated('seller_subscription') )
  1047. {
  1048. $shop = $product->user->shop;
  1049. if (
  1050. $shop->package_invalid_at == NULL
  1051. || Carbon::now()->diffInDays(Carbon::parse($shop->package_invalid_at), false) < 0
  1052. || $shop->product_upload_limit <= $shop->user->products()->where('published', 1)->count()
  1053. )
  1054. {
  1055. return 0;
  1056. }
  1057. }
  1058. $product->save();
  1059. Artisan::call('view:clear');
  1060. Artisan::call('cache:clear');
  1061. return 1;
  1062. }
  1063. public function updateFeatured( Request $request ) {
  1064. $product = Product::findOrFail($request->id);
  1065. $product->featured = $request->status;
  1066. if ( $product->save() )
  1067. {
  1068. Artisan::call('view:clear');
  1069. Artisan::call('cache:clear');
  1070. return 1;
  1071. }
  1072. return 0;
  1073. }
  1074. public function sku_combination( Request $request ) {
  1075. $options = [];
  1076. if ( $request->has('colors_active') && $request->has('colors') && count($request->colors) > 0 )
  1077. {
  1078. $colors_active = 1;
  1079. array_push($options, $request->colors);
  1080. }
  1081. else
  1082. {
  1083. $colors_active = 0;
  1084. }
  1085. $unit_price = $request->unit_price;
  1086. $product_name = $request->name;
  1087. if ( $request->has('choice_no') )
  1088. {
  1089. foreach ( $request->choice_no as $key => $no )
  1090. {
  1091. $name = 'choice_options_' . $no;
  1092. $data = [];
  1093. // foreach (json_decode($request[$name][0]) as $key => $item) {
  1094. foreach ( $request[$name] as $key => $item )
  1095. {
  1096. // array_push($data, $item->value);
  1097. array_push($data, $item);
  1098. }
  1099. array_push($options, $data);
  1100. }
  1101. }
  1102. $combinations = Combinations::makeCombinations($options);
  1103. return view('backend.product.products.sku_combinations', compact('combinations', 'unit_price', 'colors_active', 'product_name'));
  1104. }
  1105. public function sku_combination_edit( Request $request ) {
  1106. $product = Product::findOrFail($request->id);
  1107. $options = [];
  1108. if ( $request->has('colors_active') && $request->has('colors') && count($request->colors) > 0 )
  1109. {
  1110. $colors_active = 1;
  1111. array_push($options, $request->colors);
  1112. }
  1113. else
  1114. {
  1115. $colors_active = 0;
  1116. }
  1117. $product_name = $request->name;
  1118. $unit_price = $request->unit_price;
  1119. if ( $request->has('choice_no') )
  1120. {
  1121. foreach ( $request->choice_no as $key => $no )
  1122. {
  1123. $name = 'choice_options_' . $no;
  1124. $data = [];
  1125. // foreach (json_decode($request[$name][0]) as $key => $item) {
  1126. foreach ( $request[$name] as $key => $item )
  1127. {
  1128. // array_push($data, $item->value);
  1129. array_push($data, $item);
  1130. }
  1131. array_push($options, $data);
  1132. }
  1133. }
  1134. $combinations = Combinations::makeCombinations($options);
  1135. return view('backend.product.products.sku_combinations_edit', compact('combinations', 'unit_price', 'colors_active', 'product_name', 'product'));
  1136. }
  1137. /**
  1138. * Display a listing of the resource.
  1139. *
  1140. * @return \Illuminate\Http\Response
  1141. */
  1142. public function depository_products( Request $request ) {
  1143. CoreComponentRepository::instantiateShopRepository();
  1144. $type = 'In House';
  1145. $col_name = NULL;
  1146. $query = NULL;
  1147. $sort_search = NULL;
  1148. $products = Product::where('added_by', 'admin')->where('auction_product', 0)->where('wholesale_product', 0);
  1149. if ( $request->type != NULL )
  1150. {
  1151. $var = explode(",", $request->type);
  1152. $col_name = $var[0];
  1153. $query = $var[1];
  1154. $products = $products->orderBy($col_name, $query);
  1155. $sort_type = $request->type;
  1156. }
  1157. if ( $request->search != NULL )
  1158. {
  1159. $sort_search = $request->search;
  1160. $products = $products
  1161. ->where('name', 'like', '%' . $sort_search . '%')
  1162. ->orWhereHas('stocks', function ( $q ) use ( $sort_search )
  1163. {
  1164. $q->where('sku', 'like', '%' . $sort_search . '%');
  1165. });
  1166. }
  1167. $products = $products->where('digital', 0)->orderBy('created_at', 'desc')->paginate(15);
  1168. return view('backend.product.products.index', compact('products', 'type', 'col_name', 'query', 'sort_search'));
  1169. }
  1170. }