public static function _init() { $subquery = \DB::select('price.id')->from(array(Model_Price::table(), 'price'))->where('price.product_id', '=', \DB::expr(\DB::quote_identifier('product.id')))->where('price.available', 1)->order_by('price.price')->limit(1); static::$_valid_relations['has_one'] = 'Indigo\\Erp\\Stock\\HasOne'; static::$_has_one['price']['key_from'] = array('id', $subquery); static::$_has_one['price']['key_to'] = array('product_id', 'id'); static::$_has_many['prices'] = array('model_to' => 'Model_Price', 'cascade_delete' => true); }
public function execute($job, $data) { // Trigger price update/change event and modify data $data = \Event::instance('supplier')->trigger('update', $data, 'array'); $data = call_user_func_array('\\Arr::merge_assoc', $data); // This is all about update $data = $data[0]; // Do not update some fields $set = \Arr::filter_keys($data, array('external_id', 'supplier_id'), true); $data['updated_at'] = time(); return Model_Price::query()->set($set)->where('external_id', $data['external_id'])->where('supplier_id', $data['supplier_id'])->update(); }
/** * 增加价格配置段 */ public function addAction() { if ($this->_request->isPost()) { $aPrice = $this->_checkData('add'); if (empty($aPrice)) { return null; } if (Model_Price::addData($aPrice) > 0) { return $this->showMsg('价格配置段增加成功!', true); } else { return $this->showMsg('价格配置段增加失败!', false); } } }
public function execute($job, $data) { return Model_Price::query()->set(array('available' => \Arr::get($data, 'key', 1), 'updated_at' => time()))->where('external_id', 'IN', \Arr::get($data, 'ids'))->where('supplier_id', \Arr::get($data, 'supplier_id'))->update(); }
/** * Update price and availability * * @param boolean $cached Update from already downloaded files * @return boolean All products have been processed */ public function change($cached = false) { // Get data from supplier if (!($products = $this->_change($cached))) { return true; } // Get current prices from supplier $price = \DB::select('external_id', 'price', 'available')->from(Model_Price::table())->where('supplier_id', $this->model->id)->execute()->as_array('external_id'); // Cast values to the appropriate data type array_walk($price, function (&$product, $id) use(&$price) { $product['price'] = \Num::currency($product['price']); $product['available'] = intval($product['available']); unset($price[$id]['external_id']); }); $count = array(0); $available = array(); foreach ($products as $id => $product) { // Are we sure that it exists? if (!array_key_exists($id, $price)) { continue; } // Default data casting and values $product['price'] = \Arr::get($product, 'price'); is_null($product['price']) or $product['price'] = \Num::currency($product['price']); $a = \Arr::get($product, 'available'); // Check if product's price has been changed, or just became (un)available if (!is_null($product['price'])) { // Foolproofness: set the update array manually $product = array('price' => $product['price'], 'external_id' => $id, 'supplier_id' => $this->model->id); // Update availability if changed is_null($a) or $product['available'] = $a; // Get job and queue $job = $this->get_config('change.job', 'Indigo\\Erp\\Stock\\Job_Supplier_Change'); $queue = $this->get_config('change.queue', 'update'); // Use Queue if available (greater performance) if (\Package::loaded('queue')) { $count[0] += \Queue::push($queue, $job, array($product, $price[$id])) ? 1 : 0; } else { try { $job = new $job(); $count[0] += $job->execute(null, $product); } catch (\Exception $e) { } } } elseif (!is_null($a)) { $available[$a][] = $id; } } // Update availability information $available = $this->_available($available); $count[1] = $available[0]; $count[2] = $available[1]; // Set the last updated time for supplier prices $this->model->set('last_update', time())->save(); // Log success \Log::info($this->model->name . ' frissítve: ' . $count[0] . ' frissítés, ' . $count[1] . ' lett elérhetetlen, ' . $count[2] . ' lett elérhető.'); // All product have been processed return array_sum($count) == count($products); }
public function execute($job, $data) { return Model_Price::forge()->set($data)->save(); }
/** * 自媒体中心 */ public function indexAction() { $aParam = $this->getParams(); $aParam['type'] = isset($aParam['type']) ? intval($aParam['type']) : Model_Media::TYPE_WEIXIN; $iAdID = (int) $this->getParam('id'); $aAd = null; if ($iAdID > 0) { $aAd = Model_Ad::getDetail($iAdID); } if (!empty($aAd)) { $aParam['type'] = $aAd['iMediaType']; $sReferer = $this->getRequest()->getHttpReferer(); if (strpos($sReferer, '/ad/add') > 0) { if (!empty($aAd['sCatID'])) { $aParam['catid'] = intval($aAd['sCatID']); } if (!empty($aAd['sCityID'])) { $aParam['city'] = explode(',', $aAd['sCityID']); } } } $aData = Model_Media::search($aParam); foreach ($aData['aList'] as &$aRow) { $aRow['sCatName'] = Model_Media::getCategoryNames($aRow['iMediaID']); } switch ($aParam['type']) { case Model_Media::TYPE_WEIXIN: $aData['aType'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIXIN_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIXIN_TAG); break; case Model_Media::TYPE_FRIEND: $aData['aType'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_FRIEND_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_FRIEND_TAG); break; case Model_Media::TYPE_WEIBO: $aData['aType'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIBO_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIBO_TAG); break; case Model_Media::TYPE_NEWS: $aData['aType'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_NEWS_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_NEWS_TAG); break; } $aData['aPrice'] = Model_Price::getOption(); $aData['aFollower'] = Model_Follower::getOption(); $aData['aCity'] = Model_City::getPairCitys(Model_City::TYPE_FRONT); $aData['aLevel'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_RECOMMEND); $aData['aAd'] = $aAd; if (!empty($aData['aAd'])) { $aData['aChooseID'] = Model_AdMedia::getCol(array('where' => array('iStatus >' => 0, 'iAdID' => $iAdID)), 'iMediaID'); } if (empty($aData['aChooseID'])) { $sCookieKey = 'media_choose_' . $aParam['type']; $aData['aChooseID'] = !empty($_COOKIE[$sCookieKey]) ? explode(',', $_COOKIE[$sCookieKey]) : array(); } $aData['aChoose'] = array(); foreach ($aData['aChooseID'] as $k => $v) { $aMedia = Model_Media::getDetail($v); if (empty($aMedia)) { continue; } $aData['aChoose'][] = $aMedia; } $this->assign('aData', $aData); $this->assign('aParam', $aParam); $this->assign('sTopMenu', empty($aAd) ? 'media' : 'aadd'); $this->setMeta('media_center', array('sTitle' => '媒体中心')); }
/** * 搜索自媒体 * * @param unknown $aParam * @param string $sOrder * @param number $iPageSize * @return Ambigous <NULL, boolean, string, multitype:multitype: Ambigous <> , multitype:, array/string, int/false, number, unknown, unknown> */ public static function search($aParam, $sOrder = '', $iPageSize = 20) { $aRule = array(); $aTable = array('t_media m'); $aWhere = array('m.iStatus=1', 'm.iPut=1', 'm.iMediaType=' . intval($aParam['type'])); if (!empty($aParam['name'])) { $aWhere[] = '(m.sMediaName LIKE "%' . $aParam['name'] . '%" OR m.sOpenName LIKE "%' . $aParam['name'] . '%")'; } if (!empty($aParam['catid'])) { $aTable[] = 't_media_category c'; $aWhere[] = 'c.iMediaID=m.iMediaID'; $aWhere[] = 'c.iCategoryID=' . intval($aParam['catid']); //$aWhere[] = 'c.iCategoryID IN(' . join(',', $aParam['catid']) . ')'; } if (!empty($aParam['price'])) { $aPrice = Model_Price::parsePrice($aParam['price']); $aWhere[] = '(m.iPrice1>=' . $aPrice[0] . ' AND m.iPrice1<' . $aPrice[1] . ' OR m.iPrice2>=' . $aPrice[0] . ' AND m.iPrice2<' . $aPrice[1] . ')'; } if (!empty($aParam['follower'])) { $aFollower = explode('~', $aParam['follower']); $aWhere[] = '(m.iFollowerNum>=' . $aFollower[0] . ' AND m.iFollowerNum<' . $aFollower[1] . ')'; } if (!empty($aParam['city'])) { $aTable[] = 't_media_city ct'; $aWhere[] = 'ct.iMediaID=m.iMediaID'; $aWhere[] = 'ct.iCityID IN(' . join(',', $aParam['city']) . ')'; } if (!empty($aParam['readnum0'])) { $aWhere[] = 'm.iReadAvgNum >=' . intval($aParam['readnum0']); } if (!empty($aParam['readnum1'])) { $aWhere[] = 'm.iReadAvgNum <=' . intval($aParam['readnum1']); } if (!empty($aParam['score'])) { $aWhere[] = 'm.iScore >=' . intval($aParam['score']); } if (!empty($aParam['tag'])) { $aTable[] = 't_media_tag t'; $aWhere[] = 't.iMediaID=m.iMediaID'; $aWhere[] = 't.iTagID IN(' . join(',', $aParam['tag']) . ')'; } /* if (! empty($aParam['aCriceID'])) { $aTable[] = 't_media_cricle cr'; $aWhere[] = 'cr.iMediaID=m.iMediaID'; $aWhere[] = 'cr.iCricleID IN(' . join(',', $aParam['aCriceID']) . ')'; } */ $iPage = max(intval($aParam['page']), 1); $sLimit = ' LIMIT ' . ($iPage - 1) * $iPageSize . ',' . $iPageSize; $sOrder = empty($sOrder) ? '' : ' ORDER BY ' . $sOrder; $sSQL = 'SELECT m.* FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere) . ' GROUP BY m.iMediaID' . $sOrder . $sLimit; $aRet['aList'] = self::query($sSQL); if ($iPage == 1 && count($aRet['aList']) < $iPageSize) { $aRet['iTotal'] = count($aRet['aList']); $aRet['aPager'] = null; } else { unset($aParam['limit'], $aParam['order']); $sSQL = 'SELECT COUNT(DISTINCT m.iMediaID) FROM ' . join(',', $aTable) . ' WHERE ' . join(' AND ', $aWhere); $aRet['iTotal'] = self::query($sSQL, 'one'); $sUrl = Util_Common::getUrl(); $aRet['aPager'] = Util_Page::getPage($aRet['iTotal'], $iPage, $iPageSize, $sUrl, $aParam); } return $aRet; }