Browse Source

add width and height,add skuprice

stanley-king 7 years atrás
parent
commit
0787e33ccd

+ 38 - 0
crontab/control/date.php

@@ -151,6 +151,10 @@ class dateControl extends BaseCronControl
             }
         }
     }
+    public function skupriceOp()
+    {
+        $this->add_sku();
+    }
 
     private function update_invitee($invitorid,$userid)
     {
@@ -1158,4 +1162,38 @@ class dateControl extends BaseCronControl
             }
         }
     }
+    private function add_sku()
+    {
+        $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;
+    }
 }

File diff suppressed because it is too large
+ 1 - 0
data/sales/sku.csv


+ 207 - 0
helper/tools/fast_image.php

@@ -0,0 +1,207 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/9/15
+ * Time: 下午4:37
+ */
+
+namespace tools;
+
+class fast_image
+{
+    private $strpos = 0;
+    private $str;
+    private $type;
+    private $handle;
+
+    public function __construct($uri = null)
+    {
+        if ($uri) $this->load($uri);
+    }
+    public function load($uri)
+    {
+        if ($this->handle) $this->close();
+        $this->handle = fopen($uri, 'r');
+    }
+
+    public function close()
+    {
+        if ($this->handle)
+        {
+            fclose($this->handle);
+            $this->handle = null;
+            $this->type = null;
+            $this->str = null;
+        }
+    }
+    public function getSize()
+    {
+        $this->strpos = 0;
+        if ($this->getType()) {
+            return array_values($this->parseSize());
+        }
+
+        return false;
+    }
+    public function getType()
+    {
+        $this->strpos = 0;
+
+        if (!$this->type)
+        {
+            switch ($this->getChars(2))
+            {
+                case "BM":
+                    return $this->type = 'bmp';
+                case "GI":
+                    return $this->type = 'gif';
+                case chr(0xFF).chr(0xd8):
+                    return $this->type = 'jpeg';
+                case chr(0x89).'P':
+                    return $this->type = 'png';
+                default:
+                    return false;
+            }
+        }
+        return $this->type;
+    }
+    private function parseSize()
+    {
+        $this->strpos = 0;
+
+        switch ($this->type)
+        {
+            case 'png':
+                return $this->parseSizeForPNG();
+            case 'gif':
+                return $this->parseSizeForGIF();
+            case 'bmp':
+                return $this->parseSizeForBMP();
+            case 'jpeg':
+                return $this->parseSizeForJPEG();
+        }
+
+        return null;
+    }
+    private function parseSizeForPNG()
+    {
+        $chars = $this->getChars(25);
+        return unpack("N*", substr($chars, 16, 8));
+    }
+    private function parseSizeForGIF()
+    {
+        $chars = $this->getChars(11);
+        return unpack("S*", substr($chars, 6, 4));
+    }
+    private function parseSizeForBMP()
+    {
+        $chars = $this->getChars(29);
+        $chars = substr($chars, 14, 14);
+        $type = unpack('C', $chars);
+
+        return (reset($type) == 40) ? unpack('L*', substr($chars, 4)) : unpack('L*', substr($chars, 4, 8));
+    }
+    private function parseSizeForJPEG()
+    {
+        $state = null;
+        $i = 0;
+        while (true)
+        {
+            switch ($state)
+            {
+                default:
+                    $this->getChars(2);
+                    $state = 'started';
+                    break;
+
+                case 'started':
+                    $b = $this->getByte();
+                    if ($b === false) return false;
+
+                    $state = $b == 0xFF ? 'sof' : 'started';
+                    break;
+
+                case 'sof':
+                    $b = $this->getByte();
+                    if (in_array($b, range(0xe0, 0xef)))
+                    {
+                        $state = 'skipframe';
+                    }
+                    elseif (in_array($b, array_merge(range(0xC0,0xC3), range(0xC5,0xC7), range(0xC9,0xCB), range(0xCD,0xCF))))
+                    {
+                        $state = 'readsize';
+                    }
+                    elseif ($b == 0xFF)
+                    {
+                        $state = 'sof';
+                    }
+                    else
+                    {
+                        $state = 'skipframe';
+                    }
+                    break;
+
+                case 'skipframe':
+                    $skip = $this->readInt($this->getChars(2)) - 2;
+                    $state = 'doskip';
+                    break;
+
+                case 'doskip':
+                    $this->getChars($skip);
+                    $state = 'started';
+                    break;
+
+                case 'readsize':
+                    $c = $this->getChars(7);
+
+                    return array($this->readInt(substr($c, 5, 2)), $this->readInt(substr($c, 3, 2)));
+            }
+        }
+    }
+    private function getChars($n)
+    {
+        $response = null;
+
+        // do we need more data?
+        if ($this->strpos + $n -1 >= strlen($this->str))
+        {
+            $end = ($this->strpos + $n);
+            while (strlen($this->str) < $end && $response !== false)
+            {
+                // read more from the file handle
+                $need = $end - ftell($this->handle);
+                if ($response = fread($this->handle, $need))
+                {
+                    $this->str .= $response;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
+
+        $result = substr($this->str, $this->strpos, $n);
+        $this->strpos += $n;
+
+        return $result;
+    }
+    private function getByte()
+    {
+        $c = $this->getChars(1);
+        $b = unpack("C", $c);
+
+        return reset($b);
+    }
+    private function readInt($str)
+    {
+        $size = unpack("C*", $str);
+
+        return ($size[1] << 8) + $size[2];
+    }
+    public function __destruct()
+    {
+        $this->close();
+    }
+}

+ 15 - 1
helper/ugc/content.php

@@ -9,6 +9,7 @@
 namespace ugc;
 
 use Exception;
+use tools;
 
 class content_config
 {
@@ -60,11 +61,24 @@ class images_item extends UGContent
     {
         parent::__construct($content);
         $this->mTitle = empty($content['title']) ? "" : $content['title'];
-        $this->mImages = $content['images'];
+        $this->mImages = $this->add_size($content['images']);
         if(empty($content['images'])) {
             throw new Exception("上传的图片不能为空");
         }
     }
+    private function add_size($images)
+    {
+        $result = [];
+        foreach ($images as $uri) {
+            $img = new tools\fast_image($uri);
+            list($width, $height) = $img->getSize();
+            if($width > 0 && $height > 0) {
+                $uri .= "?{$width},{$height}";
+            }
+            $result[] = $uri;
+        }
+        return $result;
+    }
     public function add_image($image) {
         $this->mImages[] = $image;
     }

+ 1 - 0
helper/ugc_helper.php

@@ -19,6 +19,7 @@ require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
 require_once(BASE_ROOT_PATH . '/helper/bonus_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/predeposit_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/relation_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/tools/fast_image.php');
 
 use ugc\special_vote;
 use ugc\special;

+ 0 - 1
mobile/control/special.php

@@ -727,7 +727,6 @@ class tpl_ugc
                         </div>
                         <div class=\"thumbnail_pro\">{$title}</div>
                     </div>";
-
         }
         echo $str;
     }

+ 55 - 0
test/TestGoods.php

@@ -0,0 +1,55 @@
+<?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;
+    }
+
+}

File diff suppressed because it is too large
+ 98 - 0
test/TestUGC.php