rabin 1 ngày trước cách đây
mục cha
commit
5a9419036d

+ 2 - 2
src/place/order/app/Lib/Pay.php

@@ -273,9 +273,9 @@ class Pay
         if ($this->order['pay_money_cash'] > 0) {
             $result['pay'] = Dever::load(\Place\Lib\Account::class)->pay($this->order);
             if (isset($result['pay']['link']) && $result['pay']['link']) {
-                return $result;
+                //return $result;
             }
-            //$result['pay'] = true;
+            $result['pay'] = true;
         } else {
             $result['pay'] = true;
         }

+ 7 - 0
src/place/order/app/Lib/Source/Order.php

@@ -109,6 +109,13 @@ class Order
         } elseif ($info['method'] == 3 && $info['status'] <= 4) {
             $info['status_name'] = '自提';
             $info['method_code'] = substr($info['cdate'], -4);
+            # 获取自提地址
+            if (isset($info['sales_type']) && $info['sales_type']) {
+                $address = Dever::load('Psales\\Lib\\Info')->get($info['sales_type'], $info['sales_id']);
+                $address['phone'] = $address['mobile'];
+                $address['area_string'] = '自提地址:' . Dever::load(\Area\Lib\Data::class)->string($address['area'], '-');
+                $info['address'] = $address;
+            }
         }
         $info['method_name'] = Dever::db('porder/source')->value('method', $info['method']);
         $info['cash_text'] = $this->score->getText($info['cash'], $info['score']);

+ 157 - 1
src/place/source/manage/Lib/Excel.php

@@ -57,7 +57,7 @@ class Excel
             $result['head'][0] = ['source_name', 'channel_name', 'cate_parent_name', 'cate_child_name', 'source_type', 'sku_code', 'sku_name', 'sku_price', 'sku_pic'];
         } else {
             # 这是导入时的模板
-            $result['head'][0] = ['资源名称', '资源频道', '资源主分类', '资源子分类', '资源类型', '规格编码', '规格名称', '规格售价', '规格图片'];
+            $result['head'][0] = ['资源名称', '资源频道', '资源主分类', '资源子分类', '资源类型', '规格编码', '规格名称', '规格售价', '规格图片(插入-图片-本地图片-裁剪-锁定纵横比-宽度设置2厘米,不要内嵌到单元格中)'];
         }
         $result['body'] = [];
         if ($out) {
@@ -224,4 +224,160 @@ class Excel
 
         return $dateStr . $line;
     }
