rabin 1 dzień temu
rodzic
commit
d033e959df
100 zmienionych plików z 2967 dodań i 431 usunięć
  1. 4 0
      package/poster/index.php
  2. 12 1
      src/place/act/lib/Core.php
  3. 21 0
      src/place/act/table/review.php
  4. 4 1
      src/place/benefit/lib/Item/Promotion.php
  5. 41 0
      src/place/benefit/lib/Item/Sales.php
  6. 36 29
      src/place/benefit/lib/Scope.php
  7. 2 1
      src/place/benefit/lib/User.php
  8. 24 4
      src/place/benefit/manage/Lib/Api.php
  9. 43 0
      src/place/benefit/manage/Lib/Sales.php
  10. 14 0
      src/place/benefit/manage/core.php
  11. 2 0
      src/place/benefit/manage/exchange_scope.php
  12. 4 0
      src/place/benefit/manage/promotion.php
  13. 72 0
      src/place/benefit/manage/sales.php
  14. 44 0
      src/place/benefit/manage/sales_rebate.php
  15. 2 0
      src/place/benefit/manage/sales_rebate_platform.php
  16. 2 0
      src/place/benefit/manage/scope.php
  17. 1 4
      src/place/benefit/manage/user.php
  18. 1 4
      src/place/benefit/manage/user_log.php
  19. 4 0
      src/place/benefit/table/promotion.php
  20. 44 0
      src/place/benefit/table/sales.php
  21. 50 0
      src/place/benefit/table/sales_rebate.php
  22. 4 0
      src/place/benefit/table/sales_rebate_platform.php
  23. 58 21
      src/place/boot.php
  24. 5 0
      src/place/channel/market/index.php
  25. 5 0
      src/place/channel/sales/index.php
  26. 58 0
      src/place/channel/sales/lib/Info.php
  27. 15 0
      src/place/channel/sales/lib/Offline.php
  28. 19 0
      src/place/channel/sales/lib/Profit.php
  29. 9 0
      src/place/channel/sales/manage/Lib/Cate.php
  30. 72 0
      src/place/channel/sales/manage/Lib/Info.php
  31. 16 0
      src/place/channel/sales/manage/Lib/Offline.php
  32. 30 0
      src/place/channel/sales/manage/Lib/View.php
  33. 39 0
      src/place/channel/sales/manage/cate.php
  34. 39 0
      src/place/channel/sales/manage/core.php
  35. 185 0
      src/place/channel/sales/manage/offline.php
  36. 35 41
      src/place/channel/sales/table/cate.php
  37. 72 0
      src/place/channel/sales/table/media.php
  38. 128 0
      src/place/channel/sales/table/offline.php
  39. 96 0
      src/place/channel/sales/table/online.php
  40. 51 0
      src/place/channel/sales/table/profit.php
  41. 49 0
      src/place/channel/sales/table/seller.php
  42. 5 0
      src/place/channel/supply/index.php
  43. 0 42
      src/place/channel/table/shop_offline.php
  44. 0 38
      src/place/channel/table/supplier.php
  45. 71 0
      src/place/interface/api/Bind.php
  46. 86 59
      src/place/interface/api/Main.php
  47. 36 0
      src/place/interface/api/Order.php
  48. 337 0
      src/place/interface/api/Sales.php
  49. 8 0
      src/place/interface/api/Score.php
  50. 90 5
      src/place/interface/api/Source.php
  51. 47 5
      src/place/interface/api/User.php
  52. 9 2
      src/place/interface/lib/Core.php
  53. 9 3
      src/place/order/lib/Log.php
  54. 20 4
      src/place/order/lib/Pay.php
  55. 1 1
      src/place/order/lib/Role/Pay.php
  56. 1 1
      src/place/order/lib/Source/Cart.php
  57. 33 22
      src/place/order/lib/Source/Delivery.php
  58. 96 10
      src/place/order/lib/Source/Order.php
  59. 28 8
      src/place/order/lib/Source/Pay.php
  60. 70 5
      src/place/order/lib/Source/Refund.php
  61. 1 1
      src/place/order/manage/Lib/Source/Address.php
  62. 18 8
      src/place/order/manage/Lib/Source/Delivery.php
  63. 32 1
      src/place/order/manage/Lib/Source/Info.php
  64. 4 5
      src/place/order/manage/Lib/Source/Pdf.php
  65. 56 1
      src/place/order/manage/Lib/Source/Refund.php
  66. 78 20
      src/place/order/manage/Lib/Source/View.php
  67. 8 0
      src/place/order/manage/core.php
  68. 1 4
      src/place/order/manage/role.php
  69. 18 7
      src/place/order/manage/source.php
  70. 2 2
      src/place/order/manage/source_delivery_express.php
  71. 20 0
      src/place/order/manage/source_refund_audit.php
  72. 40 0
      src/place/order/manage/source_refund_audit_delivery.php
  73. 2 2
      src/place/order/table/rebate.php
  74. 17 1
      src/place/order/table/role.php
  75. 5 0
      src/place/order/table/role_detail.php
  76. 32 2
      src/place/order/table/source.php
  77. 5 0
      src/place/order/table/source_detail.php
  78. 10 3
      src/place/order/table/source_log.php
  79. 27 4
      src/place/order/table/source_refund.php
  80. 4 0
      src/place/page/lib/Ad.php
  81. 1 1
      src/place/page/manage/ad.php
  82. 1 1
      src/place/page/manage/nav.php
  83. 4 0
      src/place/page/table/ad.php
  84. 2 1
      src/place/page/table/nav.php
  85. 2 2
      src/place/role/lib/Info.php
  86. 16 1
      src/place/role/lib/User.php
  87. 14 0
      src/place/role/manage/Lib/Data.php
  88. 3 0
      src/place/role/manage/level.php
  89. 1 4
      src/place/role/manage/user_role.php
  90. 2 1
      src/place/role/table/level.php
  91. 12 1
      src/place/role/table/user.php
  92. 47 6
      src/place/score/lib/Log.php
  93. 2 5
      src/place/score/lib/User.php
  94. 1 4
      src/place/score/manage/user_score.php
  95. 1 4
      src/place/score/manage/user_withdraw.php
  96. 1 1
      src/place/score/table/user_log.php
  97. 8 27
      src/place/set/api/Tool.php
  98. 17 0
      src/place/set/lib/Address.php
  99. 82 0
      src/place/set/lib/Info.php
  100. 11 0
      src/place/set/manage/Lib/Address.php

+ 4 - 0
package/poster/index.php

@@ -0,0 +1,4 @@
+<?php
+define('DEVER_PACKAGE',  'poster');
+define('DEVER_APP_SETUP', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../boot.php');

+ 12 - 1
src/place/act/lib/Core.php

@@ -91,7 +91,18 @@ class Core
                 if (Place::$uid == $v['uid']) {
                     $v['oper'] = 1;
                 }
-                $v['user'] = Dever::db('info', 'place_user')->find($v['uid'], ['col' => 'name,avatar']);
+                if (isset($v['pic'])) {
+                    if ($v['pic']) {
+                        $v['pic'] = explode(',', $v['pic']);
+                    } else {
+                        $v['pic'] = [];
+                    }
+                }
+                if (isset($v['open']) && $v['open'] == 2) {
+                    $v['user'] = ['name' => '匿名', 'avatar' => 'https://api.dicebear.com/7.x/thumbs/svg?seed=1'];
+                } else {
+                    $v['user'] = Dever::db('info', 'place_user')->find($v['uid'], ['col' => 'name,avatar']);
+                }
             }
         }
         return $data;

+ 21 - 0
src/place/act/table/review.php

@@ -19,11 +19,32 @@ return [
             'name'      => '用户',
         ],
 
+        'pic'       => [
+            'name'      => '图片',
+            'type'      => 'varchar(2000)',
+        ],
+
         'content'       => [
             'name'      => '内容',
             'type'      => 'varchar(2000)',
         ],
 
+        'rate'       => [
+            'type'      => 'tinyint(1)',
+            'name'      => '评分',
+            'default'   => '5',
+        ],
+
+        'open'       => [
+            'type'      => 'tinyint(1)',
+            'name'      => '公开头像昵称',
+            'default'   => '1',
+            'value'     => [
+                1 => '公开',
+                2 => '不公开',
+            ],
+        ],
+
         'sort' => [
             'name'      => '排序',
             'type'      => 'int(11)',

+ 4 - 1
src/place/benefit/lib/Item/Promotion.php

@@ -43,8 +43,11 @@ class Promotion
     # 获取展示标签的促销信息
     public function getInfoByTag($scope)
     {
-        $data = Dever::load('item', 'place_benefit')->getList('promotion', $scope, ['tag' => 1], ['col' => 'id,name']);
+        $data = Dever::load('item', 'place_benefit')->getList('promotion', $scope, ['tag' => 1], ['col' => 'id,name,tag_name']);
         if ($data) {
+            if ($data[0]['tag_name']) {
+                $data[0]['name'] = $data[0]['tag_name'];
+            }
             return $data[0];
         }
         return [];

+ 41 - 0
src/place/benefit/lib/Item/Sales.php

@@ -0,0 +1,41 @@
+<?php namespace Place_benefit\Lib\Item;
+use Dever;
+class Sales
+{
+    # 获取返利
+    public function rebate($uid, $scope, $promotion_id, $rebate, $price)
+    {
+        if ($price <= 0) {
+            return 0;
+        }
+        $result = 0;
+        foreach ($rebate as $v) {
+            # 过滤掉未用这个促销的
+            if ($v['promotion_id'] && $v['promotion_id'] != $promotion_id) {
+                continue;
+            }
+            # 过滤掉不符合范围的
+            $state = $this->check($scope, $v['buy_scope'], $v['buy_ids']);
+            if (!$state) {
+                continue;
+            }
+
+            # 剩余的符合要求,开始计算
+            $value = Dever::math('value', $price, $v['value']);
+            if ($value > 0) {
+                $result += $value;
+            }
+        }
+        return $result;
+    }
+
+    # 验证权益是否在范围内有效
+    public function check($scope, $buy_scope, $buy_ids)
+    {
+        if ($scope) {
+            return Dever::load('scope', 'place_benefit')->valid($scope, $buy_scope, $buy_ids);
+        } else {
+            return true;
+        }
+    }
+}

+ 36 - 29
src/place/benefit/lib/Scope.php

@@ -67,39 +67,46 @@ class Scope
         if ($data) {
             $info['tip'] = '<table style="width:100%; border-collapse:collapse; text-align:left; table-layout:auto;">';
             foreach ($data as $k => $v) {
-                $v['name'] = '';
-                $v['value'] = explode(',', $v['value']);
-                $value = array_shift($v['value']);
-                if ($value == 1) {
-                    if ($v['ids']) {
-                        $source = Dever::db('info', 'place_source')->columns(['id' => ['in', $v['ids']]], 'name');
-                        $tip = implode('、', $source);
-                    } else {
-                        $tip = Dever::load('channel', 'place_source')->getName($v['value']);
-                        if (!$tip) {
-                            $tip = '全部资源';
-                        }
-                    }
-                    $unit = '个';
-                } elseif ($value == 2) {
-                    if ($v['ids']) {
-                        $source = Dever::db('level', 'place_role')->columns(['id' => ['in', $v['ids']]], 'name');
-                        $tip = implode('、', $source);
-                    } else {
-                        $tip = Dever::load('info', 'place_role')->getName($v['value']);
-                        if (!$tip) {
-                            $tip = '全部角色';
-                        }
-                    }
-                    $unit = '个';
-                }
-                if (isset($v['num']) && $v['num'] > 0) {
-                    $tip .= ' [可兑换'.$v['num'].''.$unit.']';
-                }
+                $tip = $this->getInfoStr($v['value'], $v['ids'], $v['num'] ?? 0);
                 $info['tip'] .= '<tr><td style="border:0px solid #ddd; padding:8px;">'.$tip.'</td></tr>';
             }
             $info['tip'] .= '</table>';
         }
         return $info;
     }
+
+    # 获取范围描述信息
+    public function getInfoStr($scope, $ids, $num = 0)
+    {
+        $scope = explode(',', $scope);
+        $type = array_shift($scope);
+        $result = '';
+        if ($type == 1) {
+            if ($ids) {
+                $source = Dever::db('info', 'place_source')->columns(['id' => ['in', $ids]], 'name');
+                $result = implode('、', $source);
+            } else {
+                $result = Dever::load('channel', 'place_source')->getName($scope);
+                if (!$result) {
+                    $result = '全部资源';
+                }
+            }
+            $unit = '个';
+        } elseif ($type == 2) {
+            if ($ids) {
+                $source = Dever::db('level', 'place_role')->columns(['id' => ['in', $ids]], 'name');
+                $result = implode('、', $source);
+            } else {
+                $result = Dever::load('info', 'place_role')->getName($scope);
+                if (!$result) {
+                    $result = '全部角色';
+                }
+            }
+            $unit = '个';
+        }
+        if ($num > 0) {
+            $result .= ' [可兑换'.$num.''.$unit.']';
+        }
+        return $result;
+    }
 }

+ 2 - 1
src/place/benefit/lib/User.php

@@ -15,7 +15,8 @@ class User
         $level = Dever::load('role', 'place_user')->getLevel($uid);
         if (!$level) {
             # 如果当前用户没有任何角色等级,需要给一个默认的
-            Dever::load('info', 'place_role')->up($uid);
+            $user = Dever::db('info', 'place_user')->find($uid);
+            Dever::load('info', 'place_role')->up($uid, $user['sales_type'], $user['sales_id']);
             $level = Dever::load('role', 'place_user')->getLevel($uid);
         }
         if ($level) {

+ 24 - 4
src/place/benefit/manage/Lib/Api.php

@@ -12,11 +12,11 @@ class Api
     }
 
     # 获取权益所需要的范围数据:具体项目选择
-    public function getScope($value)
+    public function getScope($value, $key = 'ids')
     {
         if (is_array($value)) {
             $result = [];
-            $result['ids']['value'] = [];
+            $result[$key]['value'] = [];
             if ($value[0] == 1) {
                 //$where = ['status' => 1];
                 $where = [];
@@ -27,9 +27,9 @@ class Api
                 } elseif (isset($value[1]) && $value[1]) {
                     $where['channel_id'] = $value[1];
                 }
-                $result['ids']['option'] = Dever::db('info', 'place_source')->select($where);
+                $result[$key]['option'] = Dever::db('info', 'place_source')->select($where);
             } elseif ($value[0] == 2) {
-                $result['ids']['option'] = Dever::db('level', 'place_role')->select(['info_id' => $value[1]]);
+                $result[$key]['option'] = Dever::db('level', 'place_role')->select(['info_id' => $value[1]]);
             }
             
             //$result['ids']['url'] = Dever::url('place/manage.getProfitData', ['s' => $value]);
@@ -37,6 +37,26 @@ class Api
         }
     }
 
+    # 获取销售渠道下的分类
+    public function getSalesCate($value)
+    {
+        if ($value) {
+            $result = [];
+            $result['sales_cate_id']['option'] = Dever::db('cate', 'place_channel_sales')->select(['type' => $value]);
+            if ($result['sales_cate_id']['option']) {
+                $result['sales_cate_id']['value'] = $result['sales_cate_id']['option'][0]['id'];
+            }
+            return $result;
+        }
+    }
+
+    # 获取权益所需要的范围数据:具体项目选择
+    public function getSalesScope($value)
+    {
+        return $this->getScope($value, 'buy_ids');
+    }
+
+
     # 获取权益所需要的信息:项目下的数据
     public function getProfitData()
     {

+ 43 - 0
src/place/benefit/manage/Lib/Sales.php

@@ -0,0 +1,43 @@
+<?php namespace Place_benefit\Manage\Lib;
+use Dever;
+class Sales
+{
+    # 获取升级奖励信息
+    public function getRebate($id, $type = '')
+    {
+        $info = Dever::db('sales_rebate' . $type, 'place_benefit')->select(['sales_id' => $id]);
+        if (!$info) {
+            return '无';
+        }
+        $body = '';
+        foreach ($info as $v) {
+            $role_name = Dever::load('info', 'place_role')->getName($v['role']);
+            $promotion = '无';
+            if ($v['promotion_id']) {
+                $promotion = Dever::db('promotion', 'place_benefit')->find($v['promotion_id']);
+                $promotion = $promotion['name'];
+            }
+            $scope = Dever::load('scope', 'place_benefit')->getInfoStr($v['buy_scope'], $v['buy_ids']);
+            $body .= '<tr>';
+            $body .= '<td>'.$role_name.'</td>';
+            $body .= '<td>'.$scope.'</td>';
+            $body .= '<td>'.$promotion.'</td>';
+            $body .= '<td>'.$v['value'].'</td>';
+            $body .= '</tr>';
+        }
+        return '<table border="1" cellspacing="0" cellpadding="8" style="border-collapse: collapse; text-align: left;">
+  <thead style="background-color: #f2f2f2;">
+    <tr>
+      <th>等级</th>
+      <th>范围</th>
+      <th>促销</th>
+      <th>数值</th>
+    </tr>
+  </thead>
+  <tbody>
+    '.$body.'
+  </tbody>
+</table>
+';
+    }
+}

+ 14 - 0
src/place/benefit/manage/core.php

@@ -146,5 +146,19 @@ return [
             'sort'      => '100',
             'show'      => 3
         ],
+
+        'sales' => [
+            'parent'    => 'place_benefit_role',
+            'name'      => '销售权益',
+            'icon'      => 'safe-2-line',
+            'sort'      => '3',
+        ],
+
+        'sales_rebate' => [
+            'parent'    => 'place_benefit_role',
+            'name'      => '销售返利权益',
+            'sort'      => '100',
+            'show'      => 3
+        ],
     ],
 ];

+ 2 - 0
src/place/benefit/manage/exchange_scope.php

