function makeOfferIn($basket, $universe, $peopleId, $companyId, $companyaddress_id, $delivery = [], $geo = []) { $collection = $collectionPush = []; $company = Model::Company()->find($companyId); $people = Model::People()->find($peopleId); if ($company && $people) { $companyStatus = isAke($company->assoc(), 'status_id', getStatus('UNCHECKED')); $offers = []; if (!empty($basket)) { $i = 0; foreach ($basket as $article) { $dir = realpath(APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'files' . DS . $universe . DS . 'users' . DS . $peopleId . DS . 'tmp_basket' . DS . $i); if ($dir) { $files = glob($dir . DS . '*'); if (!empty($files)) { foreach ($files as $file) { $article['attach'][] = $file; } } } $market = 0; $item_id = isake($article, 'item_id', 0); if (0 >= $item_id) { $market = isAke($article, 'market', 0); } else { $family = repo('segment')->getFamilyfromItem($item_id); if (!empty($family)) { $market = current($family); $market = isAke($market, 'id', 0); } } if (0 < $market) { unset($article['family']); $offers[$market][] = $article; } $i++; } } if (!empty($offers)) { foreach ($offers as $idMarket => $articles) { $statusOffer = $companyStatus == getStatus('UNCHECKED') ? getStatus('WAIT') : getStatus('OK'); $offer = bigDb('offerin')->create(['global' => true, 'companyaddress_id' => $companyaddress_id, 'delivery_date' => isAke($delivery, 'date', null), 'delivery_type' => isAke($delivery, 'type', null), 'delivery_moment' => isAke($delivery, 'moment', null), 'expiration' => strtotime('+1 month'), 'universe' => $universe, 'market' => (int) $idMarket, 'status_id' => (int) $statusOffer, 'date' => time(), 'zip' => $company->zip, 'people_id' => (int) $peopleId, 'company_id' => $companyId])->save(); foreach ($geo as $g) { bigDb('offeringeo')->create(['offerin_id' => $offer->id, 'type' => isAke($g, 'type'), isAke($g, 'type') . '_id' => isAke($g, 'id'), 'range' => isAke($g, 'range')])->save(); } foreach ($articles as $art) { $options_comp_name = isAke($art, 'options_comp_name'); $options_comp_val = isAke($art, 'options_comp_val'); $item_id = isAke($article, 'item_id', 0); if (0 == $item_id) { $statusOffer = (int) getStatus('ADV'); $offer = $offer->setStatusId($statusOffer)->save(); } if (!empty($options_comp_name) && !empty($options_comp_val)) { /* On cherche les doublons d'option le cas échéant */ list($options_comp_name, $options_comp_val) = cleanOptCompOfferIn($options_comp_name, $options_comp_val); $art['options_comp_name'] = $options_comp_name; $art['options_comp_val'] = $options_comp_val; } $attach = isAke($art, 'attach', []); unset($art['attach']); $art['offerin_id'] = $offer->id; $a = bigDb('articlein')->create($art)->save(); if (!empty($attach)) { $dirOffer = APPLICATION_PATH . DS . '..' . DS . 'public' . DS . 'files' . DS . $universe . DS . 'offer_in'; if (!is_dir($dirOffer)) { File::mkdir($dirOffer); } $dirOffer .= DS . $offer->id; if (!is_dir($dirOffer)) { File::mkdir($dirOffer); } $dirOffer .= DS . $a->id; if (!is_dir($dirOffer)) { File::mkdir($dirOffer); } foreach ($attach as $f) { $tab = explode(DS, $f); $nameAttach = Arrays::last($tab); $newFile = $dirOffer . DS . $nameAttach; File::copy($f, $newFile); File::delete($f); } } } array_push($collection, $offer->assoc()); if ($statusOffer == getStatus('OK')) { array_push($collectionPush, $offer->assoc()); } } } } if (!empty($collectionPush)) { $resellers = lib('bourse')->getResellersByOffer($collectionPush); $employees = lib('bourse')->getEmployeesToNotif($resellers, $collectionPush); lib('bourse')->push($employees); } return $collection; }