TestGoods.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. public function testSetLowprice()
  66. {
  67. $mod = Model('goods');
  68. $i = 0;
  69. while (true)
  70. {
  71. $start = $i * 1000;
  72. $items = $mod->field('goods_id,goods_price')->order('goods_id asc')->limit("{$start},1000")->select();
  73. if(empty($items)) {
  74. return;
  75. }
  76. $i++;
  77. foreach ($items as $item)
  78. {
  79. $gid = intval($item['goods_id']);
  80. if($gid <= 0) continue;
  81. $price_cent = intval(doubleval($item['goods_price']) * 100 + 0.5);
  82. $lowest_price = intval($price_cent / 2) / 100;
  83. $mod->editGoods(['goods_lowest_price' => $lowest_price],['goods_id' => $gid]);
  84. }
  85. }
  86. }
  87. }