@@ -9,6 +9,7 @@ return [
                 'option'    => 'Dever::call("place_benefit/manage/scope.getData")',
                 'remote' => 'place_benefit/manage/api.getScope',
                 'width' => '100%',
+                'clearable' => true,
             ],
             'ids' => [
                 'name'      => '关联项目',
@@ -21,6 +22,7 @@ return [
                 'width' => '100%',
                 'tags' => true,
                 'max_tags' => 3,
+                'clearable' => true,
             ],
             'num' => [
                 'rules' => true,

+ 4 - 0
src/place/benefit/manage/promotion.php

@@ -59,6 +59,10 @@ return [
                 'type' => 'radio',
                 'desc' => '展示在选择应用范围内的价格标签中,仅展示排序第一个',
             ],
+            'tag_name' => [
+                'tip' => '如不设置,默认展示促销名称',
+                'maxlength' => 15,
+            ],
             'place_benefit/scope' => [
                 'name' => '应用范围',
                 'tip' => '不添加应用范围,全场可用',

+ 72 - 0
src/place/benefit/manage/sales.php

@@ -0,0 +1,72 @@
+<?php
+return [
+    'list' => [
+        'field'      => [
+            'sales_type' => [
+                'width' => '120px',
+            ],
+            'sales_cate_id' => [
+                'width' => '120px',
+            ],
+            'score_id' => [
+                'width' => '120px',
+            ],
+            'rebate' => [
+                'name' => '自营返利',
+                'show' => 'Dever::call("place_benefit/manage/sales.getRebate", [{id}])',
+            ],
+            'rebate_platform' => [
+                'name' => '平台返利',
+                'show' => 'Dever::call("place_benefit/manage/sales.getRebate", [{id}, "_platform"])',
+            ],
+        ],
+        'button' => [
+            '新增' => ['add'],
+        ],
+        'data_button' => [
+            '编辑' => ['edit'],
+        ],
+        'search'    => [
+            'sales_type',
+        ],
+    ],
+    'update' => [
+        'tab' => [
+            '基本信息' => 'sales_type,sales_cate_id,desc',
+            '返利设置' => 'score_id,place_benefit/sales_rebate,place_benefit/sales_rebate_platform',
+        ],
+        'field'    => [
+            'sales_type' => [
+                'type' => 'radio',
+                'rules' => true,
+                'remote' => 'place_benefit/manage/api.getSalesCate',
+            ],
+            'sales_cate_id' => [
+                'rules' => true,
+                'type' => 'radio',
+            ],
+            'score_id' => [
+                'rules' => true,
+                'type' => 'radio',
+            ],
+            'place_benefit/sales_rebate' => [
+                'name' => '自营返利',
+                'where'  => ['sales_id' => 'id'],
+                'tip' => '销售渠道自行销售时的返利设置',
+            ],
+            'place_benefit/sales_rebate_platform' => [
+                'name' => '平台返利',
+                'where'  => ['sales_id' => 'id'],
+                'tip' => '销售渠道代平台销售时的返利设置',
+            ],
+            'desc' => [
+                'type' => 'editor',
+                'editorMenu' => [
+                    'uploadImage' => 1,
+                    'uploadVideo' => 3,
+                ],
+                'width' => '100%',
+            ],
+        ],
+    ],
+];

+ 44 - 0
src/place/benefit/manage/sales_rebate.php

@@ -0,0 +1,44 @@
+<?php
+return [
+    'update' => [
+        'field'    => [
+            'role' => [
+                'type' => 'cascader',
+                'option'    => 'Dever::call("place_role/manage/data.getOption")',
+                'width' => '100%',
+                'clearable' => true,
+            ],
+            'buy_scope' => [
+                'type' => 'cascader',
+                'check' => true,
+                'option'    => 'Dever::call("place_benefit/manage/scope.getData")',
+                'remote' => 'place_benefit/manage/api.getSalesScope',
+                'width' => '100%',
+                'clearable' => true,
+            ],
+            'buy_ids' => [
+                'type' => 'select2',
+                # select2需要有默认值
+                'option' => [],
+                'multiple' => true,
+                'tip' => '不选择购买项目,则当前选择范围内有效',
+                'placeholder' => '不选择购买项目,则当前选择范围内有效',
+                'width' => '100%',
+                'tags' => true,
+                'max_tags' => 3,
+                'clearable' => true,
+            ],
+            'promotion_id' => [
+                'type' => 'select',
+                'tip' => '选择购买促销后,用户购买时使用了当前促销价才会返利',
+                'placeholder' => '选择购买促销后,用户购买时使用了当前促销价才会返利',
+                'width' => '100%',
+                'clearable' => true,
+                'update' => '{promotion_id} ?: "1"',
+            ],
+            'value' => [
+                'tip' => '输入返利的奖励数值<br />输入10,就是奖励10积分<br />输入10%,就是奖励订单支付货币总额的10%积分<br />订单购买积分将自动转换成支付货币,如订单支付货币总额为100元,10%就是奖励10积分',
+            ],
+        ],
+    ],
+];

+ 2 - 0
src/place/benefit/manage/sales_rebate_platform.php

@@ -0,0 +1,2 @@
+<?php
+return include('sales_rebate.php');

+ 2 - 0
src/place/benefit/manage/scope.php

@@ -9,6 +9,7 @@ return [
                 'option'    => 'Dever::call("place_benefit/manage/scope.getData")',
                 'remote' => 'place_benefit/manage/api.getScope',
                 'width' => '100%',
+                'clearable' => true,
             ],
             'ids' => [
                 'name'      => '关联项目',
@@ -21,6 +22,7 @@ return [
                 'width' => '100%',
                 'tags' => true,
                 'max_tags' => 3,
+                'clearable' => true,
             ],
         ],
     ],

+ 1 - 4
src/place/benefit/manage/user.php

@@ -3,10 +3,7 @@ return [
     'list' => [
         'desc' => '用户权益列表仅展示用户已领取的权益,包括角色周期权益以及权益包里的权益,不包括角色固定权益',
         'field'      => [
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
-            ],
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
             'type' => [
                 
             ],

+ 1 - 4
src/place/benefit/manage/user_log.php

@@ -3,10 +3,7 @@ return [
     'list' => [
         'where' => ['user_id' => Dever::load('common', 'manage')->get('user_id')],
         'field'      => [
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
-            ],
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
             'type' => [
                 
             ],

+ 4 - 0
src/place/benefit/table/promotion.php

@@ -17,6 +17,10 @@ return [
                 2 => '不展示',
             ],
         ],
+        'tag_name' => [
+            'name'      => '标签名称',
+            'type'      => 'varchar(32)',
+        ],
         'type' => [
             'name'      => '类型',
             'type'      => 'tinyint(1)',

+ 44 - 0
src/place/benefit/table/sales.php

@@ -0,0 +1,44 @@
+<?php
+return [
+    'name' => '销售渠道权益',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => [
+        'sales_type' => [
+            'name'      => '销售类型',
+            'type'      => 'tinyint(1)',
+            'value'     => 'Dever::call("place_channel_sales/info.getType")',
+            'default'   => '1',
+        ],
+
+        'sales_cate_id' => [
+            'name'      => '销售分类',
+            'type'      => 'int(11)',
+            'value'    => 'place_channel_sales/cate',
+        ],
+
+        'score_id'        => [
+            'name'      => '奖励积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+            'default'   => '1',
+        ],
+
+        'desc' => [
+            'name'      => '权益介绍',
+            'type'      => 'text',
+        ],
+
+        'status' => [
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => [
+                1 => '生效',
+                2 => '失效',
+            ],
+        ],
+    ],
+    'index' => [
+        'search' => 'sales_type,sales_cate_id,status',
+    ],
+];

+ 50 - 0
src/place/benefit/table/sales_rebate.php

@@ -0,0 +1,50 @@
+<?php
+return [
+    'name' => '销售渠道自营返利权益',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'id asc',
+    'struct' => [
+        'sales_id' => [
+            'name'      => 'ID',
+            'type'      => 'int(11)',
+        ],
+
+        'role' => [
+            'name'      => '购买人等级',
+            'type'      => 'varchar(100)',
+        ],
+
+        'role_id' => [
+            'name'      => '角色ID',
+            'type'      => 'int(11)',
+        ],
+
+        'role_level_id' => [
+            'name'      => '角色等级ID',
+            'type'      => 'int(11)',
+        ],
+
+        'buy_scope' => [
+            'name'      => '购买范围',
+            'type'      => 'varchar(100)',
+        ],
+        'buy_ids' => [
+            'name'      => '购买项目',
+            'type'      => 'text',
+        ],
+
+        'promotion_id' => [
+            'name'      => '购买促销',
+            'type'      => 'int(11)',
+            'value'     => 'place_benefit/promotion',
+        ],
+
+        'value' => [
+            'name'      => '奖励数值',
+            'type'      => 'varchar(20)',
+        ],
+    ],
+    'index' => [
+        'search' => 'sales_id,role_level_id',
+    ],
+];

+ 4 - 0
src/place/benefit/table/sales_rebate_platform.php

@@ -0,0 +1,4 @@
+<?php
+$config = include('sales_rebate.php');
+$config['name'] = '销售渠道平台返利权益';
+return $config;

+ 58 - 21
src/place/boot.php

@@ -9,60 +9,97 @@ class Place
     public static $nav;
     public static $system;
     public static $sector;
-    public static $module;
-    public static $id;
+    #public static $module;
 
     # 生成入口码
-    public static function entry($sector_id, $module_id, $user_id, $place_id)
+    public static function encode($sector_id, $account_id, $place_id, $sales_type = 0, $sales_id = 0, $uid = 0)
     {
-        $code = \Dever\Helper\Secure::encode($sector_id . '-' . $module_id . '-' . $user_id . '-' . $place_id);
-        return $code;
+        return Dever::load('info', 'place')->decode($sector_id, $account_id, $place_id, $sales_type, $sales_id, $uid);
+    }
+
+    # 解析入口码
+    public static function decode()
+    {
+        self::$code = Dever::input('p');
+        return Dever::load('info', 'place')->decode(self::$code);
     }
 
     # 初始化
     public static function init()
     {
-        self::$code = Dever::input('p');
-        $code = Dever\Helper\Secure::decode(self::$code);
-        if (!$code) {
-            Dever::error('身份码错误');
-        }
-        list($sector_id, $module_id, $user_id, $place_id) = explode('-', $code);
+        list($sector_id, $account_id, $place_id, $sales_type, $sales_id, $uid) = self::decode();
         self::$system = Dever::db('system', 'manage')->find(['key' => 'sector']);
         self::$sector = Dever::db(self::$system['info_table'])->find($sector_id);
         if (!self::$sector) {
             Dever::error('领域信息错误');
         }
         # 切换数据库
-        Dever::load('common', 'manage')->setAuth(self::$system, $module_id, self::$sector['id'], $user_id);
+        Dever::load('common', 'manage')->setAuth(self::$system, 'sector_user', self::$sector['id'], $account_id);
 
         # 初始化身份
-        self::info($user_id, $place_id);
+        self::info($account_id, $place_id, $uid);
 
         # 切换数据库
+        /*
         self::$module = Dever::db('system_module', 'manage')->find(['key' => 'sector_place']);
         Dever::load('common', 'manage')->setAuth(self::$system, self::$module['id'], self::$sector['id'], $place_id);
+        */
+        Dever::load('common', 'manage')->setAuth(self::$system, 'sector_place', self::$sector['id'], $place_id);
+
+        # 查找销售来源
+        self::sales($sales_type, $sales_id);
     }
 
     # 身份信息
-    public static function info($user_id, $place_id)
+    public static function info($account_id, $place_id, $uid)
     {
-        $user = Dever::db('user', 'sector')->find($user_id);
-        self::$info = Dever::db('info', 'place')->find($place_id, ['col' => 'name,info,logo,type,money_id,uid,pay_account,score_name,`update`']);
+        $account = Dever::db('user', 'sector')->find($account_id);
+        self::$info = Dever::db('info', 'place')->find($place_id, ['col' => 'id,name,info,logo,type,money_id,uid,pay_account,score_name,`update`,content']);
         if (!self::$info) {
             Dever::error('信息有误');
         }
-        if (self::$info['uid'] != $user['id']) {
+        if (self::$info['uid'] != $account['id']) {
             Dever::error('信息有误');
         }
-        self::$id = $place_id;
-        self::$info['supplier'] = $user['supplier'];
+        self::$info['supplier'] = $account['supplier'];
+        self::$info['parent_uid'] = $uid;
+    }
+
+    # 销售来源
+    public static function sales($sales_type, $sales_id)
+    {
+        self::$info['sales_type'] = $sales_type;
+        self::$info['sales_id'] = $sales_id;
+        $sales = [];
+        if ($sales_type && $sales_id) {
+            $sales = Dever::load('info', 'place_channel_sales')->get($sales_type, $sales_id);
+        } else {
+            # 如果来源不存在,查找有没有实体店,如果有,根据用户当前定位,找最近的实体店,如果找不到,就找总店,如果总店也没有,就找平台店
+            # 这个来源要保存到本地,永久有效,格式:1_1
+            $location = Dever::input('location');
+            if ($location) {
+                # 如果有定位,就要根据定位找最近的实体店
+                //self::$sales = Dever::load('offline', 'place_channel_sales')->get($location);
+            }
+        }
+        if ($sales) {
+            self::$info['name'] = $sales['name'];
+            if ($sales['logo']) {
+                self::$info['logo'] = $sales['logo'];
+            }
+            if ($sales['info']) {
+                self::$info['info'] = $sales['info'];
+            }
+            if ($sales['content']) {
+                self::$info['content'] = $sales['content'];
+            }
+        }
     }
 
     # 用户信息
     public static function user($uid)
     {
-        self::$user = Dever::db('info', 'place_user')->find($uid, ['col' => 'id,parent_uid,name,mobile,password,avatar,sex,sign']);
+        self::$user = Dever::db('info', 'place_user')->find($uid, ['col' => 'id,parent_uid,name,mobile,password,avatar,sex,sign,type,sales_type,sales_id']);
         if (self::$user) {
             self::$uid = $uid;
             self::$user['mobile'] = \Dever\Helper\Str::hide(self::$user['mobile']);
@@ -95,4 +132,4 @@ class Place
         return $data;
     }
 }
-include(DEVER_APP_PATH . '../../../boot.php');
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../../boot.php');

+ 5 - 0
src/place/channel/market/index.php

@@ -0,0 +1,5 @@
+<?php
+define('DEVER_APP_NAME', 'place_channel_market');
+define('DEVER_APP_LANG', '身份营销渠道');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(DEVER_APP_PATH . '../../boot.php');

+ 5 - 0
src/place/channel/sales/index.php

@@ -0,0 +1,5 @@
+<?php
+define('DEVER_APP_NAME', 'place_channel_sales');
+define('DEVER_APP_LANG', '身份销售渠道');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(DEVER_APP_PATH . '../../boot.php');

+ 58 - 0
src/place/channel/sales/lib/Info.php

@@ -0,0 +1,58 @@
+<?php namespace Place_channel_sales\Lib;
+use Dever;
+class Info
+{
+    # 获取销售类型
+    public function getType()
+    {
+        return [
+            ['id' => 1, 'name' => '实体店', 'table' => 'offline'],
+            ['id' => 2, 'name' => '网店', 'table' => 'online'],
+            ['id' => 3, 'name' => '自媒体', 'table' => 'media'],
+            ['id' => 4, 'name' => '经销商', 'table' => 'seller'],
+        ];
+    }
+
+    public function getTypeName($type)
+    {   
+        if ($type == 1) {
+            $table = 'offline';
+        } elseif ($type == 2) {
+            $table = 'online';
+        } elseif ($type == 3) {
+            $table = 'media';
+        } elseif ($type == 4) {
+            $table = 'seller';
+        }
+        return $table;
+    }
+
+    public function get($type, $type_id)
+    {
+        $table = $this->getTypeName($type);
+        return Dever::db($table, 'place_channel_sales')->find($type_id);
+    }
+
+    # 获取信息,带地址解析
+    public function getInfo($type, $type_id)
+    {
+        $info = $this->get($type, $type_id);
+        $info['area_string'] = Dever::load('data', 'area')->string($info['area'], '-');
+        return $info;
+    }
+
+    # 根据uid获取门店列表
+    public function getList($uid)
+    {
+        $result = [];
+        $list = $this->getType();
+        foreach ($list as $k => $v) {
+            $where = ['uid' => $uid];
+            $check = Dever::db($v['table'], 'place_channel_sales')->select($where, ['col' => 'id,name, ' . $v['id'] . ' as sales_type']);
+            if ($check) {
+                $result = array_merge($check, $result);
+            }
+        }
+        return $result;
+    }
+}

+ 15 - 0
src/place/channel/sales/lib/Offline.php

@@ -0,0 +1,15 @@
+<?php namespace Place_channel_sales\Lib;
+use Dever;
+class Offline
+{
+    # 根据经纬度获取实体店
+    public function getInfo()
+    {
+        return [
+            1 => '实体店',
+            2 => '网店',
+            3 => '自媒体',
+            //10 => '经销商',
+        ]
+    }
+}

+ 19 - 0
src/place/channel/sales/lib/Profit.php

@@ -0,0 +1,19 @@
+<?php namespace Place_channel_sales\Lib;
+use Dever;
+class Profit
+{
+    # 更新日志
+    public function up($uid, $user_id, $user_log_id, $score_id, $action_id, $sales_type, $sales_id, $amount, $money)
+    {
+        $data['uid'] = $uid;
+        $data['user_id'] = $user_id;
+        $data['user_log_id'] = $user_log_id;
+        $data['score_id'] = $score_id;
+        $data['action_id'] = $action_id;
+        $data['sales_type'] = $sales_type;
+        $data['sales_id'] = $sales_id;
+        $data['amount'] = $amount;
+        $data['money'] = $money;
+        return Dever::db('profit', 'place_channel_sales')->insert($data);
+    }
+}

+ 9 - 0
src/place/channel/sales/manage/Lib/Cate.php

@@ -0,0 +1,9 @@
+<?php namespace Place_channel_sales\Manage\Lib;
+use Dever;
+class Cate
+{
+    public function getData($type = 1)
+    {
+        return Dever::db('cate', 'place_channel_sales')->select(['type' => $type, 'status' => 1]);
+    }
+}

+ 72 - 0
src/place/channel/sales/manage/Lib/Info.php

@@ -0,0 +1,72 @@
+<?php namespace Place_channel_sales\Manage\Lib;
+use Dever;
+class Info
+{
+    # 获取基本信息
+    public function getInfo($type, $id)
+    {
+        if ($type && $id) {
+            $info = Dever::load('info', 'place_channel_sales')->get($type, $id);
+            return $info['name'];
+        }
+        return '平台';
+    }
+
+    # 获取列表
+    public function getList()
+    {
+        $data = [];
+        $data[] = ['id' => '0,0', 'name' => '平台'];
+        $type = Dever::load('info', 'place_channel_sales')->getType();
+        foreach ($type as $v) {
+            $info = Dever::db($v['table'], 'place_channel_sales')->select(['status' => 1], ['col' => 'concat('.$v['id'].',",",id) as id, concat("'.$v['name'].'","-",name) as name']);
+            $data = array_merge($data, $info);
+        }
+        return $data;
+    }
+
+    public function check($db, $data)
+    {
+        if (isset($data['mobile']) && $data['mobile'] && $data['id']) {
+            $table = Dever::load('info', 'place_channel_sales')->getTypeName($data['sales_type']);
+            $info = Dever::db($table, 'place_channel_sales')->find($data['id']);
+            $data['old_mobile'] = $info['mobile'];
+            if ($info['mobile'] == $data['mobile']) {
+                # 无需修改
+                unset($data['mobile']);
+            }
+        }
+        return $data;
+    }
+
+    public function createUser($db, $data)
+    {
+        $extend = Dever::load('common', 'manage')->extend();
+        Dever::load('manage/place', 'place')->update($extend['data_id']);
+        
+        $table = Dever::load('info', 'place_channel_sales')->getTypeName($data['sales_type']);
+        if (isset($data['mobile']) && $data['mobile']) {
+            # 检测手机号是否被使用
+            if ($data['id']) {
+                $list = ['offline', 'online', 'media', 'seller'];
+                foreach ($list as $k => $v) {
+                    $where = ['mobile' => $data['old_mobile']];
+                    if ($v == $table) {
+                        $where['id'] = ['!=', $data['id']];
+                    }
+                    $check = Dever::db($v, 'place_channel_sales')->find($where);
+                    if ($check) {
+                        # 创建新用户
+                        $data['uid'] = false;
+                        break;
+                    }
+                }
+            }
+            $user = Dever::load('manage/user', 'place_user')->createUser($data['sales_type'], $data['id'], $data['truename'], $data['mobile'], $data['uid']);
+            if ($user) {
+                $update['uid'] = $user;
+                Dever::db($table, 'place_channel_sales')->update($data['id'], $update);
+            }
+        }
+    }
+}

+ 16 - 0
src/place/channel/sales/manage/Lib/Offline.php

@@ -0,0 +1,16 @@
+<?php namespace Place_channel_sales\Manage\Lib;
+use Dever;
+class Offline
+{
+    public function getAddress($area, $address)
+    {
+        $result = Dever::load('data', 'area')->string($area, '');
+        $result .= $address;
+        return $result;
+    }
+
+    public function getUser($uid, $truename, $mobile)
+    {
+        return $truename . ' | '.$mobile . ' | ' . $uid;
+    }
+}

+ 30 - 0
src/place/channel/sales/manage/Lib/View.php

@@ -0,0 +1,30 @@
+<?php namespace Place_channel_sales\Manage\Lib;
+use Dever;
+class View
+{
+    private $info;
+    private $user;
+
+    # 预览实体店
+    public function getOffline($info)
+    {
+        $info['sales_type'] = 1;
+        return $this->get($info);
+    }
+
+    public function get($info)
+    {
+        $extend = Dever::load('common', 'manage')->extend();
+        $result = Dever::load('info', 'place')->share($extend['data_id'], $info['sales_type'], $info['id'], 0, true);
+        $content[] = [
+            'type' => 'text',
+            'name' => '文本',
+            //'content' => 'H5预览链接:<a href="'.$result['h5'].'" target="_blank">点击查看</a>',
+            'content' => 'H5预览链接:' . $result['h5'],
+            # 样式primary success warning danger info exception
+            'style' => 'exception',
+        ];
+
+        return ['title' => '前台界面预览', 'info' => $content, 'tab' => []];
+    }
+}

+ 39 - 0
src/place/channel/sales/manage/cate.php

@@ -0,0 +1,39 @@
+<?php
+return [
+    'list' => [
+        'field'      => [
+            'name',
+            'type',
+            'sort',
+            'status',
+        ],
+        'button' => [
+            '新增' => ['fastadd'],
+        ],
+        'data_button' => [
+            '编辑' => ['fastedit'],
+            //'删除' => 'delete',
+        ],
+        'search'    => [
+            'name',
+            'type',
+            'status',
+        ],
+    ],
+    'update' => [
+        'field'    => [
+            'name' => [
+                'rules' => true,
+            ],
+            'type' => [
+                'rules' => true,
+                'type' => 'radio',
+            ],
+            'desc' => [
+                //'rules' => true,
+                'type' => 'textarea',
+                'autosize' => ['minRows' => 4],
+            ],
+        ],
+    ],
+];

+ 39 - 0
src/place/channel/sales/manage/core.php

@@ -0,0 +1,39 @@
+<?php
+return [
+    'menu' => [
+        'place_channel_sales' => [
+            'parent'    => 'sector_place_channel',
+            'name'      => '销售渠道',
+            'icon'      => 'safe-2-line',
+            'sort'      => '1',
+        ],
+
+        'offline' => [
+            'parent'    => 'place_channel_sales',
+            'name'      => '实体店',
+            'icon'      => 'home-8-line',
+            'sort'      => '1',
+        ],
+
+        'online' => [
+            'parent'    => 'place_channel_sales',
+            'name'      => '网店',
+            'icon'      => 'shopping-bag-2-line',
+            'sort'      => '2',
+        ],
+
+        'media' => [
+            'parent'    => 'place_channel_sales',
+            'name'      => '自媒体',
+            'icon'      => 'newspaper-line',
+            'sort'      => '3',
+        ],
+
+        'cate' => [
+            'parent'    => 'place_channel_sales',
+            'name'      => '分类',
+            'icon'      => 'align-center',
+            'sort'      => '100',
+        ],
+    ],
+];

+ 185 - 0
src/place/channel/sales/manage/offline.php

@@ -0,0 +1,185 @@
+<?php
+$config = [
+    'list' => [
+        'field'      => [
+            'id' => [
+                'name' => 'ID',
+                'width' => '50px',
+            ],
+            'name' => [
+                'truncate' => true,
+            ],
+            'cate_id' => [
+                'width' => '70px',
+            ],
+            'type' => [
+                'width' => '70px',
+            ],
+            'user' => Dever::call('place_user/manage/user.getInfo', ['联系人信息', '{truename}', '{mobile}']),
+            'address' => [
+                'truncate' => true,
+                'name' => '位置',
+                'show' => 'Dever::call("place_channel_sales/manage/offline.getAddress", ["{area}", "{address}"])',
+            ],
+            'sort',
+            'open' => [
+                'width' => '70px',
+            ],
+            //'status',
+        ],
+        'button' => [
+            '新增' => ['add', 'uid,sales_type,name,info,logo,content,cate_id,type,truename,mobile,area,address,worktime,open'],
+        ],
+        'data_button' => [
+            '编辑' => ['edit', 'uid,sales_type,name,info,logo,content,cate_id,type,area,address,worktime,open'],
+            '库存' => ['route', [
+                'path' => 'place_channel_sales/sales_stock',
+                'param' => [
+                    'set' => ['sales_type' => 1, 'sales_id' => 'id', 'menu' => 'place_channel_sales/offline', 'parent' => 'place_channel_sales/offline'],
+                    # 打开新页面
+                    //'open' => true,
+                ],
+            ]],
+        ],
+        'data_button_list' => [
+            '修改联系人' => ['fastedit', 'uid,sales_type,edit_user,edit_truename,edit_mobile'],
+            '预览' => ['drawer', [
+                'path' => 'place_channel_sales/offline',
+                'param' => [
+                    'type' => 'view',
+                    'id' => 'id',
+                    'set' => ['menu' => 'place_channel_sales/offline', 'parent' => 'place_channel_sales/offline'],
+                ],
+            ]],
+        ],
+        # 列表页导出
+        'export' => [
+            //'out' => '导出',
+            //'manage/common.out' => '自定义导出',
+        ],
+        'search'    => [
+            'name' => 'like',
+            'cate_id' => [
+                'type' => 'select',
+            ],
+            'type',
+            'open',
+            //'status',
+        ],
+    ],
+    # 详情页配置
+    'view' => 'place_channel_sales/manage/view.getOffline',
+
+    'update' => [
+        'start' => ['area/manage/info.update', 'place_channel_sales/manage/info.check'],
+        'end' => 'place_channel_sales/manage/info.createUser',
+        'layout' => [
+            ['name' => 6, 'info' => 6, 'cate_id' => 6, 'type' => 6],
+            ['truename' => 12, 'mobile' => 12],
+            ['area' => 12, 'address' => 12],
+            ['worktime' => 12, 'open' => 12],
+            ['content' => 24],
+            ['edit_user' => 24],
+            ['edit_truename' => 24],
+            ['edit_mobile' => 24],
+        ],
+        'field'    => [
+            'uid' => 'hidden',
+            'sales_type' => [
+                'type' => 'hidden',
+                'value' => 1,
+            ],
+            'name' => [
+                'rules' => true,
+            ],
+
+            'info' => [
+                //'rules' => true,
+            ],
+
+            /*
+            'logo' => [
+                'type' => 'upload',
+                'upload' => 1,
+                'yun' => true,
+                'multiple' => false,
+                'style' => 'pic',
+            ],*/
+            'content' => [
+                'type' => 'editor',
+                'editorMenu' => [
+                    'uploadImage' => 1,
+                    'uploadVideo' => 3,
+                ],
+            ],
+
+            'cate_id' => [
+                'rules' => true,
+                'type' => 'select',
+            ],
+
+            'type' => [
+                'type' => 'radio',
+                'rules' => true,
+            ],
+
+            'truename' => [
+                'rules' => true,
+            ],
+
+            'mobile' => [
+                'rules' => true,
+                'tip' => '将自动关联登录账号',
+                //'rules' => Dever::load('manage/user', 'place_user')->getMobileRules(),
+            ],
+           
+            'area' => [
+                'rules' => true,
+                'type' => 'cascader',
+                'remote'    => Dever::url('area/data.get&total=4'),
+            ],
+            'address' => [
+                'rules' => true,
+                //后续增加定位
+                //'type' => 'map',
+            ],
+            'worktime' => [
+                /*
+                'type' => 'textarea',
+                'autosize' => ['minRows' => 2],
+                */
+                'tip' => '输入文字描述即可',
+            ],
+            'open' => [
+                'type' => 'radio',
+                'rules' => true,
+            ],
+
+            'edit_user' => [
+                'name' => '关联用户信息',
+                'type' => 'show',
+                'default' => 'Dever::call("place_user/manage/user.getName", ["{uid}"])',
+            ],
+
+            'edit_truename' => [
+                'name' => '联系人姓名',
+                'field' => 'truename',
+                'rules' => true,
+                'default' => '{truename}',
+            ],
+
+            'edit_mobile' => [
+                'name' => '手机号',
+                'field' => 'mobile',
+                'desc' => '将自动关联登录账号,请勿频繁修改
+                <br />如手机号已被其他销售渠道使用,将会自动创建新账号
+                <br />如手机号未被使用,则直接修改关联登录账号',
+                'default' => '{mobile}',
+
+                //'rules' => Dever::load('manage/user', 'place_user')->getMobileRules(),
+            ],
+        ],
+    ],
+];
+
+return $config;

+ 35 - 41
src/place/channel/table/seller.php → src/place/channel/sales/table/cate.php

@@ -1,42 +1,36 @@
-<?php
-return [
-    'name' => '销售网店渠道',
-    'partition' => 'Dever::call("manage/common.system")',
-    'order' => 'sort asc',
-    'struct' => [
-        'name' => [
-            'name'      => '网店名称',
-            'type'      => 'varchar(50)',
-        ],
-
-        'type' => [
-            'name'      => '类型',
-            'type'      => 'tinyint(1)',
-            'default'   => 1,
-            'value'     => [
-                1 => '微信小店',
-                2 => '小红书',
-                3 => '抖店',
-                4 => '拼多多',
-                5 => '淘宝',
-                6 => '美团',
-            ],
-        ],
-
-        'status' => [
-            'name'      => '授权状态',
-            'type'      => 'tinyint(1)',
-            'default'   => 2,
-            'value'     => [
-                1 => '已授权',
-                2 => '未授权',
-            ],
-        ],
-
-        'sort' => [
-            'name'      => '排序',
-            'type'      => 'int(11)',
-            'default'   => 1,
-        ],
-    ],
+<?php
+return [
+    'name' => '销售渠道分类表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc',
+    'struct' => [
+        'name' => [
+            'name'      => '分类名称',
+            'type'      => 'varchar(32)',
+        ],
+        'type' => [
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'    => 'Dever::call("place_channel_sales/info.getType")',
+        ],
+        'desc' => [
+            'name'      => '分类介绍',
+            'type'      => 'varchar(1000)',
+        ],
+        'status' => [
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => [
+                1 => '上架',
+                2 => '下架',
+            ],
+        ],
+        'sort' => [
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ],
+    ],
 ];

+ 72 - 0
src/place/channel/sales/table/media.php

@@ -0,0 +1,72 @@
+<?php
+return [
+    'name' => '自媒体',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc',
+    'struct' => [
+        'name' => [
+            'name'      => '名称',
+            'type'      => 'varchar(50)',
+        ],
+
+        'cate_id' => [
+            'name'      => '分类',
+            'type'      => 'int(11)',
+            'value'    => 'Dever::call("place_channel_sales/manage/cate.getData", 3)',
+        ],
+
+        'type' => [
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => [
+                1 => '微信公众号',
+                2 => '今日头条',
+                3 => '小红书',
+                4 => '抖音',
+                5 => '快手',
+            ],
+        ],
+
+        'type_id'       => [
+            'type'      => 'varchar(500)',
+            'name'      => '三方ID',
+        ],
+
+        'website'       => [
+            'type'      => 'varchar(1000)',
+            'name'      => '自媒体网址',
+        ],
+
+        'uid'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户ID',
+        ],
+
+        'truename' => [
+            'name'      => '联系人',
+            'type'      => 'varchar(100)',
+        ],
+
+        'mobile' => [
+            'name'      => '手机号',
+            'type'      => 'bigint(11)',
+        ],
+        
+        'status' => [
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => [
+                1 => '开启',
+                2 => '关闭',
+            ],
+        ],
+
+        'sort' => [
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ],
+    ],
+];

+ 128 - 0
src/place/channel/sales/table/offline.php

@@ -0,0 +1,128 @@
+<?php
+return [
+    'name' => '实体店',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc',
+    'struct' => [
+        'name' => [
+            'name'      => '名称',
+            'type'      => 'varchar(50)',
+        ],
+
+        'info' => [
+            'name'      => '宣传语',
+            'type'      => 'varchar(200)',
+        ],
+        'logo' => [
+            'name'      => 'logo',
+            'type'      => 'varchar(150)',
+        ],
+        'bg' => [
+            'name'      => '背景图',
+            'type'      => 'varchar(150)',
+        ],
+        'content' => [
+            'name'      => '介绍',
+            'type'      => 'text(255)',
+        ],
+
+        'cate_id' => [
+            'name'      => '分类',
+            'type'      => 'int(11)',
+            'value'    => 'Dever::call("place_channel_sales/manage/cate.getData", 1)',
+        ],
+
+        'type' => [
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 10,
+            'value'     => [
+                1 => '总店',
+                10 => '分店',
+            ],
+        ],
+
+        'uid'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户ID',
+        ],
+
+        'truename' => [
+            'name'      => '联系人',
+            'type'      => 'varchar(100)',
+        ],
+        'mobile' => [
+            'name'      => '手机号',
+            'type'      => 'bigint(11)',
+        ],
+        'area' => [
+            'name'      => '城市地区',
+            'type'      => 'varchar(800)',
+        ],
+        'province_id' => [
+            'name'      => '省份',
+            'type'      => 'int(11)',
+        ],
+        'city_id' => [
+            'name'      => '城市',
+            'type'      => 'int(11)',
+        ],
+        'county_id' => [
+            'name'      => '区县',
+            'type'      => 'int(11)',
+        ],
+        'town_id' => [
+            'name'      => '街镇',
+            'type'      => 'int(11)',
+        ],
+        'address' => [
+            'name'      => '详细地址',
+            'type'      => 'varchar(1000)',
+        ],
+
+        'lng'       => array
+        (
+            'type'      => 'varchar(100)',
+            'name'      => '经度',
+        ),
+
+        'lat'       => array
+        (
+            'type'      => 'varchar(100)',
+            'name'      => '纬度',
+        ),
+
+        'open'        => array
+        (
+            'type'      => 'tinyint(1)',
+            'name'      => '营业',
+            'default'   => '1',
+            'value'     => [
+                1 => '营业',
+                2 => '关店',
+            ],
+        ),
+
+        'worktime'      => array
+        (
+            'type'      => 'varchar(100)',
+            'name'      => '营业时间',
+        ),
+
+        'status' => [
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => [
+                1 => '开启',
+                2 => '关闭',
+            ],
+        ],
+
+        'sort' => [
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ],
+    ],
+];

+ 96 - 0
src/place/channel/sales/table/online.php

@@ -0,0 +1,96 @@
+<?php
+return [
+    'name' => '网店',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc',
+    'struct' => [
+        'name' => [
+            'name'      => '名称',
+            'type'      => 'varchar(50)',
+        ],
+
+        'cate_id' => [
+            'name'      => '分类',
+            'type'      => 'int(11)',
+            'value'    => 'Dever::call("place_channel_sales/manage/cate.getData", 2)',
+        ],
+
+        'type' => [
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => [
+                1 => '微信小店',
+                2 => '小红书',
+                3 => '抖店',
+                4 => '拼多多',
+                5 => '京东',
+                6 => '淘宝',
+                7 => '美团',
+                8 => '闲鱼',
+                9 => '1688',
+                100 => '其他',
+            ],
+        ],
+
+        'type_id'       => [
+            'type'      => 'varchar(500)',
+            'name'      => '三方网店ID',
+        ],
+
+        'website'       => [
+            'type'      => 'varchar(1000)',
+            'name'      => '网店网址',
+        ],
+
+        'access_token'       => [
+            'type'      => 'varchar(500)',
+            'name'      => '网店所在平台授权token',
+        ],
+
+        'refresh_token'       => [
+            'type'      => 'varchar(500)',
+            'name'      => '网店所在平台刷新token',
+        ],
+
+        'uid'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户ID',
+        ],
+
+        'truename' => [
+            'name'      => '联系人',
+            'type'      => 'varchar(100)',
+        ],
+        'mobile' => [
+            'name'      => '手机号',
+            'type'      => 'bigint(11)',
+        ],
+
+        'auth_status' => [
+            'name'      => '授权状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => [
+                1 => '已授权',
+                2 => '未授权',
+            ],
+        ],
+
+        'status' => [
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => [
+                1 => '开启',
+                2 => '关闭',
+            ],
+        ],
+
+        'sort' => [
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ],
+    ],
+];

+ 51 - 0
src/place/channel/sales/table/profit.php

@@ -0,0 +1,51 @@
+<?php
+return [
+    'name' => '销售渠道收益记录表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => [
+        'sales_type' => [
+            'name'      => '销售类型',
+            'type'      => 'tinyint(1)',
+            'value'    => 'Dever::call("place_channel_sales/info.getType")',
+        ],
+
+        'sales_id' => [
+            'name'      => '销售ID',
+            'type'      => 'int(11)',
+        ],
+        'uid'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户',
+        ],
+        'user_id'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户积分数据表id',
+        ],
+        'user_log_id'        => [
+            'name'      => '积分日志ID',
+            'type'      => 'int(11)',
+        ],
+        'score_id'        => [
+            'name'      => '积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+        ],
+        'action_id'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户行为',
+            'value'     => 'place_score/action',
+        ],
+        'amount'        => [
+            'name'      => '积分数额',
+            'type'      => 'decimal(11,2)',
+        ],
+        'money'        => [
+            'name'      => '货币金额',
+            'type'      => 'varchar(50)',
+        ],
+    ],
+
+    'index' => [
+        'search' => 'sales_type,sales_id',
+    ],
+];

+ 49 - 0
src/place/channel/sales/table/seller.php

@@ -0,0 +1,49 @@
+<?php
+return [
+    'name' => '经销商',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc',
+    'struct' => [
+        'name' => [
+            'name'      => '名称',
+            'type'      => 'varchar(50)',
+        ],
+
+        'cate_id' => [
+            'name'      => '分类',
+            'type'      => 'int(11)',
+            'value'    => 'Dever::call("place_channel_sales/manage/cate.getData", 4)',
+        ],
+
+        'uid'       => [
+            'type'      => 'int(11)',
+            'name'      => '用户ID',
+        ],
+
+        'truename' => [
+            'name'      => '联系人',
+            'type'      => 'varchar(100)',
+        ],
+
+        'mobile' => [
+            'name'      => '手机号',
+            'type'      => 'bigint(11)',
+        ],
+        
+        'status' => [
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => [
+                1 => '开启',
+                2 => '关闭',
+            ],
+        ],
+
+        'sort' => [
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ],
+    ],
+];

+ 5 - 0
src/place/channel/supply/index.php

@@ -0,0 +1,5 @@
+<?php
+define('DEVER_APP_NAME', 'place_channel_supply');
+define('DEVER_APP_LANG', '身份供货渠道');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(DEVER_APP_PATH . '../../boot.php');

+ 0 - 42
src/place/channel/table/shop_offline.php

@@ -1,42 +0,0 @@
-<?php
-return [
-    'name' => '线下门店',
-    'partition' => 'Dever::call("manage/common.system")',
-    'order' => 'sort asc',
-    'struct' => [
-        'name' => [
-            'name'      => '门店名称',
-            'type'      => 'varchar(50)',
-        ],
-
-        'type' => [
-            'name'      => '门店类型',
-            'type'      => 'tinyint(1)',
-            'default'   => 1,
-            'value'     => [
-                1 => '直营店',
-                2 => '连锁店',
-                3 => '抖店',
-                4 => '拼多多',
-                5 => '淘宝',
-                6 => '美团',
-            ],
-        ],
-
-        'status' => [
-            'name'      => '授权状态',
-            'type'      => 'tinyint(1)',
-            'default'   => 2,
-            'value'     => [
-                1 => '已授权',
-                2 => '未授权',
-            ],
-        ],
-
-        'sort' => [
-            'name'      => '排序',
-            'type'      => 'int(11)',
-            'default'   => 1,
-        ],
-    ],
-];

+ 0 - 38
src/place/channel/table/supplier.php

@@ -1,38 +0,0 @@
-<?php
-return [
-    'name' => '供应商',
-    'partition' => 'Dever::call("manage/common.system")',
-    'order' => 'sort asc',
-    'struct' => [
-        'name' => [
-            'name'      => '供应商名称',
-            'type'      => 'varchar(50)',
-        ],
-
-        'mobile' => [
-            'name'      => '联系电话',
-            'type'      => 'varchar(50)',
-        ],
-
-        'type' => [
-            'name'      => '类型',
-            'type'      => 'tinyint(1)',
-            'default'   => 1,
-            'value'     => [
-                1 => '源小货',
-                2 => '1688',
-            ],
-        ],
-
-        'type_id'       => [
-            'type'      => 'varchar(50)',
-            'name'      => '供应商ID',
-        ],
-
-        'sort' => [
-            'name'      => '排序',
-            'type'      => 'int(11)',
-            'default'   => 1,
-        ],
-    ],
-];

+ 71 - 0
src/place/interface/api/Bind.php

@@ -0,0 +1,71 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+use Place_act\Lib\Core as Act;
+class Bind extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+
+    # 获取手机号
+    public function getMobile()
+    {
+        if (Place::$user['type'] == 1) {
+            Dever::error('您已绑定过手机号');
+        }
+        $mobile = Dever::input('mobile', 'is_numeric', '手机号');
+        return $mobile;
+    }
+
+    # 发送短信验证码
+    public function sms()
+    {
+        $mobile = $this->getMobile();
+        $data = Dever::load('template', 'msg')->send('user_code', ['mobile' => $mobile]);
+        return $data;
+    }
+
+    # 绑定手机号
+    public function mobile()
+    {
+        $mobile = $this->getMobile();
+        # 检测这个手机号是否被绑定过
+        $check = Dever::db('info', 'place_user')->find(['mobile' => $mobile]);
+        $merge = false;
+        if ($check && $check['id'] != Place::$uid) {
+            //Dever::error('这个手机号已被绑定,请更换');
+            # 直接做合并
+            $merge = $check['id'];
+        }
+
+        $code = Dever::input('code', 'is_numeric', '验证码');
+        Dever::load('template', 'msg')->check('user_code', $mobile, $code);
+
+        $state = false;
+        if ($merge) {
+            # 把当前用户删掉,然后把用户之前的信息都合并过来
+            Dever::db('info', 'place_user')->update(Place::$uid, ['is_delete' => 1]);
+
+        } else {
+            $state = Dever::db('info', 'place_user')->update(Place::$uid, ['mobile' => $mobile, 'type' => 1]);
+
+            $user = Dever::db('info', 'place_user')->find(Place::$uid);
+            Dever::load('info', 'place_role')->up(Place::$uid, $user['sales_type'], $user['sales_id']);
+        }
+        if (!$state) {
+            Dever::error('绑定失败,请重试');
+        }
+        return 'ok';
+    }
+
+    # 获取微信手机号
+    public function getWexinMobile()
+    {
+        $code = Dever::input('code', 'is_string', '微信验证码');
+
+    }
+
+    # 绑定邮箱
+    # 绑定实名
+}