+
+
+    # 导出一个模板出来
+    public function getJiuTemplate($out = false, $import = false)
+    {
+        $result = [];
+        if ($import) {
+            # 导入时的字段,一定要和下面的else里的对应
+            $result['head'][0] = ['source_name', 'cate_parent_name', 'cate_child_name', 'color', 'size', 'sku_price', 'sku_pic'];
+        } else {
+            # 这是导入时的模板
+            $result['head'][0] = ['资源名称', '资源主分类', '资源子分类', '颜色', '尺寸', '规格售价', '规格图片'];
+        }
+        $result['body'] = [];
+        return $result;
+    }
+
+    # 导入
+    public function importJiu_commit(){}
+    public function importJiu($file)
+    {
+        # 当前登录的管理员id
+        $muid = Dever::getData('muser')['id'];
+        $mname = Dever::getData('muser')['name'];
+        $mdesc = $mname . '在' . date('Y-m-d H:i:s') . '导入';
+
+        $type = array_flip(Dever::db('psource/info')->config['struct']['type']['value']);
+
+        $result = $this->getJiuTemplate(false, true);
+
+        $file = Dever::load(\Upload\Lib\View::class)->local($file);
+        $import = Dever::load(\Excel\Lib\Import::class);
+        $i = 0;
+        foreach ($import->act($file, 0, 1, $result['head'][0]) as $row) {
+            if (!$row['source_name']) {
+                continue;
+            }
+            $info = Dever::db('psource/info')->find(['name' => $row['source_name']]);
+            if (isset($row['sku_pic'][0])) {
+                $row['sku_pic'] = $row['sku_pic'][0];
+            }
+            $source = [];
+            $source['cate'] = [];
+
+            # 频道
+            $channel_id = 1;
+            $source['cate'][] = $channel_id;
+
+            # 父级分类
+            $cate_parent_id = 0;
+            if ($row['cate_parent_name']) {
+                $cate = Dever::db('psource/cate')->find(['name' => $row['cate_parent_name']]);
+                if ($cate) {
+                    $cate_parent_id = $cate['id'];
+                } else {
+                    $cate_parent_id = Dever::db('psource/cate')->insert(['name' => $row['cate_parent_name'], 'channel_id' => $channel_id]);
+                }
+                $source['cate'][] = $cate_parent_id;
+                $source['cate_id'] = $cate_parent_id;
+            }
+
+            # 子分类
+            $cate_child_id = 0;
+            if ($row['cate_child_name']) {
+                $cate = Dever::db('psource/cate')->find(['name' => $row['cate_child_name']]);
+                if ($cate) {
+                    $cate_child_id = $cate['id'];
+                } else {
+                    $cate_child_id = Dever::db('psource/cate')->insert(['name' => $row['cate_child_name'], 'channel_id' => $channel_id, 'parent_id' => $cate_parent_id]);
+                }
+                $source['cate'][] = $cate_child_id;
+                $source['cate_id'] = $cate_child_id;
+            }
+
+            $source['name'] = $row['source_name'];
+            $source['type'] = 1;
+            $source['channel_id'] = $channel_id;
+            $source['cate_parent_id'] = $cate_parent_id;
+            $source['cate_child_id'] = $cate_child_id;
+            $source['cate'] = implode(',', $source['cate']);
+            
+            if ($info) {
+                if ($row['sku_pic']) {
+                    $pic = explode(',', $info['pic']);
+                    $pic[] = $row['sku_pic'];
+                    $source['pic'] = implode(',', $pic);
+                }
+                if ($info['price'] > $row['sku_price']) {
+                    $source['price'] = $row['sku_price'];
+                }
+                Dever::db('psource/info')->update($info['id'], $source);
+                $id = $info['id'];
+            } else {
+                $source['pic'] = $row['sku_pic'];
+                $source['price'] = $row['sku_price'];
+                $id = Dever::db('psource/info')->insert($source);
+            }
+            
+            if ($id) {
+                # 建立规格
+                $row['sku_name'] = '颜色:' . $row['color'] . ' & 尺寸:' . $row['size'];
+                if (isset($row['sku_name']) && $row['sku_name']) {
+                    $temp = explode('&', $row['sku_name']);
+                    $spec_value_id = [];
+                    foreach ($temp as $v) {
+                        # 颜色:白色 & 尺寸:35
+                        $v = trim($v);
+                        list($spec_name, $spec_value) = explode(':', $v);
+
+                        $spec_data = ['info_id' => $id, 'name' => $spec_name];
+                        $spec = Dever::db('psource/spec')->find($spec_data);
+                        if ($spec) {
+                            $spec_id = $spec['id'];
+                        } else {
+                            $spec_data['sort'] = $i;
+                            $spec_id = Dever::db('psource/spec')->insert($spec_data);
+                        }
+                        if ($spec_id) {
+                            $spec_data = ['info_id' => $id, 'spec_id' => $spec_id, 'value' => $spec_value];
+                            $spec_value = Dever::db('psource/spec_value')->find($spec_data);
+                            if ($spec_value) {
+                                $spec_value_id[] = $spec_value['id'];
+                            } else {
+                                $spec_data['sort'] = $i;
+                                $spec_value_id[] = Dever::db('psource/spec_value')->insert($spec_data);
+                            }
+                        }
+                    }
+                    $update = [];
+                    if ($spec_value_id) {
+                        $spec_value_id = implode(',', $spec_value_id);
+                        $update['spec_type'] = 3;
+                    } else {
+                        $spec_value_id = -1;
+                        $update['spec_type'] = 2;
+                    }
+                    $row['sku_code'] = $this->createCode($i);
+                    $sku_data = ['info_id' => $id, 'key' => $spec_value_id];
+                    $sku = Dever::db('psource/sku')->find($sku_data);
+                    $sku_data += ['pic' => $row['sku_pic'], 'price' => $row['sku_price'], 'code' => $row['sku_code']];
+                    if ($sku) {
+                        Dever::db('psource/sku')->update($sku['id'], $sku_data);
+                    } else {
+                        Dever::db('psource/sku')->insert($sku_data);
+                    }
+
+                    $sku = Dever::load(\Api\Lib\Sku::class)->getPrice(['info_id' => $id], $update['spec_type'], 'psource');
+                    $update['price'] = $sku['price'];
+                    $update['sku_id'] = $sku['id'];
+                    Dever::db('psource/info')->update($id, $update);
+
+                    $i++;
+                }
+            }
+        }
+    }
 }

+ 8 - 4
src/place/source/manage/Lib/Info.php

@@ -9,7 +9,7 @@ class Info
             if (!$data['import']) {
                 Dever::error('请选择导入文件');
             }
-            Dever::load(\Psource\Lib\Manage\Excel::class)->import($data['import']);
+            Dever::load(\Psource\Manage\Lib\Excel::class)->importJiu($data['import']);
             return 'end';
         }
         if ($data['cate']) {
@@ -43,9 +43,13 @@ class Info
     public function getPrice($id)
     {
         $info = Dever::db('psource/info')->find($id);
-        $cate = Dever::load(\Psource\Lib\Cate::class)->getInfo($info['cate_id']);
-        $info['price'] = Dever::load(\Pscore\Lib\Info::class)->getText($info['price'], $cate['score']);
-        return $info['price'];
+        if ($info['cate_id']) {
+            $cate = Dever::load(\Psource\Lib\Cate::class)->getInfo($info['cate_id']);
+            $info['price'] = Dever::load(\Pscore\Lib\Info::class)->getText($info['price'], $cate['score']);
+            return $info['price'];
+        } else {
+            return '-';
+        }
     }
 
     # 根据资源编号获取资源id