123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/9/15
- * Time: 下午6:03
- */
- define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
- require_once(BASE_ROOT_PATH . '/fooder.php');
- class TestGoods extends PHPUnit_Framework_TestCase
- {
- public static function setUpBeforeClass()
- {
- Base::run_util();
- }
- public function testAddSku()
- {
- $path = BASE_DATA_PATH . "/sales/sku.csv";
- $lines = explode("\r",$this->read_file($path));
- $mod_price = Model('');
- foreach($lines as $line)
- {
- $row = explode(';',$line);
- $omsid = intval($row[0]);
- $market_price = intval($row[1] * 100 + 0.5) / 100;
- $purchase_price = intval($row[2] * 100 + 0.5) / 100;
- $sku_price = intval($row[3] * 100 + 0.5) / 100;
- if($omsid <= 0) continue;
- $val = ['omsid' => $omsid,'purchase_price' => $purchase_price,'market_price' => $market_price,'sku_price' => $sku_price];
- $ret = $mod_price->table('goods_orgprice')->insert($val);
- if($ret == false) {
- Log::record("cannot insert row",Log::DEBUG);
- }
- }
- }
- private function read_file($path)
- {
- $file = fopen($path, "r");
- $datas = '';
- while (!feof($file)) {
- $datas .= fgets($file);
- }
- return $datas;
- }
- public function testEvaluate()
- {
- $mod = Model('goods');
- $i = 0;
- while (true)
- {
- $start = $i * 1000;
- $items = Model()->table('evaluate_goods')->field('geval_commonid,geval_goodsid')->order('geval_id asc')->limit("{$start},1000")->select();
- if(empty($items)) {
- return;
- }
- $i++;
- foreach ($items as $item)
- {
- $cid = intval($item['geval_commonid']);
- if($cid <= 0) continue;
- $mod->editGoodsCommon(['comments' => array('exp', "comments+1")],['goods_commonid' => $cid]);
- }
- }
- }
- public function testSetLowprice()
- {
- $mod = Model('goods');
- $i = 0;
- while (true)
- {
- $start = $i * 1000;
- $items = $mod->field('goods_id,goods_price')->order('goods_id asc')->limit("{$start},1000")->select();
- if(empty($items)) {
- return;
- }
- $i++;
- foreach ($items as $item)
- {
- $gid = intval($item['goods_id']);
- if($gid <= 0) continue;
- $price_cent = intval(doubleval($item['goods_price']) * 100 + 0.5);
- $lowest_price = intval($price_cent / 2) / 100;
- $mod->editGoods(['goods_lowest_price' => $lowest_price],['goods_id' => $gid]);
- }
- }
- }
- }
|