+ 86 - 59
src/place/interface/api/Main.php

@@ -41,7 +41,6 @@ class Main extends Core
                 ];
             }
         }
-        //$data['i'] = htmlspecialchars_decode(Place::$info['content']);
         $data['n'] = Place::$info['name'];
         $data['i'] = Place::$info['info'];
         $data['l'] = Place::$info['logo'];
@@ -50,6 +49,13 @@ class Main extends Core
         return $data;
     }
 
+    # 获取身份介绍
+    public function getContent()
+    {
+        $data['content'] = htmlspecialchars_decode(Place::$info['content']);
+        return $data;
+    }
+
     # 获取个人中心首页需要的信息
     public function getUserHome()
     {
@@ -59,6 +65,8 @@ class Main extends Core
         if ($data['role']) {
             foreach ($data['role'] as &$v) {
                 if ($v['info'] && !$data['role_info']) {
+                    $v['subname'] = $v['info'];
+                    $v['button'] = '立即开通';
                     $data['role_info'] = $v;
                 }
                 $v['level_name'] = '成为' . $v['name'];
@@ -76,81 +84,115 @@ class Main extends Core
     public function login_commit(){}
     public function login()
     {
-        $account = Dever::input('account', 'is_string', '账户信息', 'wechat');
-        $env = Dever::input('env', 'is_numeric', '环境信息', 3);
         $mobile = Dever::input('mobile', 'is_numeric', '手机号');
         $pwd = Dever::input('pwd');
         if (!$pwd) {
             $code = Dever::input('code', 'is_numeric', '验证码');
             Dever::load('template', 'msg')->check('reg_code', $mobile, $code);
         }
-        $where['mobile'] = $mobile;
+        $invite = Dever::input('invite');
         $db = Dever::db('info', 'place_user');
-        $user = $db->find($where);
+        $user = $db->find(['mobile' => $mobile]);
         if ($user) {
+            $action = '登录';
             if ($pwd && Dever::load('common', 'manage')->hash($pwd, $user['salt']) != $user['password']) {
                 Dever::error('登录失败,密码无效');
             }
             # 已注册,登录
             $uid = $user['id'];
+            # 记录日志
             Dever::load('log', 'place_score')->action('登录')->add($uid);
             # 升级初始角色等级
-            Dever::load('info', 'place_role')->up($uid);
+            if ($user['type'] == 1) {
+                Dever::load('info', 'place_role')->up($uid, $user['sales_type'], $user['sales_id']);
+            }
         } else {
-            Dever::error('登录失败,账户无效');
+            $action = '注册';
+            if ($invite) {
+                $parent_uid = Dever::load('code', 'invite')->getUid($invite);
+                if (!$parent_uid) {
+                    Dever::error('邀请码不存在');
+                }
+            } else {
+                # 如果没有上级,从入口码里找:
+                $parent_uid = Place::$info['parent_uid'];
+                /*  这里暂时不做
+                if (!$parent_uid && Place::$info['sales_type'] && Place::$info['sales_id']) {
+                    # 如果还没有上级,找销售渠道,销售渠道就是其的上级
+                    $sales = Dever::load('info', 'place_channel_sales')->get(Place::$info['sales_type'] && Place::$info['sales_id']);
+                    if ($sales['uid']) {
+                        $parent_uid = $sales['uid'];
+                    }
+                }*/
+            }
+            $uid = Dever::load('info', 'place_user')->createUser($mobile, Place::$info['sales_type'], Place::$info['sales_id'], $parent_uid);
         }
-        return $this->result($account, $env, $uid);
+        return $this->result($uid);
     }
 
-    # 注册
+    # 静默注册
     public function reg_commit(){}
     public function reg()
     {
-        $account = Dever::input('account', 'is_string', '账户信息', 'wechat');
+        $value = Dever::input('uuid');
+        if (!$value) {
+            return [];
+        }
+        $platform = Dever::input('platform', 'is_string', '平台信息', 'weixin');
         $env = Dever::input('env', 'is_numeric', '环境信息', 3);
-        $mobile = Dever::input('mobile', 'is_numeric', '手机号');
-        $pwd = Dever::input('pwd', 'is_string', '密码');
-        $code = Dever::input('code', 'is_numeric', '验证码');
-        $invite = Dever::input('invite');
-        Dever::load('template', 'msg')->check('reg_code', $mobile, $code);
-        $where['mobile'] = $mobile;
-        $db = Dever::db('info', 'place_user');
-        $user = $db->find($where);
-        if ($user) {
-            Dever::error('手机号已注册,请登录');
-        } else {
-            if ($invite) {
-                $parent_uid = Dever::load('code', 'invite')->getUid($invite);
-                if (!$parent_uid) {
-                    Dever::error('邀请码不存在');
+        if ($env == 5) {
+            $value = false;
+            # 小程序下获取openid
+            $account = Dever::db('account', 'api')->find(['key' => $platform]);
+            if ($account) {
+                $param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
+                $applet = Dever::load('account', 'api')->run($account, 'applet_login', $param, $env);
+                if (isset($applet['openid'])) {
+                    $value = $applet['openid'];
                 }
             }
-            $data = $where;
-            $data['name'] = \Dever\Helper\Str::hide($mobile);
-            # 默认头像 https://github.com/dicebear/dicebear
-            $data['avatar'] = 'https://api.dicebear.com/7.x/lorelei/svg?seed=' . urlencode($data['name']);
-            $uid = $db->insert($data);
-            if ($invite) {
-                $parent = $db->find($parent_uid);
-                if ($parent) {
-                    Dever::load('relation', 'invite')->set($parent_uid, $uid);
-                    $db->update($uid, ['parent_uid' => $parent_uid]);
+        }
+        if (!$value) {
+            return [];
+        }
+        $data = ['env' => $env, 'platform' => $platform, 'value' => $value];
+        $uuid = Dever::db('uuid', 'place_user')->find($data);
+        if ($uuid) {
+            return $this->result($uuid['uid'], false);
+        }
+        $id = Dever::db('uuid', 'place_user')->insert($data);
+        if ($id) {
+            # 生成新用户
+            $parent_uid = Place::$info['parent_uid'];
+            $mobile = Dever::load('info', 'place_user')->createMobile();
+            $uid = Dever::load('info', 'place_user')->createUser($mobile, Place::$info['sales_type'], Place::$info['sales_id'], $parent_uid, 2);
+            if ($uid) {
+                Dever::db('uuid', 'place_user')->update($id, ['uid' => $uid]);
+                if ($env == 5) {
+                    $update['uid'] = $uid;
+                    $update['account_id'] = $account['id'];
+                    $update['env'] = $env;
+                    $update['openid'] = $value;
+                    Dever::db('openid', 'api')->insert($update);
                 }
             }
-            Dever::load('log', 'place_score')->action('注册')->add($uid);
-            # 升级初始角色等级
-            Dever::load('info', 'place_role')->up($uid);
+            return $this->result($uid, false);
         }
-        return $this->result($account, $env, $uid);
     }
 
-    private function result($account, $env, $uid)
+    # env = 2 => 'h5',3 => 'jsapi',4 => 'app',5 => '小程序',6 => 'pc',
+    private function result($uid, $openid = true)
     {
         $result['t'] = \Dever\Helper\Secure::login($uid);
-        # 获取openid
-        $result = Dever::load('util', 'api')->openid($account, $env, $uid, $result);
-        if (isset($result['openid'])) {
-            unset($result['openid']);
+        if ($openid) {
+            # 获取openid
+            $platform = Dever::input('platform', 'is_string', '平台信息', 'wechat');
+            $env = Dever::input('env', 'is_numeric', '环境信息', 3);
+
+            $result = Dever::load('util', 'api')->openid($platform, $env, $uid, $result);
+            if (isset($result['openid'])) {
+                unset($result['openid']);
+            }
         }
         return $result;
     }
@@ -186,19 +228,4 @@ class Main extends Core
         }
         return $info;
     }
-
-    # 获取版权信息
-    public function version()
-    {
-        $data = [
-            'name' => '源代宝',
-            'info' => '让资源交易更简单',
-            'logo' => 'http://127.0.0.1/ydb/data/yuandaibao_v2/upload/3_1/5_1/1/f5/ad/4a/f5ad4a6f12853b9b155bca3ed26d2698.png?t=1748266972',
-            'site' => 'yuandaibao.com',
-            'company' => '北京时空之翼网络科技有限公司  版权所有',
-            'copyright' => 'Copyright © 2020-2025 Shemic. All Rights Reserved.',
-            'version' => 'v1.0.0',//后续增加
-        ];
-        return $data;
-    }
 }

+ 36 - 0
src/place/interface/api/Order.php

@@ -2,6 +2,7 @@
 use Dever;
 use Place;
 use Place_interface\Lib\Core;
+use Place_act\Lib\Core as Act;
 class Order extends Core
 {
     protected $login = true;
@@ -93,4 +94,39 @@ class Order extends Core
         }
         return $info;
     }
+
+    # 提交评价
+    public function review_commit(){}
+    public function review()
+    {
+        $info = $this->getInfo();
+        if ($info['review_status'] != 2) {
+            Dever::error('您现在不可以评价');
+        }
+        $data['pic'] = Dever::input('pic');
+        if (!$data['pic']) {
+            $data['pic'] = '';
+        }
+        $data['content'] = Dever::input('content', 'is_string', '内容');
+        $data['rate'] = Dever::input('rate', 'is_numeric', '评分');
+        if (!$data['rate']) {
+            Dever::error('评分错误');
+        }
+        $data['rate'] = intval($data['rate']);
+        if ($data['rate'] > 5 || $data['rate'] <= 0) {
+            Dever::error('评分错误');
+        } 
+        $data['open'] = Dever::input('open');
+        if ($data['open'] == 'true') {
+            $data['open'] = 1;
+        } else {
+            $data['open'] = 2;
+        }
+        $detail = Dever::db('source_detail', 'place_order')->select(['order_id' => $info['id']]);
+        foreach ($detail as $v) {
+            $act = Act::load('review', 1, $v['source_id'])->up($data, '请不要发布相同内容');
+        }
+        Dever::db('source', 'place_order')->update($info['id'], ['review_status' => 3]);
+        return 'ok';
+    }
 }

+ 337 - 0
src/place/interface/api/Sales.php

@@ -0,0 +1,337 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+class Sales extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+    protected $info;
+    protected $data = [];
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->data['sales_type'] = Dever::input('sales_type', 'is_numeric', '销售渠道类型');
+        $this->data['sales_id'] = Dever::input('sales_id', 'is_numeric', '销售渠道ID');
+        $this->info = Dever::load('info', 'place_channel_sales')->get($this->data['sales_type'], $this->data['sales_id']);
+        if ($this->info['uid'] != Place::$uid) {
+            Dever::error('您没有权限', -3);
+        }
+        $this->info['mobile'] = \Dever\Helper\Str::hide($this->info['mobile']);
+        if (!$this->info['info']) {
+            $this->info['info'] = Place::$info['info'];
+        }
+    }
+
+    # 销售渠道信息
+    public function info()
+    {
+        $data['user'] = Place::$user;
+        $data['info'] = $this->info;
+        $data['desc'] = $this->info['info'];
+
+        # 获取权益
+        $data['benefit'] = '';
+        $benefit = Dever::db('sales', 'place_benefit')->find(['sales_cate_id' => $this->info['cate_id'], 'status' => 1]);
+        if ($benefit && $benefit['desc']) {
+            $data['benefit'] = htmlspecialchars_decode($benefit['desc']);
+        }
+        
+        # 用户数
+        $where = $this->data;
+        $where['status'] = 1;
+        $data['member'] = Dever::db('info', 'place_user')->count($this->data);
+
+        # 角色数
+        $data['role'] = [];
+        # 角色列表
+        $role = Dever::db('info', 'place_role')->select(['status' => 1]);
+        if ($role) {
+            $roleWhere = $this->data;
+            foreach ($role as $k => $v) {
+                $level = Dever::db('level', 'place_role')->find(['info_id' => $v['id'], 'status' => 1]);
+                if ($level) {
+                    $roleWhere['info_id'] = $v['id'];
+                    $roleWhere['status'] = 1;
+                    $num = Dever::db('user', 'place_role')->count($roleWhere);
+                    $data['role'][] = ['id' => $v['id'], 'name' => $v['name'], 'num' => $num];
+                }
+            }
+        }
+
+        # 订单数
+        unset($where['status']);
+        $data['order'] = Dever::db('source', 'place_order')->count($where);
+
+        $money = Place::money();
+        
+        # 收益
+        $data['profit'] = Dever::db('profit', 'place_channel_sales')->sum($where, 'money') . $money['unit'];
+
+        # 流水
+        $where['status'] = ['in', '2,3,4,5,6'];
+        $data['cash'] = Dever::db('source', 'place_order')->sum($where, 'money_cash') . $money['unit'];
+
+
+        # 获取待付款
+        $where['status'] = 1;
+        $data['order_1'] = Dever::db('source', 'place_order')->count($where);
+        # 待发货
+        $where['status'] = 2;
+        $data['order_2'] = Dever::db('source', 'place_order')->count($where);
+        # 待收货
+        $where['status'] = ['in', '3,4'];
+        $data['order_3'] = Dever::db('source', 'place_order')->count($where);
+        # 已完成
+        $where['status'] = ['in', '5,6'];
+        $data['order_4'] = Dever::db('source', 'place_order')->count($where);
+
+        # 有退款
+        unset($where['status']);
+        $where['refund_status'] = 1;
+        $data['order_5'] = Dever::db('source', 'place_order')->count($where);
+        return $data;
+    }
+
+    # 店铺用户列表
+    public function getUser()
+    {
+        $this->data['status'] = 1;
+        $data['list'] = Dever::db('info', 'place_user')->select($this->data, ['num' => 10, 'col' => 'id,name,avatar,num_order,cdate']);
+        if ($data['list']) {
+            foreach ($data['list'] as &$v) {
+                $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
+                $v['order'] = $v['num_order'] . '单';
+            }
+        }
+        $data['page'] = Dever::page('total');
+        return $data;
+    }
+
+    # 店铺角色用户列表
+    public function getRoleUser()
+    {
+        $id = Dever::input('id', 'is_numeric', '角色');
+        $this->data['info_id'] = $id;
+        $this->data['status'] = 1;
+        $data['info'] = $info = Dever::db('info', 'place_role')->find(['id' => $id, 'status' => 1], ['col' => 'id,name,info,score_id']);
+        $user = Dever::db('user', 'place_role')->select($this->data, ['num' => 10, 'col' => '*']);
+        $data['list'] = [];
+        if ($user) {
+            foreach ($user as $k => $v) {
+                $data['list'][$k] = Dever::db('info', 'place_user')->find($v['uid'], ['col' => 'id,name,avatar,num_order']);
+                if ($data['list'][$k]) {
+                    $data['list'][$k]['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
+                    # 获取订单数
+                    $data['list'][$k]['order'] = $data['list'][$k]['num_order'] . '单';
+                }
+            }
+        }
+        $data['page'] = Dever::page('total');
+        return $data;
+    }
+
+    # 店铺订单列表
+    public function getOrder()
+    {
+        $status = Dever::input('status');
+        $data = Dever::load('source/order', 'place_order')->getList(Place::$uid, $status, $this->data['sales_type'], $this->data['sales_id']);
+        return ['list' => $data];
+    }
+
+    # 店铺订单详情
+    public function getOrderView()
+    {
+        $info = $this->getOrderInfo();
+        $info = Dever::load('source/order', 'place_order')->getInfo($info, true);
+        $data = ['info' => $info, 'refund_desc_type' => Dever::db('source_refund', 'place_order')->value('desc_type'), 'refund_type' => Dever::db('source_refund', 'place_order')->value('type')];
+        $data['express'] = [Dever::call("sector/delivery.getList", 1)];
+        $data['virtual'] = [Dever::call("sector/delivery.getList", 2)];
+
+        # 获取退货地址
+        if ($data['info']['refund_status'] == 1 && isset($data['info']['refund']) && $data['info']['refund'] && $data['info']['refund']['status'] == 1 && $data['info']['refund']['type'] == 1 && $data['info']['method'] > 1) {
+            //$data['address'] = Dever::load('address', 'place')->getList();
+            $name = $this->info['name'];
+            $data['address'][] = ['id' => 'sales_' . $this->data['sales_type'] . '_' . $this->data['sales_id'], 'name' => $name];
+            $data['address'] = [$data['address']];
+        }
+        return $data;
+    }
+
+    # 获取订单信息
+    private function getOrderInfo()
+    {
+        $id = Dever::input('order_id');
+        if (!$id) {
+            Dever::error('订单信息错误');
+        }
+        $info = Dever::db('source', 'place_order')->find(['id' => $id, 'sales_type' => $this->data['sales_type'], 'sales_id' => $this->data['sales_id']]);
+        if (!$info) {
+            Dever::error('订单信息有误');
+        }
+        return $info;
+    }
+
+    # 确认自提
+    public function setPickup()
+    {
+        $info = $this->getOrderInfo();
+        $code = Dever::input('code', 'is_numeric', '自提码');
+        $info['code'] = substr($info['cdate'], -4);
+        if ($info['code'] != $code) {
+            Dever::error('自提码错误');
+        }
+        Dever::load('source/order', 'place_order')->finish($this->data['sales_type'], $info, true, $this->data['sales_id']);
+        return 'ok';
+    }
+
+    # 发货
+    public function setDelivery()
+    {
+        $info = $this->getOrderInfo();
+        $detail_id = Dever::input('detail_id', 'is_numeric', '订单信息');
+        $delivery_id = Dever::input('delivery_id', 'is_numeric', '发货信息');
+        $content = Dever::input('content', 'is_string', '发货信息');
+        Dever::load('source/delivery', 'place_order')->up($info['id'], $detail_id, $delivery_id, $content, $this->data['sales_type']+10, $this->data['sales_id']);
+        return 'ok';
+    }
+
+    # 审核退款
+    public function setRefund()
+    {
+        $data = $this->getOrderView();
+        if ($data['info']['refund_status'] == 1 && isset($data['info']['refund']) && $data['info']['refund']) {
+            $type = Dever::input('type', 'is_numeric', '审核类型');
+            $desc = Dever::input('desc');
+            $address_id = Dever::input('address_id');
+            if ($type == 2 && !$desc) {
+                Dever::error('审核备注不能为空');
+            }
+            if ($type == 1 && isset($data['address']) && $data['address']) {
+                if (!$address_id) {
+                    Dever::error('请选择退货地址');
+                }
+            }
+            Dever::load('source/refund', 'place_order')->audit($data['info']['refund']['id'], $type, $desc, $address_id, $this->data['sales_type']+10, $this->data['sales_id']);
+            return 'ok';
+        } else {
+            Dever::error('审核失败');
+        }
+    }
+
+    # 审核退货
+    public function setRefundDelivery()
+    {
+        $data = $this->getOrderView();
+        if ($data['info']['refund_status'] == 1 && isset($data['info']['refund']) && $data['info']['refund']) {
+            $type = Dever::input('type', 'is_numeric', '审核类型');
+            $desc = Dever::input('desc');
+            if ($type == 2 && !$desc) {
+                Dever::error('审核备注不能为空');
+            }
+            Dever::load('source/refund', 'place_order')->auditDelivery($data['info']['refund']['id'], $type, $desc, $this->data['sales_type']+10, $this->data['sales_id']);
+            return 'ok';
+        } else {
+            Dever::error('审核失败');
+        }
+    }
+
+    # 店铺订单发货、退款、代完成等
+
+    # 店铺流水列表
+    public function getOrderCash()
+    {
+        
+    }
+
+    # 店铺收益列表
+    public function getProfit()
+    {
+        $where = $this->data;
+        $data['money'] = Place::money();
+        $data['cash'] = Dever::db('profit', 'place_channel_sales')->sum($where, 'money') . $data['money']['unit'];
+        $data['list'] = Dever::db('profit', 'place_channel_sales')->select($where, ['num' => 10]);
+        if ($data['list']) {
+            foreach ($data['list'] as &$v) {
+                $log = Dever::db('user_log', 'place_score')->find($v['user_log_id']);
+                $v['desc'] = $log['desc'];
+                $v['cdate'] = date('Y-m-d H:i:s', $v['cdate']);
+                $info = Dever::db('action', 'place_score')->find($v['action_id']);
+                $v['action_name'] = $info['name'];
+                $v['amount'] = Dever::load('info', 'place_score')->getText($v['amount'], $v['score_id']);
+                $v['money'] .= $data['money']['unit'];
+            }
+        }
+        return $data;
+    }
+
+    # 店铺权益列表 暂时不做
+    public function getBenefit()
+    {
+
+    }
+
+    # 获取店铺信息
+    public function getInfo()
+    {
+        $this->info['content'] = htmlspecialchars_decode($this->info['content']);
+        if (isset($this->info['area'])) {
+            $this->info['area_string'] = Dever::load('data', 'area')->string($this->info['area'], '-');
+            $this->info['area'] = explode(',', 'CN,' . $this->info['area']);
+        }
+        return $this->info;
+    }
+
+    # 更新信息
+    public function update()
+    {
+        $update = [];
+        $name = Dever::input('name', 'is_string', '名称');
+        $truename = Dever::input('truename', 'is_string', '联系人');
+        $this->info['name'] = $update['name'] = $name;
+        $this->info['truename'] = $update['truename'] = $truename;
+        $logo = Dever::input('logo');
+        if ($logo) {
+            $this->info['logo'] = $update['logo'] = $logo;
+        }
+        $info = Dever::input('info');
+        if ($info) {
+            $this->info['info'] = $update['info'] = $info;
+        }
+        $content = Dever::input('content');
+        if ($content) {
+            $this->info['content'] = $update['content'] = $content;
+        }
+        $open = Dever::input('open');
+        if ($open) {
+            $this->info['open'] = $update['open'] = $open;
+        }
+        $worktime = Dever::input('worktime');
+        if ($worktime) {
+            $this->info['worktime'] = $update['worktime'] = $worktime;
+        }
+
+        if (isset($this->info['area'])) {
+            $province = Dever::input('province_id', 'is_numeric', '省份');
+            $city = Dever::input('city_id', 'is_numeric', '城市');
+            $county = Dever::input('county_id', 'is_numeric', '区县');
+            $town = Dever::input('town_id', 'is_numeric', '街镇');
+            $address = Dever::input('address', 'is_string', '地址');
+            $this->info['province_id'] = $update['province_id'] = $province;
+            $this->info['city_id'] = $update['city_id'] = $city;
+            $this->info['county_id'] = $update['county_id'] = $county;
+            $this->info['town_id'] = $update['town_id'] = $town;
+            if ($province && $city && $county && $town) {
+                $update['area'] = $province . ',' . $city . ',' . $county . ',' . $town;
+            }
+            $this->info['address'] = $update['address'] = $address;
+        }
+        if ($update) {
+            $table = Dever::load('info', 'place_channel_sales')->getTypeName($this->data['sales_type']);
+            Dever::load('info', 'place')->update(Place::$info['id']);
+            Dever::db($table, 'place_channel_sales')->update($this->data['sales_id'], $update);
+        }
+        return $this->getInfo();
+    }
+}

+ 8 - 0
src/place/interface/api/Score.php

@@ -29,6 +29,14 @@ class Score extends Core
         return $data;
     }
 
+    # 获取获得的积分总额说明
+    public function getCash()
+    {
+        $name = Dever::input('name', 'is_string', '类型');
+        $data['cash'] = Dever::load('log', 'place_score')->getCash(Place::$uid, $name);
+        return $data;
+    }
+
     # 获取充值信息
     public function recharge()
     {

+ 90 - 5
src/place/interface/api/Source.php

@@ -37,28 +37,111 @@ class Source extends Core
         return $data;
     }
 
+    # 搜索页
+    public function search()
+    {
+        $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
+        $source = Dever::input('source', 'is_numeric', '页面来源');
+        # 搜索历史
+        $data['history'] = [];
+        if (Place::$uid) {
+            $data['history'] = Dever::db('search', 'place_user')->select(['uid' => Place::$uid, 'channel_id' => $channel_id], ['limit' => 10]);
+        }
+        
+        # 热门搜索
+        $data['hot'] = Dever::db('search', 'place_source')->select(['channel_id' => $channel_id, 'status' => 1], ['limit' => 10]);
+        return $data;
+    }
+
+    # 搜索页搜索
+    public function searchData()
+    {
+        $search = Dever::input('search', 'is_string', '搜索词');
+        $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
+        $source = Dever::input('source', 'is_numeric', '页面来源');
+        $channel = Dever::load('channel', 'place_source')->getInfo($channel_id);
+        $channel['score'] = Dever::load('info', 'place_score')->get($channel['score_id']);
+        $channel['scope'] = '1,' . $channel['id'];
+        $data['list'] = Dever::load('info', 'place_source')->getList($channel, false, 10);
+
+        if (Place::$uid) {
+            # 记录历史
+            $history = ['uid' => Place::$uid, 'channel_id' => $channel_id, 'source' => $source, 'search' => $search];
+            $info = Dever::db('search', 'place_user')->find($history);
+            if (!$info) {
+                $history['num'] = 1;
+                Dever::db('search', 'place_user')->insert($history);
+            } else {
+                Dever::db('search', 'place_user')->update($info['id'], ['num' => ['+', 1]]);
+            }
+            Dever::db('search', 'place_source')->update(['channel_id' => $channel_id, 'value' => $search], ['num' => ['+', 1]]);
+            Dever::load('log', 'place_score')->action('搜索')->add(Place::$uid);
+        }
+
+        # 搜索页轮播图、搜索页信息流
+        $data['ad'] = Dever::load('ad', 'place_page')->gets([41,42], $channel_id, false);
+
+        return $data;
+
+    }
+
+    # 频道分类页
+    public function channel()
+    {
+        $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
+        # 获取频道信息
+        $channel = Dever::load('channel', 'place_source')->getInfo($channel_id);
+
+        $data['channel'] = [
+            'id'    => $channel['id'],
+            'name'  => $channel['name'],
+            'desc'  => $channel['desc'],
+        ];
+
+        # 获取主分类
+        $data['top'] = Dever::load('cate', 'place_source')->getTop($channel_id, 0);
+        if ($data['top']) {
+            foreach ($data['top'] as &$v) {
+                $v['cate'][] = ['id' => $v['id'], 'name' => '全部'];
+                $v['cate'] = array_merge($v['cate'], Dever::load('cate', 'place_source')->getList($channel_id, $v['id']));
+            }
+        }
+
+        return $data;
+    }
+
     # 分类列表页
     public function cate()
     {
+        $show = Dever::input('show');
         $cate_id = Dever::input('id', 'is_numeric', '分类ID');
         $cate = Dever::load('cate', 'place_source')->getInfo($cate_id);
+        $data['list'] = Dever::load('info', 'place_source')->getList($cate, false, 10);
+        if ($show == 2) {
+            # 仅展示分类列表
+            return $data;
+        }
         $data['cate'] = [
             'id'    => $cate['id'],
             'name'  => $cate['name'],
             'desc'  => $cate['desc'],
         ];
-        $data['list'] = Dever::load('info', 'place_source')->getList($cate, false, 10);
-
         $data['child'] = [];
         if ($cate['parent_id'] == 0) {
             $cate_id = $cate['id'];
-            $data['child'] = Dever::load('cate', 'place_source')->getList($cate['channel_id'], $cate['id']);
+            $data['child'][] = ['id' => $cate['id'], 'name' => '全部'];
+            $data['child'] = array_merge($data['child'], Dever::load('cate', 'place_source')->getList($cate['channel_id'], $cate['id']));
         } else {
             $cate_id = $cate['parent_id'];
         }
 
         # 列表页轮播图、列表页信息流
         $data['ad'] = Dever::load('ad', 'place_page')->gets([11,12], $cate['channel_id'], $cate_id);
+        if (isset($data['ad']['info']) && $data['ad']['info']) {
+            foreach ($data['list'] as $k => $v) {
+
+            }
+        }
 
         return $data;
     }
@@ -68,9 +151,11 @@ class Source extends Core
     {
         $source_id = Dever::input('id', 'is_numeric', '资源ID');
         $info = Dever::load('info', 'place_source')->getInfo($source_id);
+        $data['user'] = Place::$user;
         $data['info'] = [
             'id'            => $info['id'],
             'cate_id'       => $info['cate_id'],
+            'channel_id'    => $info['channel_id'],
             'name'          => $info['name'],
             'info'          => $info['info'],
             'sku_name'      => $info['sku_name'],
@@ -99,7 +184,7 @@ class Source extends Core
         }
 
         # 获取评价
-        $data['review'] = Act::load('review', 1, $source_id)->getList(['limit' => 3]);
+        $data['review'] = Act::load('review', 1, $source_id)->getList(['limit' => 3], 'content,pic,rate,open');
         # 评价总数
         $data['review_total'] = Act::load('review', 1, $source_id)->getTotal();
 
@@ -179,7 +264,7 @@ class Source extends Core
     {
         $source_id = Dever::input('source_id', 'is_numeric', '资源ID');
         $num = Dever::input('num', 'is_numeric', '分页条数', 10);
-        $data = Act::load('review', 1, $source_id)->getList(['num' => $num]);
+        $data = Act::load('review', 1, $source_id)->getList(['num' => $num], 'content,pic,rate,open');
         $result['list'] = $data;
         $result['total'] = Dever::page('total');
         return $result;

+ 47 - 5
src/place/interface/api/User.php

@@ -2,6 +2,7 @@
 use Dever;
 use Place;
 use Place_interface\Lib\Core;
+use Place_act\Lib\Core as Act;
 class User extends Core
 {
     protected $login = true;
@@ -11,6 +12,9 @@ class User extends Core
     public function info()
     {
         $data['user'] = Place::$user;
+        if ($data['user']['type'] == 2) {
+            $data['user']['mobile'] = '临时用户,请先绑定手机号';
+        }
         # 优惠券
         $data['user']['coupon'] = Dever::db('coupon', 'place_user')->count(['uid' => Place::$uid, 'status' => 1]);
         # 礼品卡
@@ -33,7 +37,7 @@ class User extends Core
                     $v['subname'] = $user_role[$v['id']];
                     $v['button'] = '了解详情';
                 } else {
-                    $v['subname'] = $v['info'];
+                    $v['subname'] = '未开通';
                     $v['button'] = '立即开通';
                 }
                 
@@ -54,6 +58,24 @@ class User extends Core
             }
         }
 
+        # 获取待付款
+        $data['order_1'] = Dever::db('source', 'place_order')->count(['uid' => Place::$uid, 'status' => 1]);
+        # 待发货
+        $data['order_2'] = Dever::db('source', 'place_order')->count(['uid' => Place::$uid, 'status' => 2]);
+        # 待收货
+        $data['order_3'] = Dever::db('source', 'place_order')->count(['uid' => Place::$uid, 'status' => ['in', '3,4']]);
+        # 待评价
+        $data['order_4'] = Dever::db('source', 'place_order')->count(['uid' => Place::$uid, 'review_status' => 2]);
+
+        # 获取用户管理信息
+        $data['sales'] = Dever::load('info', 'place_channel_sales')->getList(Place::$uid);
+        return $data;
+    }
+
+    # 仅获取用户信息
+    public function my()
+    {
+        $data['user'] = Place::$user;
         return $data;
     }
 
@@ -85,6 +107,10 @@ class User extends Core
         if ($sex) {
             Place::$user['sex'] = $update['sex'] = $sex;
         }
+        $weixin = Dever::input('weixin');
+        if ($weixin) {
+            Place::$user['weixin'] = $update['weixin'] = $weixin;
+        }
         if ($update) {
             Dever::db('info', 'place_user')->update(Place::$uid, $update);
         }
@@ -129,15 +155,31 @@ class User extends Core
     # 我的下级列表
     public function getGroup()
     {
+        $data['parent'] = 2;
+        # 获取我的上级
+        $relation = Dever::load('relation', 'invite')->getParent(Place::$uid);
+        if ($relation) {
+            $data['parent'] = 1;
+            $data['parent_info'] = Dever::db('info', 'place_user')->find($relation['uid'], ['col' => 'id,name,avatar,cdate']);
+            if ($data['parent_info']) {
+                $data['parent_info']['cdate_str'] = date('Y-m-d H:i:s', $data['parent_info']['cdate']);
+            }
+        }
+
         $relation = Dever::load('relation', 'invite')->getChild(Place::$uid);
-        $result = [];
+        $data['list'] = [];
         if ($relation) {
             foreach ($relation as $k => $v) {
-                $result[$k] = Dever::db('info', 'place_user')->find($v['to_uid'], ['col' => 'id,name,avatar']);
-                $result[$k]['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
+                $data['list'][$k] = Dever::db('info', 'place_user')->find($v['to_uid'], ['col' => 'id,name,avatar,num_order']);
+                if ($data['list'][$k]) {
+                    $data['list'][$k]['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
+                    # 获取订单数
+                    $data['list'][$k]['order'] = $data['list'][$k]['num_order'] . '单';
+                }
             }
         }
-        return $result;
+        $data['page'] = Dever::page('total');
+        return $data;
     }
 
     # 填写邀请码,添加上级

+ 9 - 2
src/place/interface/lib/Core.php

@@ -27,7 +27,7 @@ class Core
         }
         if ($this->entry) {
             if (Place::$info['type'] >= 2 && !Place::$uid) {
-                Dever::error('您没有权限');
+                Dever::error('您没有权限', -2);
             }
             /*
             if (Place::$member && Place::$user['entry_type'] <= 2) {
@@ -38,11 +38,18 @@ class Core
 
     protected function showLogin()
     {
-        Dever::error('请先登录', -2);
+        Dever::error('请先登录', -4);
     }
 
+    # 获取要更新的数据版本号
     public function getUpdate()
     {
         return Place::$info['update'];
     }
+
+    # 获取要更新的系统版本号
+    public function getVersion()
+    {
+        return 100;
+    }
 }

+ 9 - 3
src/place/order/lib/Log.php

@@ -35,9 +35,15 @@ class Log
             $user = Dever::db('info', 'place_user')->find($info['uid']);
         } elseif ($info['utype'] == 2) {
             $user = Dever::db('user', 'sector')->find($info['uid']);
-        } elseif ($info['utype'] == 3) {
-            //$user = Dever::db('supplier', 'place')->find($info['uid']);
-            $user = Dever::db('user', 'sector')->find($info['uid']);
+        } elseif ($info['utype'] > 30) {
+            $type = $info['utype'] - 30;
+            $user = Dever::load('info', 'place_channel_market')->get($type, $info['uid']);
+        } elseif ($info['utype'] > 20) {
+            $type = $info['utype'] - 20;
+            $user = Dever::load('info', 'place_channel_supply')->get($type, $info['uid']);
+        } elseif ($info['utype'] > 10) {
+            $type = $info['utype'] - 10;
+            $user = Dever::load('info', 'place_channel_sales')->get($type, $info['uid']);
         } else {
             $user['name'] = $user['mobile'] = '-';
         }

+ 20 - 4
src/place/order/lib/Pay.php

@@ -21,6 +21,11 @@ class Pay
         $this->set = $set;
         $this->set['rebate'] = ['rule' => []];
         $this->order['cash'] = $this->order['num'] = 0;
+        $this->order['sales_type'] = $this->order['sales_id'] = 0;
+        if (Place::$info['sales_type'] && Place::$info['sales_id']) {
+            $this->order['sales_type'] = Place::$info['sales_type'];
+            $this->order['sales_id'] = Place::$info['sales_id'];
+        }
         foreach ($detail as $k => $v) {
             $this->getDetail($v);
         }
@@ -48,7 +53,7 @@ class Pay
         $this->user['gift'] = Dever::load('gift', 'place_user')->getUseList(Place::$uid, $this->detail, $this->set['score'], $gift_id, $gift_cash);
 
         # 获取地址
-        if (isset($this->order['deliver_type']) && $this->order['deliver_type'] == 1) {
+        if (isset($this->order['deliver_type']) && $this->order['deliver_type'] == 1 && $this->order['is_address'] == 1) {
             if ($address_id) {
                 $this->user['address'] = Dever::load('address', 'place_user')->getInfo($address_id, Place::$uid);
             } else {
@@ -210,6 +215,7 @@ class Pay
 
         $this->order['pay_cash'] = Dever::number($this->order['pay_cash']);
         $this->order['pay_money_cash'] = Dever::math('mul', $this->order['pay_cash'], $this->set['score']['exp']);
+        $this->order['money_cash'] = Dever::math('mul', $this->order['cash'], $this->set['score']['exp']);
     }
 
     # 下单
@@ -222,11 +228,11 @@ class Pay
         if (!$this->order) {
             Dever::error('订单不存在');
         }
-        $this->check();
-        
+        if ($this->order['num'] <= 0) {
+            Dever::error('下单失败,数量为0');
+        }
         $table = 'place_order/' . $this->type;
         $prefix = strtoupper(substr($this->type, 0, 2));
-
         $this->order['uid'] = Place::$uid;
         # 获取上级
         if (Place::$user['parent_uid'] && Place::$user['parent_uid'] > 0) {
@@ -236,6 +242,8 @@ class Pay
         $this->order['notify'] = $table . '/pay.notify|' . Dever::input('p') . '|' . $this->order['order_num'];
         $this->order['buy_info'] = Dever::input('remark');
 
+        $this->check();
+
         $result = [];
         if ($this->order['pay_money_cash'] > 0) {
             /*
@@ -265,6 +273,8 @@ class Pay
     public function success($order_id)
     {
         Dever::load($this->type . '/log', 'place_order')->up(1, $this->order['uid'], $order_id, '下单成功');
+        # 记录购买订单数
+        Dever::db('info', 'place_user')->update($this->order['uid'], ['num_order' => ['+', 1]]);
 
         $table = $this->type . '_detail';
         foreach ($this->detail as $v) {
@@ -277,8 +287,14 @@ class Pay
 
             # 记录明细
             $v['order_id'] = $order_id;
+            $v['promotion_id'] = $promotion['id'];
             $id = Dever::db($table, 'place_order')->insert($v);
 
+            # 记录销量
+            if (isset($v['source_id'])) {
+                Dever::db('info', 'place_source')->update($v['source_id'], ['num_sell' => ['+', 1]]);
+            }
+
             if ($id) {
                 # 记录促销
                 if ($promotion) {

+ 1 - 1
src/place/order/lib/Role/Pay.php

@@ -67,7 +67,7 @@ class Pay extends Core
             $detail = Dever::db('role_detail', 'place_order')->select(['order_id' => $order['id']], ['order' => 'level asc']);
             if ($detail) {
                 foreach ($detail as $v) {
-                    Dever::load('user', 'place_role')->up($order['uid'], $v['role_id'], $v['level_id']);
+                    Dever::load('user', 'place_role')->up($order['uid'], $v['role_id'], $v['level_id'], $order['sales_type'], $order['sales_id']);
                 }
             }
         }

+ 1 - 1
src/place/order/lib/Source/Cart.php

@@ -47,7 +47,7 @@ class Cart
             Dever::error('商品不存在');
         }
 
-        $stock = Dever::load('stock', 'place_source')->yue($data['source_id'], $data['sku_id']);
+        $stock = Dever::load('info', 'place_stock')->yue($data['source_id'], $data['sku_id']);
         if ($stock !== false && $num > $stock) {
             Dever::error('库存不足');
         }

+ 33 - 22
src/place/order/lib/Source/Delivery.php

@@ -3,26 +3,37 @@ use Dever;
 class Delivery
 {
     # 自动发货
-    public function up($id, $order_id, $detail_id, $delivery_type, $delivery_id, $content, $log = false)
+    public function up($order_id, $detail_id, $delivery_id, $content, $utype, $uid)
     {
-        $update['order_id'] = $order_id;
-        $update['delivery_id'] = $delivery_id;
-        $update['content'] = $content;
-        if ($id) {
-            $delivery = Dever::db('source_delivery_express', 'place_order')->find($id);
-            if ($delivery) {
-                Dever::db('source_delivery_express', 'place_order')->update($delivery['id'], $update);
-            }
+        $detail = Dever::db('source_detail', 'place_order')->find($detail_id);
+        if ($detail['order_id'] != $order_id) {
+            Dever::error('订单信息错误');
+        }
+        if ($detail['status'] != 1) {
+            Dever::error('订单信息错误');
+        }
+
+        if ($detail['source_type'] == 1) {
+            # 实物
+            $table = 'source_delivery_express';
         } else {
-            Dever::db('source_delivery_express', 'place_order')->insert($update);
-            Dever::db('source', 'place_order')->update($order_id, ['status' => 3, 'ddate' => time()]);
+            # 虚拟
+            $table = 'source_delivery_virtual';
         }
-        if ($log) {
-            $type = $log['type'];
-            $uid = $log['uid'];
-            $delivery_info = Dever::db('delivery', 'sector')->find($update['delivery_id']);
-            $msg = '已发货:' . $delivery_info['name'] . ',' . $update['content'];
-            Dever::load('source/log', 'place_order')->up($type, $uid, $order_id, $msg);
+        $state = Dever::db($table, 'place_order')->insert(['order_id' => $order_id, 'detail_id' => $detail_id, 'delivery_id' => $delivery_id, 'content' => $content]);
+        if ($state) {
+            $delivery_info = Dever::db('delivery', 'sector')->find($delivery_id);
+            if (!$content) {
+                $content = '无单号';
+            }
+            Dever::db('source_detail', 'place_order')->update(['id' => $detail_id], ['status' => 2, 'ddate' => time()]);
+            $state = Dever::db('source_detail', 'place_order')->find(['order_id' => $order_id, 'status' => 1]);
+            if (!$state) {
+                Dever::db('source', 'place_order')->update($order_id, ['status' => 3, 'ddate' => time()]);
+            }
+            $delivery = $delivery_info['name'] . ',' . $content;
+            $msg = '已发货:' . $delivery;
+            Dever::load('source/log', 'place_order')->up($utype, $uid, $order_id, $msg, false);
         }
     }
 
@@ -39,7 +50,7 @@ class Delivery
                 $type = 'virtual';
             }
             $info = Dever::db('source_delivery_' . $type, 'place_order')->find(['detail_id' => $v['id']]);
-            if ($info && $info['delivery_id'] && $info['content']) {
+            if ($info && $info['delivery_id']) {
                 $v['uid'] = $order['uid'];
                 $v['address_id'] = $order['address_id'];
                 $info = Dever::load('delivery', 'sector')->getInfo($v, $info, $v['source_type'], 1);
@@ -68,12 +79,12 @@ class Delivery
     }
 
     # 获取退货单发货信息
-    public function getRefundInfo($order)
+    public function getRefundInfo($refund)
     {
-        $info = Dever::db('source_refund_express', 'place_order')->find(['source_refund_id' => $order['id']]);
+        $info = Dever::db('source_refund_express', 'place_order')->find(['source_refund_id' => $refund['id']]);
         if ($info) {
-            $order['delivery'] = Dever::load('delivery', 'sector')->getInfo($order, $info, 1, 2);
+            $refund['delivery'] = Dever::load('delivery', 'sector')->getInfo($refund, $info, 1, 2);
         }
-        return $order;
+        return $refund;
     }
 }

+ 96 - 10
src/place/order/lib/Source/Order.php

@@ -3,9 +3,14 @@ use Dever;
 class Order
 {
     # 获取订单列表
-    public function getList($uid, $status = 0)
+    public function getList($uid, $status = 0, $sales_type = 0, $sales_id = 0)
     {
-        $where['uid'] = $uid;
+        if ($sales_type && $sales_id) {
+            $where['sales_type'] = $sales_type;
+            $where['sales_id'] = $sales_id;
+        } else {
+            $where['uid'] = $uid;
+        }
         if ($status > 0) {
             if ($status == 1) {
                 # 待付款
@@ -25,7 +30,7 @@ class Order
             }
         }
         $set['num'] = 10;
-        $set['col'] = 'id,status,cdate,score_id,num,refund_status,cash';
+        $set['col'] = 'id,status,cdate,score_id,num,refund_status,review_status,cash,method';
         $data = Dever::db('source', 'place_order')->select($where, $set);
         if ($data) {
             foreach ($data as &$v) {
@@ -61,7 +66,7 @@ class Order
     # 获取订单里每个商品
     public function getDetail($info)
     {
-        $result = Dever::db('source_detail', 'place_order')->select(['order_id' => $info['id']], ['col' => 'id,cash,status,name,sku_name,pic,num']);
+        $result = Dever::db('source_detail', 'place_order')->select(['order_id' => $info['id']], ['col' => 'id,cash,status,name,sku_name,pic,num,source_id,source_type']);
         if ($result) {
             foreach ($result as &$v) {
                 $v['cash_text'] = Dever::load('info', 'place_score')->getText($v['cash'], $info['score']);
@@ -78,9 +83,26 @@ class Order
             $info['score'] = Dever::load('info', 'place_score')->get($info['score_id']);
         }
         $info['status_name'] = Dever::db('source', 'place_order')->value('status', $info['status']);
+        if ($info['status'] < 3) {
+            $info['status_type'] = 'primary';
+        } elseif ($info['status'] < 5) {
+            $info['status_type'] = 'success';
+        } elseif ($info['status'] < 7) {
+            $info['status_type'] = 'info';
+        } else {
+            $info['status_type'] = 'info';
+        }
         if ($info['refund_status'] == 1) {
             $info['status_name'] = '退款申请中';
+            $info['status_type'] = 'error';
+        } elseif ($info['review_status'] == 2) {
+            $info['status_name'] = '待评价';
+            $info['status_type'] = 'warning';
+        } elseif ($info['method'] == 3 && $info['status'] <= 4) {
+            $info['status_name'] = '自提';
+            $info['method_code'] = substr($info['cdate'], -4);
         }
+        $info['method_name'] = Dever::db('source', 'place_order')->value('method', $info['method']);
         $info['cash_text'] = Dever::load('info', 'place_score')->getText($info['cash'], $info['score']);
 
         if (!$view) {
@@ -106,7 +128,7 @@ class Order
         if ($info['address_id']) {
             $info['address'] = Dever::load('address', 'place_user')->getInfo($info['address_id'], $info['uid']);
         }
-        $info['user'] = Dever::db('info', 'place_user')->find($info['uid']);
+        $info['user'] = Dever::db('info', 'place_user')->find($info['uid'], ['col' => 'id,name,mobile,avatar']);
         if (in_array($info['status'], [3,4,5,6])) {
             $info = Dever::load('source/delivery', 'place_order')->getSourceInfo($info);
         }
@@ -186,6 +208,18 @@ class Order
                 $this->getViewDate($refund);
                 if ($refund['status'] < 4 && !$info['refund']) {
                     $info['refund'] = $refund;
+                    if ($refund['address_id']) {
+                        if (strstr($refund['address_id'], '_')) {
+                            $temp = explode('_', $refund['address_id']);
+                            $address = Dever::load('info', 'place_channel_' . $temp[0])->get($temp[1], $temp[2]);
+                            $name = $address['name'] . ',' . $address['mobile'] . ',' . Dever::load('data', 'area')->string($address['area'], ',') . ',' . $address['address'];
+                            $info['refund']['address'] = $name;
+                        } else {
+                            $address = Dever::db('address', 'place')->find($refund['address_id']);
+                            $name = $address['name'] . ',' . $address['phone'] . ',' . Dever::load('data', 'area')->string($address['area'], ',') . ',' . $address['address'];
+                            $info['refund']['address'] = $name;
+                        }
+                    }
                 }
             }
         }
@@ -220,7 +254,7 @@ class Order
             $state = Dever::db('source', 'place_order')->update($order['id'], ['status' => $status, 'fdate' => time()]);
             if ($state) {
                 # 恢复库存
-                Dever::load('stock', 'place_source')->refundAll($order['id']);
+                Dever::load('info', 'place_stock')->refundAll($order);
             }
             return 'ok';
         }
@@ -242,20 +276,18 @@ class Order
         Dever::load('source/log', 'place_order')->up(1, $order['uid'], $data['order_id'], $msg);
         if ($state && $update['status'] == 7) {
             # 恢复库存
-            Dever::load('stock', 'place_source')->refundAll($order['id']);
+            Dever::load('info', 'place_stock')->refundAll($order);
         }
         return $state;
     }
 
     # 确认收货
     public function finish_commit(){}
-    public function finish($type = 1, $order, $yes = false)
+    public function finish($type = 1, $order, $yes = false, $uid = false)
     {
         if ($yes || ($order['status'] >= 3 && $order['status'] <= 4)) {
             if ($type == 1) {
                 $uid = $order['uid'];
-            } else {
-                $uid = '';
             }
             # 检查有没有退款
             $refund = Dever::db('source_refund', 'place_order')->select(['order_id' => $order['id'], 'status' => 4]);
@@ -274,6 +306,60 @@ class Order
                         Dever::load('log', 'place_score')->free($v['id']);
                     }
                 }
+
+                # 发放销售渠道收益
+                $this->sales($order);
+            }
+        }
+    }
+
+    private function sales($order)
+    {
+        # 发放销售渠道收益
+        if ($order['sales_type'] && $order['sales_id']) {
+            # 如果是平台发货,销售渠道将获取收益
+            $sales = Dever::load('info', 'place_channel_sales')->get($order['sales_type'], $order['sales_id']);
+            if ($sales && $sales['uid']) {
+                $benefit = Dever::db('sales', 'place_benefit')->find(['sales_cate_id' => $sales['cate_id'], 'status' => 1]);
+                if ($benefit && $benefit['score_id']) {
+                    if ($order['method'] == 1) {
+                        # 平台发货
+                        $table = 'sales_rebate_platform';
+                    } else {
+                        # 店铺发货
+                        $table = 'sales_rebate';
+                    }
+                    $rebate = Dever::db($table, 'place_benefit')->select(['sales_id' => $benefit['id']]);
+                    if ($rebate) {
+                        $detail = Dever::db('source_detail', 'place_order')->select(['order_id' => $order['id']]);
+                        $score = Dever::load('info', 'place_score')->get($order['score_id']);
+                        foreach ($rebate as $k => $v) {
+                            # 先检测购买人等级
+                            if ($v['role']) {
+                                $t = explode(',', $v['role']);
+                                $check = Dever::load('user', 'place_role')->check($order['uid'], $t[0], $t[1]);
+                                if (!$check) {
+                                    unset($rebate[$k]);
+                                    continue;
+                                }
+                            }
+                        }
+                        $value = 0;
+                        foreach ($detail as $k => $v) {
+                            if ($v['pay_cash'] > 0) {
+                                $v['pay_cash'] -= $v['refund_cash'];
+                                if ($v['pay_cash'] > 0) {
+                                    $money = Dever::math('mul', $v['pay_cash'], $score['exp']);
+                                    $value += Dever::load('item', 'place_benefit')->load('sales')->rebate($order['uid'], $v['scope'], $v['promotion_id'], $rebate, $money);
+                                }
+                            }
+                        }
+                        if ($value > 0) {
+                            # 给关联用户发收益
+                            Dever::load('log', 'place_score')->action('店铺收益', $benefit['score_id'])->add($sales['uid'], $sales['name'] . '订单:' . $order['order_num'], $value, 1, 'source_order_' . $order['id'], $order['sales_type'], $order['sales_id']);
+                        }
+                    }
+                }
             }
         }
     }

+ 28 - 8
src/place/order/lib/Source/Pay.php

@@ -41,15 +41,29 @@ class Pay extends Core
             'cash_text' => $detail['price_text'],
             'total_cash' => $detail['total_price'],
             'pay_cash' => $detail['total_price'],
-            'num' => $detail['buy_num'],
+            'num' => intval($detail['buy_num']),
             'unum' => $detail['unum'],
             'stock' => $detail['stock'],
             'promotion' => $detail['promotion'],
             'promotion_text' => $detail['promotion_text'],
         ];
         if ($source['type'] == 1) {
-            # 如果有快递发货
+            # 实物,如果有快递发货
             $this->order['deliver_type'] = 1;
+            # 0是销售渠道配送,1是平台配送
+            $this->order['method'] = 1;
+            # 1是需要填写地址,2是不需要
+            $this->order['is_address'] = 1;
+            if ($detail['stock'] && $detail['stock']['list'] && empty($this->order['method_list'])) {
+                # 如果有店铺配送
+                $this->order['method_list'] = $detail['stock']['list'];
+                $this->order['method'] = $detail['stock']['value'];
+                $this->order['is_address'] = $detail['stock']['address'];
+                if ($this->order['method'] == 0 && $this->order['is_address'] == 2) {
+                    # 自提,获取店铺地址
+                    $this->order['sales_address'] = Dever::load('info', 'place_channel_sales')->getInfo($this->order['sales_type'], $this->order['sales_id']);
+                }
+            }
         }
         $this->order['cash'] += $detail['price'] * $detail['buy_num'];
         $this->order['num'] += $detail['buy_num'];
@@ -58,22 +72,28 @@ class Pay extends Core
     # 验证库存
     protected function check()
     {
-        if (isset($this->order['deliver_type']) && $this->order['deliver_type'] == 1 && !$this->order['address_id']) {
+        if (isset($this->order['deliver_type']) && $this->order['deliver_type'] == 1 && $this->order['is_address'] == 1 && !$this->order['address_id']) {
             Dever::error('您还未填写收货地址');
         }
         foreach ($this->detail as $v) {
-            $stock = Dever::load('stock', 'place_source')->yue($v['source_id'], $v['sku_id']);
-            if ($stock >= 0) {
-                if ($stock < $v['num']) {
+            $stock = Dever::load('info', 'place_stock')->yue($v['source_id'], $v['sku_id']);
+            if ($stock['num'] >= 0) {
+                if ($stock['num'] < $v['num']) {
                     Dever::error($v['name'] . '[' . $v['sku_name'] . ']库存不足');
                 } else {
-                    $state = Dever::load('stock', 'place_source')->sell($v['source_id'], $v['sku_id'], $v['num']);
+                    $state = Dever::load('info', 'place_stock')->sell($this->order, $v['source_id'], $v['sku_id'], $v['num'], '订单号:' . $this->order['order_num']);
                     if (!$state) {
                         Dever::error('库存不足');
                     }
                 }
             }
         }
+        if ($this->order['method'] == 0) {
+            $this->order['method'] = 2;
+            if ($this->order['is_address'] == 2) {
+                $this->order['method'] = 3;
+            }
+        }
     }
 
     # 支付成功回调
@@ -96,7 +116,7 @@ class Pay extends Core
         }
         if ($state && $update['status'] == 7) {
             # 恢复库存
-            Dever::load('stock', 'place_source')->refundAll($order['id']);
+            Dever::load('info', 'place_stock')->refundAll($order);
         } elseif ($state && $update['status'] == 2) {
             # 自动发货
             //Dever::load('source/order', 'place_order')->finish(1, $order, true);

+ 70 - 5
src/place/order/lib/Source/Refund.php

@@ -2,6 +2,70 @@
 use Dever;
 class Refund
 {
+    # 前台审核
+    public function audit($id, $type, $info, $address_id, $utype, $uid)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($id);
+        if ($refund['status'] == 1) {
+            if ($type == 1) {
+                $refund['status'] = $update['status'] = 2;
+                $update['pdate'] = time();
+                $desc = '退款:审核通过';
+            } else {
+                $update['status'] = 5;
+                $update['pdate'] = time();
+                $update['fdate'] = time();
+                $desc = '退款:审核驳回';
+                Dever::db('source', 'place_order')->update($refund['order_id'], ['refund_status' => 2]);
+            }
+            $update['audit_desc'] = $info;
+            if ($address_id) {
+                $update['address_id'] = $address_id;
+            }
+            Dever::db('source_refund', 'place_order')->update($refund['id'], $update);
+            if ($update['audit_desc']) {
+                $desc .= '-' . $update['audit_desc'];
+            }
+            Dever::load('source/log', 'place_order')->up($utype, $uid, $refund['order_id'], $desc);
+            if ($refund['type'] == 2 && $refund['status'] == 2) {
+                # 仅退款
+                $order = Dever::db('source', 'place_order')->find($refund['order_id']);
+                $this->finish($order, $refund);
+            }
+        }
+        return 'ok';
+    }
+
+    # 前台审核退货
+    public function auditDelivery($id, $type, $info, $utype, $uid)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($id);
+        if ($refund['status'] == 3) {
+            if ($type == 1) {
+                $refund['status'] = $update['status'] = 3;
+                $update['delivery_pdate'] = time();
+                $desc = '退款:审核通过';
+            } else {
+                $update['status'] = 6;
+                $update['delivery_pdate'] = time();
+                $update['fdate'] = time();
+                $desc = '退款:审核驳回';
+                Dever::db('source', 'place_order')->update($refund['order_id'], ['refund_status' => 2]);
+            }
+            $update['delivery_audit_desc'] = $info;
+            Dever::db('source_refund', 'place_order')->update($refund['id'], $update);
+            if ($update['delivery_audit_desc']) {
+                $desc .= '-' . $update['delivery_audit_desc'];
+            }
+            Dever::load('source/log', 'place_order')->up($utype, $uid, $refund['order_id'], $desc);
+            if ($refund['status'] == 3) {
+                $order = Dever::db('source', 'place_order')->find($refund['order_id']);
+                $this->finish($order, $refund);
+            }
+        }
+        return 'ok';
+    }
+
     # 买家发货
     public function express($order, $refund_id, $delivery_id, $content)
     {
@@ -27,6 +91,10 @@ class Refund
     {
         $refund = Dever::db('source_refund', 'place_order')->find($refund['id']);
         if ($refund['status'] == 2 || $refund['status'] == 3) {
+
+            # 更新状态
+            Dever::db('source_refund', 'place_order')->update($refund['id'], ['status' => 4, 'fdate' => time()]);
+
             # 查找历史已退款金额
             $history = Dever::db('source_refund', 'place_order')->sum(['order_id' => $order['id'], 'status' => 4], 'cash');
 
@@ -36,7 +104,7 @@ class Refund
                 Dever::load('source/log', 'place_order')->up(1, $order['uid'], $order['id'], '订单已全额退款');
                 # 退货 恢复库存
                 if ($refund['type'] == 1) {
-                    Dever::load('stock', 'place_source')->refundAll($order['id']);
+                    Dever::load('info', 'place_stock')->refundAll($order);
                 }
             } else {
                 # 只退了一部分
@@ -47,7 +115,7 @@ class Refund
                         if ($v['num'] > 0 && $refund['type'] == 1) {
                             # 恢复库存
                             $detail = Dever::db('source_detail', 'place_order')->find($v['detail_id']);
-                            Dever::load('stock', 'place_source')->refund($detail['source_id'], $detail['sku_id'], $v['num']);
+                            Dever::load('info', 'place_stock')->refund($order, $detail['source_id'], $detail['sku_id'], $v['num']);
                         }
                     }
 
@@ -96,9 +164,6 @@ class Refund
                 Dever::load('source/log', 'place_order')->up(1, $order['uid'], $order['id'], '订单已部分退款');
             }
 
-            # 更新状态
-            Dever::db('source_refund', 'place_order')->update($refund['id'], ['status' => 4, 'fdate' => time()]);
-
             # 开始退款
             $cash = $this->getCash($order, $refund['cash'], $history);
 

+ 1 - 1
src/place/order/manage/Lib/Source/Address.php

@@ -21,7 +21,7 @@ class Address
         $update['phone'] = $phone;
         $update['type'] = 3;
         $update['area'] = $area;
-        list($update['province_id'], $update['city_id'], $update['county_id']) = explode(',', $update['area']);
+        list($update['province_id'], $update['city_id'], $update['county_id'], $update['town_id']) = explode(',', $update['area']);
         $update['address'] = $address;
         $address = [];
         if ($address_id) {

+ 18 - 8
src/place/order/manage/Lib/Source/Delivery.php

@@ -45,29 +45,39 @@ class Delivery
     public function update($db, $data)
     {
         $order = Dever::db('source', 'place_order')->find($data['order_id']);
-        if ($order && $order['status'] <= 3) {
+        if ($order && $order['status'] <= 4) {
             $express = Dever::db('source_delivery_express', 'place_order')->select(['order_id' => $data['order_id']]);
             $delivery = [];
             $detail_id = [];
             if ($express) {
                 foreach ($express as $k => $v) {
-                    $delivery_info = Dever::db('delivery', 'sector')->find($v['delivery_id']);
-                    $delivery[] = $delivery_info['name'] . ',' . $v['content'];
-                    $detail_id[] = $v['detail_id'];
+                    if ($v['delivery_id']) {
+                        $delivery_info = Dever::db('delivery', 'sector')->find($v['delivery_id']);
+                        if (!$v['content']) {
+                            $v['content'] = '无单号';
+                        }
+                        $delivery[] = $delivery_info['name'] . ',' . $v['content'];
+                        $detail_id[] = $v['detail_id'];
+                    }
                 }
             }
             $virtual = Dever::db('source_delivery_virtual', 'place_order')->select(['order_id' => $data['order_id']]);
             if ($virtual) {
                 foreach ($virtual as $k => $v) {
-                    $delivery_info = Dever::db('delivery', 'sector')->find($v['delivery_id']);
-                    $delivery[] = $delivery_info['name'] . ',' . $v['content'];
-                    $detail_id[] = $v['detail_id'];
+                    if ($v['delivery_id']) {
+                        $delivery_info = Dever::db('delivery', 'sector')->find($v['delivery_id']);
+                        $delivery[] = $delivery_info['name'] . ',' . $v['content'];
+                        $detail_id[] = $v['detail_id'];
+                    }
                 }
             }
             if ($delivery) {
                 $msg = '已发货:' . implode('、', $delivery);
-                Dever::db('source', 'place_order')->update($data['order_id'], ['status' => 3]);
                 Dever::db('source_detail', 'place_order')->update(['id' => ['in', $detail_id]], ['status' => 2, 'ddate' => time()]);
+                $state = Dever::db('source_detail', 'place_order')->find(['order_id' => $data['order_id'], 'status' => 1]);
+                if (!$state) {
+                    Dever::db('source', 'place_order')->update($data['order_id'], ['status' => 3, 'ddate' => time()]);
+                }
                 Dever::load('source/log', 'place_order')->up(2, Dever::$data['muser']['id'], $data['order_id'], $msg, $data['id']);
             } else {
                 Dever::error('发货失败,请检查重试');

+ 32 - 1
src/place/order/manage/Lib/Source/Info.php

@@ -46,9 +46,10 @@ class Info
             $score = Dever::load('info', 'place_score')->get($score_id);
             foreach ($detail as $v) {
                 $tip['content'] = [
-                    ['name' => '编号', 'content' => Dever::load('info', 'place_source')->getCode($v['id'])],
+                    ['name' => '编号', 'content' => Dever::load('info', 'place_source')->getCode($v['source_id'])],
                     ['name' => '名称', 'content' => $v['name']],
                     ['name' => '规格', 'content' => $v['sku_name']],
+                    //['name' => '编码', 'content' => $v['code']],
                     ['name' => '单价', 'content' => Dever::load('info', 'place_score')->getText($v['cash'], $score)],
                     ['name' => '数量', 'content' => $v['num']],
                 ];
@@ -82,4 +83,34 @@ class Info
         );
         return $result;
     }
+
+    # 根据资源编号获取资源id
+    public function getIdByCode($value)
+    {
+        $value = Dever::load('info', 'place_source')->getCode($value, false);
+        return $this->getSearch($value);
+        $info = Dever::db('info', 'place_source')->sql(['id' => $value], ['col' => 'id']);
+        return $this->getSearch($info);
+    }
+
+    # 根据资源编号获取资源id
+    public function getIdByName($value)
+    {
+        $info = Dever::db('info', 'place_source')->sql(['name' => ['like', $value]], ['col' => 'id']);
+        return $this->getSearch($info);
+    }
+
+    # 根据资源订单详情获取信息
+    public function getSearch($info)
+    {
+        if ($info) {
+            //$info = Dever::db('source_detail', 'place_order')->columns(['source_id' => ['in', $info]], 'order_id');
+            $info = Dever::db('source_detail', 'place_order')->sql(['source_id' => ['in', $info]], ['col' => 'order_id']);
+        }
+
+        if (!$info) {
+            $info = 'error';
+        }
+        return ['id', 'in', $info];
+    }
 }

+ 4 - 5
src/place/order/manage/Lib/Source/Pdf.php

@@ -2,9 +2,8 @@
 use Dever;
 class Pdf
 {
-    public function get($page)
+    public function get($result)
     {
-        $result = $page->info;
         $result['content'] = Dever::json_decode($result['content']);
         $button = [];
         $button[] = [
@@ -12,7 +11,7 @@ class Pdf
             'type' => 'fastedit',
             'path' => 'sector_place_order/pdf_edit',
             'row' => [
-                'id' => $page->info['id'],
+                'id' => $result['id'],
             ],
             # pdf内容字段名,仅pdf页面里有效
             'content' => 'content',
@@ -22,13 +21,13 @@ class Pdf
             'type' => 'fastedit',
             'path' => 'sector_place_order/pdf',
             'row' => [
-                'id' => $page->info['id'],
+                'id' => $result['id'],
             ],
         ];
         $button[] = [
             'name' => '预览原文件',
             'type' => 'link',
-            'param' => $page->info['file'],
+            'param' => $result['file'],
         ];
         return ['info' => $result, 'button' => $button, 'upload' => '9'];
     }

+ 56 - 1
src/place/order/manage/Lib/Source/Refund.php

@@ -2,7 +2,7 @@
 use Dever;
 class Refund
 {
-    # 后台提交
+    # 后台提交申请
     public function update($db, $data)
     {
         $detail = Dever::input('place_order/source_refund_detail');
@@ -31,6 +31,9 @@ class Refund
                 Dever::db('source', 'place_order')->update($refund['order_id'], ['refund_status' => 2]);
             }
             $update['audit_desc'] = $data['audit_desc'];
+            if (isset($data['address_id']) && $data['address_id']) {
+                $update['address_id'] = $data['address_id'];
+            }
             Dever::db('source_refund', 'place_order')->update($data['id'], $update);
             if ($update['audit_desc']) {
                 $desc .= '-' . $update['audit_desc'];
@@ -44,4 +47,56 @@ class Refund
         }
         return 'end';
     }
+
+    # 后台退货审核
+    public function auditDelivery($db, $data)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($data['id']);
+        if ($refund['status'] == 3) {
+            if ($data['audit'] == 1) {
+                $refund['status'] = $update['status'] = 3;
+                $update['delivery_pdate'] = time();
+                $desc = '退货:审核通过';
+            } else {
+                $update['status'] = 6;
+                $update['delivery_pdate'] = time();
+                $update['fdate'] = time();
+                $desc = '退货:审核驳回';
+                Dever::db('source', 'place_order')->update($refund['order_id'], ['refund_status' => 2]);
+            }
+            $update['delivery_audit_desc'] = $data['delivery_audit_desc'];
+            Dever::db('source_refund', 'place_order')->update($data['id'], $update);
+            if ($update['delivery_audit_desc']) {
+                $desc .= '-' . $update['delivery_audit_desc'];
+            }
+            Dever::load('source/log', 'place_order')->up(2, Dever::$data['muser']['id'], $refund['order_id'], $desc);
+            if ($refund['type'] == 2 && $refund['status'] == 2) {
+                $order = Dever::db('source', 'place_order')->find($refund['order_id']);
+                Dever::load('source/refund', 'place_order')->finish($order, $refund);
+            }
+        }
+        return 'end';
+    }
+
+    # 展示字段
+    public function show($type, $value)
+    {
+        return Dever::db('source_refund', 'place_order')->value($type, $value);
+    }
+
+    # 展示发货信息
+    public function showDelivery($id)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($id);
+        $info = Dever::load('source/delivery', 'place_order')->getRefundInfo($refund);
+        if ($info) {
+            $info['delivery']['name'] = '类型:' . $info['delivery']['name'];
+            if ($info['delivery']['content']) {
+                $info['delivery']['name'] .= '<br />单号:' . $info['delivery']['content'];
+            }
+            
+            return $info['delivery']['name'];
+        }
+        return '-';
+    }
 }

+ 78 - 20
src/place/order/manage/Lib/Source/View.php

@@ -6,10 +6,10 @@ class View
     private $user;
 
     # 后台详情页
-    public function get($page)
+    public function get($info)
     {
-        $page->info['detail'] = Dever::db('source_detail', 'place_order')->select(['order_id' => $page->info['id']]);
-        $this->info = Dever::load('source/order', 'place_order')->getView($page->info);
+        $info['detail'] = Dever::db('source_detail', 'place_order')->select(['order_id' => $info['id']]);
+        $this->info = Dever::load('source/order', 'place_order')->getView($info);
         $this->info['source_type'] = [];
         $tab = $this->getTab();
         return ['title' => '订单详情', 'info' => $this->getInfo(), 'tab' => $tab];
@@ -66,6 +66,8 @@ class View
     private function getView()
     {
         $content = [];
+        $sales = Dever::load('manage/info', 'place_channel_sales')->getInfo($this->info['sales_type'], $this->info['sales_id']);
+        $method = Dever::db('source', 'place_order')->value('method', $this->info['method']);
         $content[] = [
             'type' => 'list',
             'name' => '用户信息',
@@ -78,6 +80,14 @@ class View
                     'name' => '用户账户',
                     'content' => $this->info['user']['mobile'],
                 ],
+                [
+                    'name' => '渠道信息',
+                    'content' => $sales,
+                ],
+                [
+                    'name' => '发货方式',
+                    'content' => $method,
+                ],
             ],
         ];
 
@@ -482,9 +492,23 @@ class View
             $data['content']['content'][] = ['name' => '退款明细', 'content' => $refund['detail_str']];
         }
         if ($refund['status'] == 5) {
-            $data['content']['content'][] = ['name' => '驳回原因', 'content' => $refund['audit_desc']];
+            $data['content']['content'][] = ['name' => '申请驳回', 'content' => $refund['audit_desc']];
         } elseif ($refund['status'] >= 2) {
-            $data['content']['content'][] = ['name' => '审核备注', 'content' => $refund['audit_desc']];
+            $data['content']['content'][] = ['name' => '申请审核', 'content' => $refund['audit_desc']];
+        }
+        # 退货退款
+        if ($refund['type'] == 1 && $refund['status'] >= 3) {
+            $refund = Dever::load('source/delivery', 'place_order')->getRefundInfo($refund);
+            if (isset($refund['delivery']['name']) && $refund['delivery']['name']) {
+                $data['content']['content'][] = ['name' => '发货类型', 'content' => $refund['delivery']['name']];
+                $data['content']['content'][] = ['name' => '发货内容', 'content' => $refund['delivery']['content']];
+            }
+            if (isset($refund['delivery']['log']) && $refund['delivery']['log']) {
+                $data['content']['content'][] = ['name' => '快递信息', 'content' => $refund['delivery']['log']];
+            }
+        }
+        if ($refund['status'] == 6) {
+            $data['content']['content'][] = ['name' => '退货驳回', 'content' => $refund['delivery_audit_desc']];
         }
         $result = [0 => $data];
         return $result;
@@ -629,24 +653,30 @@ class View
                 ];*/
             }
 
-            if ($this->info['refund_status'] == 2 && (isset($this->info['source_type'][1]) || isset($this->info['source_type'][2]))) {
-                $button[] = [
-                    'name' => '手动发货',
-                    'type' => 'fastadd',
-                    'path' => 'sector_place_order/source_delivery',
-                    # row必填,这里的按钮来自于列表页,需要依赖哪一行。这里就写id就行,后续优化这里吧
-                    'row' => [],
-                    'param' => [
-                        'order_id' => $this->info['id'],
-                    ],
-                    # 弹窗宽度
-                    'width' => '60%',
-                ];
+            if ($this->info['method'] <= 2) {
+                $name = '平台发货';
+                if ($this->info['method'] == 2) {
+                    $name = '店铺发货';
+                }
+                if ($this->info['refund_status'] == 2 && (isset($this->info['source_type'][1]) || isset($this->info['source_type'][2]))) {
+                    $button[] = [
+                        'name' => $name,
+                        'type' => 'fastadd',
+                        'path' => 'sector_place_order/source_delivery',
+                        # row必填,这里的按钮来自于列表页,需要依赖哪一行。这里就写id就行,后续优化这里吧
+                        'row' => [],
+                        'param' => [
+                            'order_id' => $this->info['id'],
+                        ],
+                        # 弹窗宽度
+                        'width' => '60%',
+                    ];
+                }
             }
-        } elseif ($this->info['status'] == 3 && isset($this->info['delivery']) && $info['delivery']['edit']) {
+        } elseif ($this->info['status'] == 3 && isset($this->info['delivery_edit']) && $this->info['delivery_edit']) {
             # 已发货,修改发货信息
             $button[] = [
-                'name' => '修改收货信息',
+                'name' => '修改货信息',
                 'type' => 'fastadd',
                 'path' => 'sector_place_order/source_delivery',
                 # row必填,这里的按钮来自于列表页,需要依赖哪一行。这里就写id就行,后续优化这里吧
@@ -658,6 +688,21 @@ class View
                 'width' => '60%',
             ];
         } elseif ($this->info['status'] == 3 || $this->info['status'] == 4) {
+
+            if (isset($this->info['delivery_show']) && $this->info['delivery_show']) {
+                    $button[] = [
+                    'name' => '查看发货信息',
+                    'type' => 'fastadd',
+                    'path' => 'sector_place_order/source_delivery',
+                    # row必填,这里的按钮来自于列表页,需要依赖哪一行。这里就写id就行,后续优化这里吧
+                    'row' => [],
+                    'param' => [
+                        'order_id' => $this->info['id'],
+                    ],
+                    # 弹窗宽度
+                    'width' => '60%',
+                ];
+            }
             /*
             $button[] = [
                 'name' => '确认收货',
@@ -701,6 +746,19 @@ class View
                 ],
             ];
         }
+        if ($this->info['refund'] && $this->info['refund']['status'] == 3) {
+            $button[] = [
+                'name' => '退货审核',
+                'type' => 'fastedit',
+                'path' => 'sector_place_order/source_refund_audit_delivery',
+                'row' => [
+                    'id' => $this->info['refund']['id'],
+                ],
+                'param' => [
+                    'order_id' => $this->info['id'],
+                ],
+            ];
+        }
         return $button;
     }
 }

+ 8 - 0
src/place/order/manage/core.php

@@ -77,6 +77,14 @@ return [
             'show'      => 3,
         ],
 
+        'source_refund_audit_delivery' => [
+            'parent'    => 'sector_place_order',
+            'name'      => '订单退货审核',
+            'icon'      => 'product-hunt-line',
+            'sort'      => '10',
+            'show'      => 3,
+        ],
+
         'role' => [
             'parent'    => 'sector_place_order',
             'name'      => '角色订单',

+ 1 - 4
src/place/order/manage/role.php

@@ -3,10 +3,7 @@ $config = [
     'list' => [
         'field'      => [
             'order_num',
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
-            ],
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
             'score_id',
             'cash',
             'wallet_cash',

+ 18 - 7
src/place/order/manage/source.php

@@ -16,9 +16,13 @@ $config = [
                 'tag' => true,
                 'show' => 'Dever::call("place_order/manage/source/info.getDetail", [{id}, {score_id}])',
             ],
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
+            'sales' => [
+                'name' => '渠道信息',
+                'show' => 'Dever::call("place_channel_sales/manage/info.getInfo", [{sales_type}, {sales_id}])',
+            ],
+            'method' => [
+                
             ],
             //'score_id',
             'cash' => [
@@ -61,18 +65,25 @@ $config = [
                 'type' => 'select_text',
                 'option' => [
                     ['id' => 1, 'name' => '订单号', 'value' => 'order_num'],
-                    ['id' => 2, 'name' => '资源编号', 'value' => 'place_source/info.getIdByCode'],
-                    ['id' => 3, 'name' => '资源名称', 'value' => 'place_source/info.getIdByName'],
+                    ['id' => 2, 'name' => '资源编号', 'value' => 'place_order/manage/source/info.getIdByCode'],
+                    ['id' => 3, 'name' => '资源名称', 'value' => 'place_order/manage/source/info.getIdByName'],
                     ['id' => 4, 'name' => '用户ID', 'value' => 'uid'],
-                    ['id' => 5, 'name' => '用户名', 'value' => 'place_user/manage/user.getUidByName'],
+                    ['id' => 5, 'name' => '用户名', 'value' => 'place_user/manage/user.getUidByName'],
                     ['id' => 6, 'name' => '用户电话', 'value' => 'place_user/manage/user.getUidByMobile'],
                     ['id' => 7, 'name' => '上级用户ID', 'value' => 'parent_uid'],
-                    ['id' => 8, 'name' => '上级用户名', 'value' => 'place_user/manage/user.getParentUidByName'],
+                    ['id' => 8, 'name' => '上级用户名', 'value' => 'place_user/manage/user.getParentUidByName'],
                     ['id' => 9, 'name' => '上级用户电话', 'value' => 'place_user/manage/user.getParentUidByMobile'],
                     ['id' => 10, 'name' => '收货人姓名', 'value' => 'place_user/manage/user.getUidByAddName'],
                     ['id' => 11, 'name' => '收货人电话', 'value' => 'place_user/manage/user.getUidByAddMobile'],
                 ],
             ),
+            'sales' => [
+                'type' => 'select2',
+                'name' => '渠道',
+                'option' => 'Dever::call("place_channel_sales/manage/info.getList")',
+                'col' => 'sales_type,sales_id',
+            ],
+            'method',
             //'order_num',
             //'uid',
             //'name' => 'like',

+ 2 - 2
src/place/order/manage/source_delivery_express.php

@@ -1,7 +1,7 @@
 <?php
 return [
     'update' => [
-        'start' => 'place_order/manage/source/delivery.updateExpress',
+        //'start' => 'place_order/manage/source/delivery.updateExpress',
         'field'    => [
             'id' => 'hidden',
             'name' => [
@@ -12,7 +12,7 @@ return [
                 'type' => 'hidden',
             ],
             'delivery_id' => [
-                
+                'tip' => '选择自提无需填写单号',
             ],
             'content' => [
                 'type' => 'textarea',

+ 20 - 0
src/place/order/manage/source_refund_audit.php

@@ -1,9 +1,18 @@
 <?php
+
 $config = [
     'source' => 'place_order/source_refund',
     'update' => [
         'start' => 'place_order/manage/source/refund.audit',
         'field'    => [
+            'type' => [
+                'type' => 'show',
+                'default' => 'Dever::call("place_order/manage/source/refund.show", ["type", "{type}"])',
+            ],
+            'desc_type' => [
+                'type' => 'show',
+                'default' => 'Dever::call("place_order/manage/source/refund.show", ["desc_type", "{desc_type}"])',
+            ],
             'audit' => [
                 'name' => '退款审核',
                 'rules' => true,
@@ -23,5 +32,16 @@ $config = [
         ],
     ],
 ];
+$id = Dever::input('id');
+if ($id) {
+    $info = Dever::db('source_refund', 'place_order')->find($id);
+    if ($info && $info['type'] == 1) {
+        $config['update']['field']['address_id'] = [
+            'type' => 'select',
+            'rules' => true,
+            'option' => 'Dever::call("place/address.getList")',
+        ];
+    }
+}
 
 return $config;

+ 40 - 0
src/place/order/manage/source_refund_audit_delivery.php

@@ -0,0 +1,40 @@
+<?php
+
+$config = [
+    'source' => 'place_order/source_refund',
+    'update' => [
+        'start' => 'place_order/manage/source/refund.auditDelivery',
+        'field'    => [
+            'type' => [
+                'type' => 'show',
+                'default' => 'Dever::call("place_order/manage/source/refund.show", ["type", "{type}"])',
+            ],
+            'desc_type' => [
+                'type' => 'show',
+                'default' => 'Dever::call("place_order/manage/source/refund.show", ["desc_type", "{desc_type}"])',
+            ],
+            'info' => [
+                'type' => 'show',
+                'name' => '退货信息',
+                'default' => 'Dever::call("place_order/manage/source/refund.showDelivery", ["{id}"])',
+            ],
+            'audit' => [
+                'name' => '退货审核',
+                'rules' => true,
+                'type' => 'radio',
+                'option' => [
+                    1 => '审核通过',
+                    2 => '审核驳回',
+                ],
+                'default' => 1,
+            ],
+            'delivery_audit_desc' => [
+                'name' => '审核备注',
+                //'rules' => true,
+                'type' => 'textarea',
+                'autosize' => ['minRows' => 2],
+            ],
+        ],
+    ],
+];
+return $config;

+ 2 - 2
src/place/order/table/rebate.php

@@ -16,12 +16,12 @@ return [
 
         'rebate_id'       => [
             'type'      => 'int(11)',
-            'name'      => '促销',
+            'name'      => '返利',
         ],
 
         'rebate_rule_id'       => [
             'type'      => 'int(11)',
-            'name'      => '促销规则',
+            'name'      => '返利规则',
         ],
 
         'name'      => [

+ 17 - 1
src/place/order/table/role.php

@@ -8,6 +8,17 @@ return [
             'name'      => '用户ID',
         ],
 
+        'sales_type' => [
+            'name'      => '销售类型',
+            'type'      => 'tinyint(1)',
+            'value'    => 'Dever::call("place_channel_sales/info.getType")',
+        ],
+
+        'sales_id' => [
+            'name'      => '销售ID',
+            'type'      => 'int(11)',
+        ],
+
         'parent_uid' => [
             'name'      => '上级',
             'type'      => 'int(11)',
@@ -32,7 +43,12 @@ return [
 
         'cash'      => [
             'type'      => 'decimal(11,2)',
-            'name'      => '总积分',
+            'name'      => '总金额',
+        ],
+
+        'money_cash'      => [
+            'type'      => 'decimal(11,2)',
+            'name'      => '货币总金额',
         ],
 
         'num'      => [

+ 5 - 0
src/place/order/table/role_detail.php

@@ -23,6 +23,11 @@ return [
             'name'      => '订单ID',
         ],
 
+        'promotion_id'       => [
+            'type'      => 'int(11)',
+            'name'      => '促销ID',
+        ],
+
         'scope'      => [
             'type'      => 'varchar(50)',
             'name'      => '范围',

+ 32 - 2
src/place/order/table/source.php

@@ -14,8 +14,19 @@ return [
             'name'      => '用户ID',
         ],
 
+        'sales_type' => [
+            'name'      => '销售类型',
+            'type'      => 'tinyint(1)',
+            'value'    => 'Dever::call("place_channel_sales/info.getType")',
+        ],
+
+        'sales_id' => [
+            'name'      => '销售ID',
+            'type'      => 'int(11)',
+        ],
+
         'parent_uid' => [
-            'name'      => '上级',
+            'name'      => '推荐人',
             'type'      => 'int(11)',
         ],
 
@@ -46,6 +57,11 @@ return [
             'name'      => '总金额',
         ],
 
+        'money_cash'      => [
+            'type'      => 'decimal(11,2)',
+            'name'      => '货币总金额',
+        ],
+
         'pay_cash'      => [
             'type'      => 'decimal(11,2)',
             'name'      => '支付金额',
@@ -137,6 +153,17 @@ return [
             ],
         ],
 
+        # 1是平台发货,2是店铺发货,3是店铺自提,其中1和2、3分账方式不同,支付形式也应该不同
+        'method' => [
+            'name'      => '发货方式',
+            'type'      => 'tinyint(1)',
+            'default'   => '1',
+            'value'         => [
+                1 => '平台发货',
+                2 => '店铺发货',
+                3 => '店铺自提',
+            ],
+        ],
         'status'        => [
             'type'      => 'tinyint(1)',
             'name'      => '订单状态',
@@ -176,6 +203,9 @@ return [
     ],
 
     'index' => [
-        'search' => 'uid,order_num',
+        'order_num' => 'order_num',
+        'search' => 'uid,status',
+        'review_status' => 'uid,review_status',
+        'sales' => 'sales_type,sales_id,status',
     ],
 ];

+ 5 - 0
src/place/order/table/source_detail.php

@@ -23,6 +23,11 @@ return [
             'name'      => '订单ID',
         ],
 
+        'promotion_id'       => [
+            'type'      => 'int(11)',
+            'name'      => '促销ID',
+        ],
+
         'scope'      => [
             'type'      => 'varchar(50)',
             'name'      => '范围',

+ 10 - 3
src/place/order/table/source_log.php

@@ -14,9 +14,16 @@ return [
             'default'   => 1,
             'value'     => [
                 -1 => '系统',
-                1 => '买家',
-                2 => '卖家',
-                3 => '渠道',
+                1 => '用户',
+                2 => '平台',
+                # 销售渠道
+                11 => '实体店',
+                12 => '网店',
+                13 => '自媒体',
+                14 => '经销商',
+                # 进货渠道
+
+                # 营销渠道
             ],
         ],
 

+ 27 - 4
src/place/order/table/source_refund.php

@@ -9,9 +9,16 @@ return [
             'default'   => 1,
             'value'     => [
                 -1 => '系统',
-                1 => '买家',
-                2 => '卖家',
-                3 => '渠道',
+                1 => '用户',
+                2 => '平台',
+                # 销售渠道
+                11 => '实体店',
+                12 => '网店',
+                13 => '自媒体',
+                14 => '经销商',
+                # 进货渠道
+
+                # 营销渠道
             ],
         ],
 
@@ -40,6 +47,11 @@ return [
             'name'      => '审核备注',
         ],
 
+        'delivery_audit_desc'      => [
+            'type'      => 'varchar(200)',
+            'name'      => '退货审核备注',
+        ],
+
         'type' => [
             'name'      => '退款类型',
             'type'      => 'tinyint(1)',
@@ -85,10 +97,16 @@ return [
                 2 => '已审核',
                 3 => '已退货',
                 4 => '已退款',
-                5 => '已驳回',
+                5 => '审核驳回',
+                6 => '退货驳回',
             ],
         ],
 
+        'address_id'       => [
+            'type'      => 'varchar(20)',
+            'name'      => '退款地址',
+        ],
+
         'pdate'       => [
             'type'      => 'int(11)',
             'name'      => '审核时间',
@@ -99,6 +117,11 @@ return [
             'name'      => '发货时间',
         ],
 
+        'delivery_pdate'       => [
+            'type'      => 'int(11)',
+            'name'      => '退货审核时间',
+        ],
+
         'fdate'       => [
             'type'      => 'int(11)',
             'name'      => '完成时间',

+ 4 - 0
src/place/page/lib/Ad.php

@@ -23,6 +23,10 @@ class Ad
         31 => 'focus',
         32 => 'info',
         33 => 'alert',
+
+        41 => 'focus',
+        42 => 'info',
+        43 => 'alert',
     ];
     public function gets($location, $channel_id, $cate_id = false)
     {

+ 1 - 1
src/place/page/manage/ad.php

@@ -84,7 +84,7 @@ return [
                 'type' => 'radio',
             ],
             'location' => [
-                'type' => 'radio',
+                'type' => 'select',
             ],
             'type' => [
                 'type' => 'radio',

+ 1 - 1
src/place/page/manage/nav.php

@@ -24,7 +24,7 @@ return [
         'end' => 'place_page/manage/nav.update',
         'control' => [
             'type_id' => [
-                'type' => 10,
+                'type' => [10,11],
             ],
         ],
 

+ 4 - 0
src/place/page/table/ad.php

@@ -42,6 +42,10 @@ return [
                 31 => '内容页轮播',
                 32 => '内容页信息流',
                 //33 => '内容页弹窗',
+
+                41 => '搜索页轮播',
+                //42 => '搜索页信息流',
+                //43 => '搜索页弹窗',
             ],
         ],
         'type' => [

+ 2 - 1
src/place/page/table/nav.php

@@ -19,7 +19,8 @@ return [
             'value'     => [
                 1 => '个人中心',
                 2 => '已购列表',
-                10 => '资源频道',
+                10 => '频道首页',
+                11 => '频道分类',
             ],
         ],
         'type_id' => [

+ 2 - 2
src/place/role/lib/Info.php

@@ -3,12 +3,12 @@ use Dever;
 class Info
 {
     # 默认初始等级
-    public function up($uid)
+    public function up($uid, $sales_type = 0, $sales_id = 0)
     {
         $level = Dever::db('level', 'place_role')->select(['type' => 2, 'status' => 1]);
         if ($level) {
             foreach ($level as $v) {
-                Dever::load('user', 'place_role')->up($uid, $v['info_id'], $v);
+                Dever::load('user', 'place_role')->up($uid, $v['info_id'], $v, $sales_type, $sales_id);
             }
         }
     }

+ 16 - 1
src/place/role/lib/User.php

@@ -3,6 +3,19 @@ use Dever;
 use Place;
 class User
 {
+    # 检测是否开通相关角色
+    public function check($uid, $info_id, $level_id)
+    {
+        $info = Dever::db('user', 'place_role')->find(['uid' => $uid, 'info_id' => $info_id, 'level_id' => $level_id, 'status' => 1]);
+        if ($info) {
+            if ($info['edate'] > time()) {
+                return true;
+            }
+            Dever::db('role', 'place_user')->update($info['id'], ['status' => 2]);
+        }
+        return false;
+    }
+
     public function getInfo($id)
     {
         $user = [
@@ -73,7 +86,7 @@ class User
     }
 
     # 更新账户信息
-    public function up($uid, $role_id, $info)
+    public function up($uid, $role_id, $info, $sales_type = 0, $sales_id = 0)
     {
         $data = ['uid' => $uid, 'info_id' => $role_id];
         $user = Dever::db('user', 'place_role')->find($data);
@@ -81,6 +94,8 @@ class User
             $info = Dever::db('level', 'place_role')->find($info);
         }
         if ($info) {
+            $data['sales_type'] = $sales_type;
+            $data['sales_id'] = $sales_id;
             $data['level_id'] = $info['id'];
             if ($info['day'] < 0) {
                 $info['day'] = 3650;

+ 14 - 0
src/place/role/manage/Lib/Data.php

@@ -15,4 +15,18 @@ class Data
         }
         return $result;
     }
+
+    public function getOption()
+    {
+        $result = [];
+        $set = ['col' => 'id,name'];
+        $role = Dever::db('info', 'place_role')->select(['status' => 1], $set);
+        foreach ($role as $k => $v) {
+            $v['children'] = Dever::db('level', 'place_role')->select(['info_id' => $v['id'], 'status' => 1], ['col' => 'id,name']);
+            if ($v['children']) {
+                $result[] = $v;
+            }
+        }
+        return $result;
+    }
 }

+ 3 - 0
src/place/role/manage/level.php

@@ -63,6 +63,9 @@ return [
             'type' => [
                 'type' => 'radio',
                 'rules' => true,
+                'tip' => '支付:需要在前台支付购买
+                <br />注册赠送:用户注册后自动获得该等级
+                <br />手动赠送:可以后台手动赠送',
             ],
             'pay' => [
                 'type' => 'radio',

+ 1 - 4
src/place/role/manage/user_role.php

@@ -3,10 +3,7 @@ return [
     'source' => 'place_role/user',
     'list' => [
         'field'      => [
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
-            ],
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
             'info_id',
             'level_id',
             'card' => [

+ 2 - 1
src/place/role/table/level.php

@@ -60,6 +60,7 @@ return [
                 2 => '注册赠送',
                 //3 => '邀请人数',
                 //4 => '消费金额',
+                10 => '手动赠送',
             ],
         ],
 
@@ -94,7 +95,7 @@ return [
         ],
 
         'status' => [
-            'name'      => '等级状态',
+            'name'      => '状态',
             'type'      => 'tinyint(1)',
             'default'   => 1,
             'value'     => [

+ 12 - 1
src/place/role/table/user.php

@@ -7,6 +7,16 @@ return [
             'type'      => 'int(11)',
             'name'      => '用户ID',
         ],
+        'sales_type' => [
+            'name'      => '销售类型',
+            'type'      => 'tinyint(1)',
+            'value'    => 'Dever::call("place_channel_sales/info.getType")',
+        ],
+
+        'sales_id' => [
+            'name'      => '销售ID',
+            'type'      => 'int(11)',
+        ],
         'info_id'        => [
             'name'      => '角色',
             'type'      => 'int(11)',
@@ -39,6 +49,7 @@ return [
         ],
     ],
     'index' => [
-        'search' => 'uid,info_id,level_id,card',
+        'search' => 'uid,info_id,level_id,card,status',
+        'sales' => 'sales_type,sales_id,info_id,status',
     ],
 ];

+ 47 - 6
src/place/score/lib/Log.php

@@ -14,7 +14,7 @@ class Log
         Dever::load('log', 'place_score')->action('购买/充值/提现/兑换', $score_id)->add($uid, '干了什么', 100);
     */
     public function add_commit(){}
-    public function add($uid, $desc = '', $num = 0, $status = 1, $relation = '')
+    public function add($uid, $desc = '', $num = 0, $status = 1, $relation = '', $sales_type = 0, $sales_id = 0)
     {
         $this->uid = $uid;
         $this->status = $status;
@@ -24,7 +24,7 @@ class Log
         if ($this->score_id && $num != 0) {
             # 积分记录
             # 这里以后增加:按照num的数量来控制增加其他积分,比如消费100元送1金币
-            return $this->up($this->score_id, $num, $desc, $relation);
+            return $this->up($this->score_id, $num, $desc, $relation, $sales_type, $sales_id);
         }
 
         # 规则操作
@@ -87,14 +87,16 @@ class Log
     public function getList($uid, $info_id, $action = '', $type = false)
     {
         $where['uid'] = $uid;
-        $where['info_id'] = $info_id;
+        if ($info_id > 0) {
+            $where['info_id'] = $info_id;
+        }
         if ($action) {
             $where['action_id'] = Dever::load('action', 'place_score')->get($action, 2);
         }
-        if ($type) {
+        if ($type > 0) {
             $where['type'] = $type;
         }
-        $result = Dever::db('user_log', 'place_score')->select($where, ['num' => 10, 'col' => 'id,type,amount,balance,`desc`,action_id,cdate']);
+        $result = Dever::db('user_log', 'place_score')->select($where, ['num' => 10, 'col' => 'id,info_id,type,amount,balance,`desc`,action_id,cdate']);
         if ($result) {
             foreach ($result as &$v) {
                 $v['cdate'] = date('Y-m-d H:i:s', $v['cdate']);
@@ -106,11 +108,44 @@ class Log
                         $v['action_name'] .= ' - [待审核]';
                     }
                 }
+                if ($info_id < 0) {
+                    $v['amount'] = Dever::load('info', 'place_score')->getText($v['amount'], $v['info_id']);
+                }
             }
         }
         return $result;
     }
 
+    # 获取金额总额说明
+    public function getCash($uid, $action = '')
+    {
+        $where['uid'] = $uid;
+        if ($action) {
+            $action_id = Dever::load('action', 'place_score')->get($action, 2);
+        }
+        $info = Dever::db('info', 'place_score')->select(['status' => 1]);
+        $result = [];
+        if ($info) {
+            foreach ($info as $k => $v) {
+                $where['info_id'] = $v['id'];
+                if ($action) {
+                    $where['action_id'] = $action_id;
+                }
+                $where['type'] = 1;
+                $amount = Dever::db('user_log', 'place_score')->sum($where, 'amount');
+                if ($amount > 0) {
+                    $amount = Dever::load('info', 'place_score')->getText($amount, $v);
+                    $result[] = $amount;
+                }
+            }
+        }
+        
+        if ($result) {
+            return '共获得' . implode('、', $result);
+        }
+        return '暂无数据';
+    }
+
     # 获取某个用户的日志统计数据
     public function getData($uid, $info_id, $action = '', $status = 1)
     {
@@ -173,7 +208,7 @@ class Log
     }
 
     # 增加积分
-    private function up($info_id, $amount, $desc = '', $relation = '')
+    private function up($info_id, $amount, $desc = '', $relation = '', $sales_type = 0, $sales_id = 0)
     {
         if ($amount == 0) {
             return ['id' => 0];
@@ -205,6 +240,12 @@ class Log
         $data['id'] = Dever::db('user_log', 'place_score')->insert($data);
         if ($data['id']) {
             Dever::load('user', 'place_score')->up($user['id'], $data['amount'], $this->status);
+            # 记录销售的收益
+            if ($sales_type && $sales_id && $data['amount'] > 0) {
+                $score = Dever::load('info', 'place_score')->get($info_id);
+                $money = Dever::load('info', 'place_score')->toMoney($data['amount'], $score['exp']);
+                Dever::load('profit', 'place_channel_sales')->up($data['uid'], $data['user_id'], $data['id'], $data['info_id'], $data['action_id'], $sales_type, $sales_id, $data['amount'], $money);
+            }
         }
         return $data;
     }

+ 2 - 5
src/place/score/lib/User.php

@@ -34,11 +34,8 @@ class User
         $user = Dever::db('user', 'place_score')->find($data);
 
         if (!$user) {
-            $user = [];
-            $user['id'] = Dever::db('user', 'place_score')->insert($data);
-            $user['balance'] = 0;
-            $user['udate'] = 0;
-            $user['status'] = 1;
+            Dever::db('user', 'place_score')->insert($data);
+            $user = $this->get($uid, $info_id);
         }
         return $user;
     }

+ 1 - 4
src/place/score/manage/user_score.php

@@ -3,10 +3,7 @@ return [
     'source' => 'place_score/user',
     'list' => [
         'field'      => [
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
-            ],
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
             'info_id',
             'total',
             'used',

+ 1 - 4
src/place/score/manage/user_withdraw.php

@@ -2,10 +2,7 @@
 return [
     'list' => [
         'field'      => [
-            'uid' => [
-                'name' => '用户信息',
-                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
-            ],
+            'uid' => Dever::call('place_user/manage/user.getInfo'),
             'info_id',
             'type',
             'realname',

+ 1 - 1
src/place/score/table/user_log.php

@@ -64,7 +64,7 @@ return [
     ],
 
     'index' => [
-        'search' => 'uid,info_id,action_id',
+        'search' => 'uid,info_id,action_id,type',
         'relation' => 'relation',
     ],
 ];

+ 8 - 27
src/place/set/api/Tool.php

@@ -1,6 +1,5 @@
 <?php namespace Place\Api;
 use Dever;
-use Place;
 class Tool
 {
     # 根据身份码获取入口
@@ -14,38 +13,20 @@ class Tool
         if (!$code) {
             Dever::error('身份码错误');
         }
-        $entry = Place::entry($code['sector_id'], $code['module_id'], $code['user_id'], $code['place_id']);
-        return $entry;
+        $result = Dever::load('info', 'place')->encode($code['sector_id'], $code['user_id'], $code['place_id']);
+        return $result;
     }
 
     public function url()
     {
         $id = Dever::input('id');
-        $info = Dever::db('info', 'place')->find($id);
-        if ($info) {
-            $extend = Dever::load('common', 'manage')->extend();
-            $entry = Place::entry($extend['info_id'], $extend['module_id'], $extend['data_id'], $id);
-            $url = 'http://localhost:8080/#/?p=' . $entry;
-            header('location:' . $url);
-
-            /*
-            $extend = Dever::load('common', 'manage')->extend();
-            $param['p'] = Place::entry($extend['info_id'], $extend['module_id'], $extend['data_id'], $id);
-            $link = str_replace('https://ct.yuandaibao.com/src/place/interface/', 'https://api.work.yuandaibao.com/', Dever::url('place_interface/main.home', $param));
-            header('HTTP/1.1 301 Moved Permanently');
-            header('Location: ' . $link);
-            */
-        }
+        $sales_type = Dever::input('sales_type');
+        $sales_id = Dever::input('sales_id');
+        $result = Dever::load('info', 'place')->share($id, $sales_type, $sales_id, 0, true);
+        header('HTTP/1.1 301 Moved Permanently');
+        header('location:' . $result['url']);
     }
-
-    # 根据身份码获取入口
-    public function go()
-    {
-        $entry = $this->code();
-        $url = 'http://localhost:8080/#/?p=' . $entry;
-        header('location:' . $url);
-    }
-
+    
     # 测试链接先知控制器回调
     public function call()
     {

+ 17 - 0
src/place/set/lib/Address.php

@@ -0,0 +1,17 @@
+<?php namespace Place\Lib;
+use Dever;
+class Address
+{
+    public function getList()
+    {
+        $data = Dever::db('address', 'place')->select(['status' => 1]);
+        $result = [];
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $name = $v['name'] . ',' . Dever::load('data', 'area')->string($v['area'], ',') . ',' . $v['address'];
+                $result[] = ['id' => $v['id'], 'name' => $name];
+            }
+        }
+        return $result;
+    }
+}

+ 82 - 0
src/place/set/lib/Info.php

@@ -1,5 +1,6 @@
 <?php namespace Place\Lib;
 use Dever;
+use Dever\Helper\Secure;
 class Info
 {
     public function money()
@@ -12,4 +13,85 @@ class Info
             return \Place::money();
         }
     }
+
+    # 生成分享需要的东西
+    public function share($place_id = 0, $sales_type = 0, $sales_id = 0, $uid = 0, $manage = false)
+    {
+        $result = [];
+        $info = Dever::db('info', 'place')->find($place_id);
+        if ($info) {
+            # code 第一个是领域id,第二个账户id,第三个是身份id
+            if ($manage) {
+                # 后台生成
+                $extend = Dever::load('common', 'manage')->extend();
+                $code = [$extend['info_id'], $info['uid'], $info['id'], $sales_type, $sales_id, $uid];
+            } else {
+                # 前台生成
+                $code = $this->decode(Dever::input('p'));
+                $code[3] = $sales_type;
+                $code[4] = $sales_id;
+                $code[5] = $uid;
+            }
+            $code = $this->encode(...$code);
+
+            $host = 'http://localhost:8080/#';
+            $path = '/pages/main?p=' . $code;
+
+            # 生成各个端口的身份入口:
+            $result['code'] = $code;
+
+            # 网页版
+            $result['web'] = '';
+
+            # h5页面
+            $result['h5'] = $host . $path;
+            # h5二维码码
+            $result['h5_ercode'] = '';
+            
+            # 小程序码
+            $result['applet'] = [
+                # 微信小程序
+                'wechat' => $path,
+                # 抖音小程序
+                # 快手小程序
+                # 支付宝小程序
+                # 美团小程序 等等
+            ];
+
+            # app
+            $result['app'] = [
+                'android' => '',
+                'ios' => '',
+            ];
+
+            # 桌面
+            $result['desktop'] = [
+                'win' => '',
+            ];
+
+        }
+        return $result;
+    }
+
+    public function encode($sector_id, $account_id, $place_id, $sales_type = 0, $sales_id = 0, $uid = 0)
+    {
+        $place = $sector_id . '-' . $account_id . '-' . $place_id. '-' . $sales_type . '-' . $sales_id . '-' . $uid;
+        $code = Secure::encode($place);
+        return $code;
+    }
+
+    public function decode($code)
+    {
+        $code = Secure::decode($code);
+        if (!$code) {
+            Dever::error('身份码错误');
+        }
+        return explode('-', $code);
+    }
+
+    # 更新个人身份的版本号
+    public function update($id)
+    {
+        return Dever::db('info', 'place')->update($id, ['update' => time()]);
+    }
 }

+ 11 - 0
src/place/set/manage/Lib/Address.php

@@ -0,0 +1,11 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Address
+{
+    public function getAddress($area, $address)
+    {
+        $result = Dever::load('data', 'area')->string($area, '');
+        $result .= $address;
+        return $result;
+    }
+}

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików