TestGoods.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/9/15
  6. * Time: 下午6:03
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. class TestGoods extends PHPUnit_Framework_TestCase
  11. {
  12. public static function setUpBeforeClass()
  13. {
  14. Base::run_util();
  15. }
  16. public function testAddSku()
  17. {
  18. $path = BASE_DATA_PATH . "/sales/sku.csv";
  19. $lines = explode("\r",$this->read_file($path));
  20. $mod_price = Model('');
  21. foreach($lines as $line)
  22. {
  23. $row = explode(';',$line);
  24. $omsid = intval($row[0]);
  25. $market_price = intval($row[1] * 100 + 0.5) / 100;
  26. $purchase_price = intval($row[2] * 100 + 0.5) / 100;
  27. $sku_price = intval($row[3] * 100 + 0.5) / 100;
  28. if($omsid <= 0) continue;
  29. $val = ['omsid' => $omsid,'purchase_price' => $purchase_price,'market_price' => $market_price,'sku_price' => $sku_price];
  30. $ret = $mod_price->table('goods_orgprice')->insert($val);
  31. if($ret == false) {
  32. Log::record("cannot insert row",Log::DEBUG);
  33. }
  34. }
  35. }
  36. private function read_file($path)
  37. {
  38. $file = fopen($path, "r");
  39. $datas = '';
  40. while (!feof($file)) {
  41. $datas .= fgets($file);
  42. }
  43. return $datas;
  44. }
  45. public function testEvaluate()
  46. {
  47. $mod = Model('goods');
  48. $i = 0;
  49. while (true)
  50. {
  51. $start = $i * 1000;
  52. $items = Model()->table('evaluate_goods')->field('geval_commonid,geval_goodsid')->order('geval_id asc')->limit("{$start},1000")->select();
  53. if(empty($items)) {
  54. return;
  55. }
  56. $i++;
  57. foreach ($items as $item)
  58. {
  59. $cid = intval($item['geval_commonid']);
  60. if($cid <= 0) continue;
  61. $mod->editGoodsCommon(['comments' => array('exp', "comments+1")],['goods_commonid' => $cid]);
  62. }
  63. }
  64. }
  65. }