Browse Source

fixed bug when add goods' storage_expdate is null

lionared 7 years ago
parent
commit
060eab8b6e

+ 1 - 0
.gitignore

@@ -9,3 +9,4 @@ data/log/20170824.log
 /data/session/
 /installx/
 /data/upload/
+mac_start.sh

+ 4 - 0
data/model/goods_class.model.php

@@ -155,6 +155,10 @@ class goods_classModel extends Model
      */
     public function getGoodsClassInfoById($id) {
         $data = $this->getCache();
+        if(!isset($data['data'][$id])) {
+            $this->dropCache();
+            $data = $this->getCache();
+        }
         return $data['data'][$id];
     }
 

+ 1 - 1
shop/control/store_goods_add.php

@@ -327,7 +327,7 @@ class store_goods_addControl extends BaseSellerControl
                         $goods['first_pay']         = floatval($value['first_pay']);     //首付
                         $goods['month_pay']         = floatval($value['month_pay']);     //月供
                         $goods['final_pay']         = floatval($value['final_pay']);     //尾款
-                        $goods['storage_exp_date']  = strtotime($value['expdate']);      //库存有效期
+                        $goods['storage_exp_date']  = $value['expdate'] ? strtotime($value['expdate']) : null;      //库存有效期
                         $final_pay_solution = [
                             'support_stage' => $value['support_stage'],
                             'surplus_periods' => $value['surplus_periods'],

+ 1 - 1
shop/control/store_goods_online.php

@@ -483,7 +483,7 @@ class store_goods_onlineControl extends BaseSellerControl {
                     $update['first_pay']         = floatval($value['first_pay']);   //首付
                     $update['month_pay']         = floatval($value['month_pay']);   //月供
                     $update['final_pay']         = floatval($value['final_pay']);   //尾款
-                    $update['storage_exp_date']  = strtotime($value['expdate']);    //库存有效期
+                    $update['storage_exp_date']  = $value['expdate'] ? strtotime($value['expdate']) : null;    //库存有效期
                     $final_pay_solution = [
                         'support_stage' => $value['support_stage'],
                         'surplus_periods' => $value['surplus_periods'],

+ 55 - 0
test/TestCar.php

@@ -240,4 +240,59 @@ class TestCar extends PHPUnit_Framework_TestCase
         $result_name = $validator->from_name($areas[0],$areas[1],$areas[2]);
     }
 
+    public function testCompareData()
+    {
+        $file = "/Users/a2/work/model.csv";
+        //$file = "/Users/a2/work/brand.csv";
+        $content = file_get_contents($file);
+        $encoding = self::get_encoding($content);
+        unset($content);
+
+        $mod_brand = Model('brand');
+        $mod_car = Model('car');
+        $fs = @fopen($file, 'r');
+        $i = 0;
+        $new_names = [];
+        while( $line = @fgets($fs) )
+        {
+            $line = iconv($encoding, 'UTF-8', trim($line));
+            if($i > 0 )
+            {
+                $arr = explode(";", $line);
+                $car_name = $arr[1];
+                $callback = function($mod,$name) {
+                    $result = $mod->table('car_base')->where(['car_name'=>$name])->find();
+                    if(!empty($result)) {
+                        return true;
+                    } else {
+                        return false;
+                    }
+                };
+                $found = $callback($mod_car, $car_name);
+                if(!$found) {
+                    $new_names[] = $car_name;
+                }
+                /*$brand_name = $arr[1];
+                $callback = function ($mod, $name) {
+                    $result = $mod->table('brand')->where(['brand_name'=>$name])->find();
+                    if(!empty($result)) {
+                        return true;
+                    } else {
+                        return false;
+                    }
+                };
+                $found = $callback($mod_brand,$brand_name);
+                if(!$found) {
+                    $new_names[] = $brand_name;
+                }*/
+            }
+            $i++;
+        }
+        var_dump($new_names);
+    }
+
+    private static function get_encoding($str)
+    {
+        return mb_detect_encoding($str, ['GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII']);
+    }
 }