rabin 3 月之前
父節點
當前提交
84bcc75daf
共有 100 個文件被更改,包括 3573 次插入1317 次删除
  1. 52 5
      src/place/act/lib/Core.php
  2. 1 1
      src/place/act/table/collect.php
  3. 1 1
      src/place/act/table/like.php
  4. 1 1
      src/place/act/table/review.php
  5. 18 16
      src/place/boot.php
  6. 2 1
      src/place/interface/api/Address.php
  7. 52 0
      src/place/interface/api/Agent.php
  8. 2 0
      src/place/interface/api/Collect.php
  9. 92 0
      src/place/interface/api/Coupon.php
  10. 57 15
      src/place/interface/api/Main.php
  11. 9 0
      src/place/interface/api/Order.php
  12. 2 0
      src/place/interface/api/Review.php
  13. 1 1
      src/place/interface/api/Role.php
  14. 52 0
      src/place/interface/api/Saler.php
  15. 9 0
      src/place/interface/api/Score.php
  16. 106 190
      src/place/interface/api/Source.php
  17. 11 2
      src/place/interface/api/Tool.php
  18. 26 17
      src/place/interface/api/User.php
  19. 45 0
      src/place/interface/api/Vip.php
  20. 9 0
      src/place/interface/api/Wallet.php
  21. 6 1
      src/place/interface/lib/Core.php
  22. 0 25
      src/place/order/api/Manage.php
  23. 160 0
      src/place/order/lib/Pay.php
  24. 71 0
      src/place/order/lib/Role/Pay.php
  25. 0 0
      src/place/order/lib/Source/Cart.php
  26. 3 16
      src/place/order/lib/Source/Express.php
  27. 0 0
      src/place/order/lib/Source/Log.php
  28. 277 0
      src/place/order/lib/Source/Order.php
  29. 113 0
      src/place/order/lib/Source/Pay.php
  30. 143 0
      src/place/order/lib/Source/Refund.php
  31. 89 0
      src/place/order/lib/Source/User.php
  32. 26 0
      src/place/order/lib/Source/Virtual.php
  33. 0 547
      src/place/order/lib/source/Order.php
  34. 0 184
      src/place/order/lib/source/Refund.php
  35. 7 6
      src/place/order/manage/Lib/Source/Address.php
  36. 16 0
      src/place/order/manage/Lib/Source/Express.php
  37. 365 0
      src/place/order/manage/Lib/Source/Order.php
  38. 44 0
      src/place/order/manage/Lib/Source/Refund.php
  39. 16 0
      src/place/order/manage/Lib/Source/Virtual.php
  40. 10 1
      src/place/order/manage/core.php
  41. 6 0
      src/place/order/manage/role.php
  42. 5 4
      src/place/order/manage/source.php
  43. 10 7
      src/place/order/manage/source_address.php
  44. 1 1
      src/place/order/manage/source_express.php
  45. 1 1
      src/place/order/manage/source_refund.php
  46. 2 1
      src/place/order/manage/source_refund_audit.php
  47. 26 0
      src/place/order/manage/source_virtual.php
  48. 31 7
      src/place/order/table/role.php
  49. 38 13
      src/place/order/table/source.php
  50. 11 1
      src/place/order/table/source_detail.php
  51. 20 0
      src/place/order/table/source_virtual.php
  52. 13 27
      src/place/order/table/user_source.php
  53. 71 0
      src/place/order/table/user_source_log.php
  54. 5 0
      src/place/role/index.php
  55. 23 0
      src/place/role/manage/Lib/Api.php
  56. 18 0
      src/place/role/manage/Lib/Data.php
  57. 32 0
      src/place/role/manage/core.php
  58. 65 0
      src/place/role/manage/info.php
  59. 23 23
      src/place/role/manage/level.php
  60. 36 0
      src/place/role/manage/profit_buy.php
  61. 46 0
      src/place/role/manage/profit_partner.php
  62. 37 0
      src/place/role/manage/profit_sale.php
  63. 44 0
      src/place/role/table/info.php
  64. 3 9
      src/place/role/table/level.php
  65. 6 12
      src/place/role/table/profit_buy.php
  66. 69 0
      src/place/role/table/profit_partner.php
  67. 54 0
      src/place/role/table/profit_sale.php
  68. 5 5
      src/place/score/lib/Action.php
  69. 38 40
      src/place/score/lib/Log.php
  70. 33 0
      src/place/score/lib/Rebate.php
  71. 28 0
      src/place/score/manage/convert.php
  72. 19 1
      src/place/score/manage/core.php
  73. 18 7
      src/place/score/manage/info.php
  74. 29 0
      src/place/score/manage/rebate.php
  75. 90 0
      src/place/score/manage/rule.php
  76. 14 3
      src/place/score/manage/user.php
  77. 33 0
      src/place/score/manage/user_log.php
  78. 2 0
      src/place/score/table/action_log.php
  79. 41 0
      src/place/score/table/convert.php
  80. 15 7
      src/place/score/table/info.php
  81. 53 0
      src/place/score/table/rebate.php
  82. 10 25
      src/place/score/table/rule.php
  83. 2 1
      src/place/score/table/user.php
  84. 18 2
      src/place/score/table/user_log.php
  85. 1 1
      src/place/set/api/Url.php
  86. 1 1
      src/place/set/lib/Account.php
  87. 0 77
      src/place/set/lib/Manage.php
  88. 195 0
      src/place/set/lib/Role.php
  89. 25 0
      src/place/set/manage/Lib/Account.php
  90. 43 0
      src/place/set/manage/Lib/Api.php
  91. 53 0
      src/place/set/manage/Lib/Code.php
  92. 11 0
      src/place/set/manage/Lib/Nav.php
  93. 43 0
      src/place/set/manage/Lib/Place.php
  94. 30 0
      src/place/set/manage/Lib/Profit.php
  95. 8 0
      src/place/set/manage/core.php
  96. 7 6
      src/place/set/manage/info.php
  97. 92 0
      src/place/set/manage/nav.php
  98. 5 4
      src/place/set/manage/place.php
  99. 6 0
      src/place/set/table/code.php
  100. 15 1
      src/place/set/table/info.php

+ 52 - 5
src/place/act/lib/Core.php

@@ -6,6 +6,16 @@ class Core
     private $db;
     private $type;
     private $type_id;
+    protected $data;
+    public static $instance = array();
+    public static function load($name, $type = false, $type_id = false)
+    {
+        if (empty(static::$instance[$name])) {
+            static::$instance[$name] = new self($name, $type, $type_id);
+        }
+        return static::$instance[$name];
+    }
+
     public function __construct($name, $type = false, $type_id = false)
     {
         $this->type = Dever::input('type', '', '', $type);
@@ -26,7 +36,10 @@ class Core
         if ($this->getInfo($data)) {
             $msg && Dever::error($msg);
         } else {
-            $this->db->insert($this->data);
+            $state = $this->db->insert($this->data);
+            if ($state) {
+                Dever::load('log', 'place_score')->add(Place::$uid, '互动', $this->db->config['name']);
+            }
         }
         return 'ok';
     }
@@ -34,8 +47,12 @@ class Core
     # 删除
     public function del($data = array())
     {
-        if ($info = $this->getInfo($data)) {
-            $this->db->delete($info['id']);
+        $info = $this->getInfo($data);
+        if ($info) {
+            $state = $this->db->delete($info['id']);
+            if ($state) {
+                Dever::load('log', 'place_score')->add(Place::$uid, '互动', '取消' . $this->db->config['name']);
+            }
         }
         return 'ok';
     }
@@ -44,17 +61,47 @@ class Core
     public function getInfo($data = array(), $get = false, $field = array())
     {
         $this->check();
-        $this->data = $data;
         $this->data['type'] = $this->type;
         $this->data['type_id'] = $this->type_id;
         $this->data['uid'] = Place::$uid;
-        $info = $this->db->find($this->data);
+        $info = $this->db->find($data);
         if ($get) {
             return $this->handleInfo($info, $field);
         }
         return $info;
     }
 
+    # 获取列表
+    public function getList($set, $col = 'content')
+    {
+        $where['type'] = $this->type;
+        $where['type_id'] = $this->type_id;
+
+        $set['col'] = 'id,uid,cdate,' . $col;
+        $data = $this->db->select($where, $set);
+        if ($data) {
+            foreach ($data as &$v) {
+                $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
+                unset($v['cdate']);
+                $v['oper'] = 2;
+                if (Place::$uid == $v['uid']) {
+                    $v['oper'] = 1;
+                }
+                $v['user'] = Dever::db('info', 'place_user')->find($v['uid'], array('col' => 'name,avatar'));
+            }
+        }
+        return $data;
+    }
+
+    # 获取总数
+    public function getTotal()
+    {
+        $where['type'] = $this->type;
+        $where['type_id'] = $this->type_id;
+        $data = $this->db->count($where);
+        return $data;
+    }
+
     # 获取用户的互动列表
     public function getUserList($field = array(), $page = 10)
     {

+ 1 - 1
src/place/act/table/collect.php

@@ -1,7 +1,7 @@
 <?php
 return array
 (
-    'name' => '收藏',
+    'name' => '收藏',
     'partition' => 'Dever::call("manage/common.system")',
     'struct' => array
     (

+ 1 - 1
src/place/act/table/like.php

@@ -1,7 +1,7 @@
 <?php
 return array
 (
-    'name' => '点赞',
+    'name' => '点赞',
     'partition' => 'Dever::call("manage/common.system")',
     'struct' => array
     (

+ 1 - 1
src/place/act/table/review.php

@@ -1,7 +1,7 @@
 <?php
 return array
 (
-    'name' => '评价',
+    'name' => '评价',
     'partition' => 'Dever::call("manage/common.system")',
     'order' => 'sort asc',
     'struct' => array

+ 18 - 16
src/place/boot.php

@@ -6,7 +6,7 @@ class Place
     public static $user;
     public static $uid;
     public static $code;
-    public static $channel;
+    public static $nav;
     public static $system;
     public static $sector;
     public static $module;
@@ -42,17 +42,13 @@ class Place
         # 切换数据库
         self::$module = Dever::db('system_module', 'manage')->find(array('key' => 'sector_place'));
         Dever::load('common', 'manage')->setAuth(self::$system['partition'], self::$system['id'], self::$sector['id'], self::$module['id'], $place_id);
-
-        # 初始化频道
-        self::channel();
-
     }
 
     # 身份信息
     public static function info($user_id, $place_id)
     {
         $user = Dever::db('user', 'sector')->find($user_id);
-        self::$info = Dever::db('info', 'place')->find($place_id, array('col' => 'name,logo,content,bg,type,money_id,uid,pay_account'));
+        self::$info = Dever::db('info', 'place')->find($place_id, array('col' => 'name,logo,type,money_id,uid,pay_account,score_name,`update`'));
         if (!self::$info) {
             Dever::error('信息有误');
         }
@@ -60,30 +56,36 @@ class Place
             Dever::error('信息有误');
         }
         self::$id = $place_id;
-        self::$info['channel'] = $user['channel'];
-        self::$info['content'] = htmlspecialchars_decode(self::$info['content']);
-    }
-
-    # 资源信息
-    public static function channel()
-    {
-        self::$channel = Dever::db('channel', 'place_source')->select(['status' => 1], array('col' => 'id,name,icon,icon_select'));
+        self::$info['supplier'] = $user['supplier'];
     }
 
     # 用户信息
     public static function user($uid)
     {
-        self::$user = Dever::db('info', 'place_user')->find($uid, array('col' => 'id,name,avatar'));
+        self::$user = Dever::db('info', 'place_user')->find($uid, array('col' => 'id,name,avatar,sex,sign'));
         if (self::$user) {
             self::$uid = $uid;
         }
     }
 
+    # 菜单信息
+    public static function nav()
+    {
+        return Dever::db('nav', 'place')->select(['status' => 1], array('col' => 'id,name,type,type_id,icon,icon_select'));
+    }
+
+    # 支付的货币信息
+    public static function money()
+    {
+        return Dever::db('money', 'sector')->find(self::$info['money_id'], array('col' => 'name,code,sign,unit'));
+    }
+
     public static function result($data)
     {
         $data['place'] = self::$info;
-        $data['channel'] = self::$channel;
         $data['user'] = self::$user;
+        $data['nav'] = self::nav();
+        $data['nav_select'] = $data['nav'][0]['id'];
         return $data;
     }
 }

+ 2 - 1
src/place/interface/api/Address.php

@@ -22,11 +22,12 @@ class Address extends Core
         $province = Dever::input('province', 'is_numeric', '省份');
         $city = Dever::input('city', 'is_numeric', '城市');
         $county = Dever::input('county', 'is_numeric', '区县');
+        $town = Dever::input('town', 'is_numeric', '街镇');
         $address = Dever::input('address', 'is_string', '地址');
         $name = Dever::input('name', 'is_string', '联系人');
         $phone = Dever::input('phone', 'is_string', '联系方式');
 
-        return Dever::load('address', 'place_user')->update($id, $type, $phone, $name, $province, $city, $county, $address);
+        return Dever::load('address', 'place_user')->update($id, $type, $phone, $name, $province, $city, $county, $town, $address);
     }
 
     # 获取默认地址

+ 52 - 0
src/place/interface/api/Agent.php

@@ -0,0 +1,52 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+use Place\Lib\Role;
+class Agent extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->role = new Role('agent', 3);
+    }
+
+    # 代理中心
+    public function home()
+    {
+        $data = Dever::db('agent', 'place_user')->find(array('uid' => Place::$uid));
+        return $data;
+    }
+
+    # 基本信息
+    public function getList()
+    {
+        return $this->role->getList();
+    }
+
+    # 确认支付
+    public function pay_confirm()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::error('代理不存在');
+        }
+        $info = $this->role->getList($id);
+        if (!$info['list']) {
+            Dever::error('代理不存在');
+        }
+        $data = Dever::load('role/pay', 'place_order')->get($info['list']);
+        $data['money'] = Place::money();
+        return $data;
+    }
+
+    # 拉起支付
+    public function pay()
+    {
+        $this->pay_confirm();
+        return Dever::load('role/pay', 'place_order')->act();
+    }
+}

+ 2 - 0
src/place/interface/api/Collect.php

@@ -14,11 +14,13 @@ class Collect extends Core
         $this->act = new Act('collect');
     }
 
+    public function up_commit(){}
     public function up()
     {
         return $this->act->up();
     }
 
+    public function cancel_commit(){}
     public function cancel()
     {
         return $this->act->del();

+ 92 - 0
src/place/interface/api/Coupon.php

@@ -0,0 +1,92 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+class Coupon extends Core
+{
+    protected $login = false;
+    protected $entry = true;
+
+    # 领劵列表
+    public function getList()
+    {
+        $source_id = Dever::input('source_id');
+        $detail = array();
+        $set = array('col' => 'id,name,type,value,min,`limit`,date_type,date_day,date_start,date_end');
+        if ($source_id) {
+            $detail = Dever::db('info', 'place_source')->select(['id' => $source_id], ['col' => '1 as coupon_type, id as coupon_type_id']);
+            $set['num'] = 10;
+        }
+        $data = array();
+        $where = ['get' => 1, 'status' => 1];
+        $list = Dever::db('coupon', 'place_source')->select($where, $set);
+        if ($list) {
+            $t = array();
+            foreach ($list as $k => $v) {
+                $state = false;
+                if (Place::$uid && $v['limit'] > 0) {
+                    $user = Dever::db('coupon', 'place_user')->count(['uid' => Place::$uid, 'coupon_id' => $v['id']]);
+                    if ($v['limit'] <= $user) {
+                        continue;
+                    }
+                }
+                if ($detail) {
+                    $state = Dever::load('coupon', 'place_user')->getScope($v['id'], $detail, $t);
+                } else {
+                    $state = true;
+                }
+                if ($state) {
+                    $v['id'] = \Dever\Helper\Secure::encode($v['id']);
+                    $v = Dever::load('coupon', 'place_source')->getInfo($v);
+                    $data[] = $v;
+                }
+            }
+        }
+        return ['coupon' => $data];
+    }
+
+    # 我的优惠券
+    public function my()
+    {
+        if (!Place::$uid) {
+            $this->showLogin();
+        }
+        $data['list'] = Dever::load('coupon', 'place_user')->getList();
+        $data['money'] = Place::$info['money'];
+        return $data;
+    }
+
+
+    # 领取优惠券
+    public function get()
+    {
+        if (!Place::$uid) {
+            $this->showLogin();
+        }
+        $code = Dever::input('code');
+        if ($code) {
+            $code = Dever::db('coupon_code', 'place_source')->find(['code' => $code, 'status' => 1]);
+            if (!$code) {
+                Dever::error('兑换码错误');
+            }
+            if ($code['total'] > 0) {
+                $yue = $code['total'] - $code['used'];
+                if ($yue <= 0) {
+                    Dever::error('剩余兑换次数不足');
+                }
+            }
+            $id = $code['coupon_id'];
+        } else {
+            $id = \Dever\Helper\Secure::decode(Dever::input('id'));
+        }
+        if (!$id) {
+            Dever::error('优惠券不存在');
+        }
+        $state = Dever::load('coupon', 'place_user')->get($id, $code);
+        if (!$state) {
+            Dever::error('领取失败');
+        }
+        return '领取成功';
+    }
+
+}

+ 57 - 15
src/place/interface/api/Main.php

@@ -7,59 +7,63 @@ class Main extends Core
     # 首页
     public function home()
     {
-        $data['entry'] = false;
+        $data['e'] = false;
         if (Place::$info['type'] == 1) {
             # 公开
-            $data['entry'] = true;
+            $data['e'] = true;
         } elseif (Place::$info['type'] == 2 && Place::$user) {
             # 注册
-            $data['entry'] = true;
+            $data['e'] = true;
         } elseif (Place::$info['type'] > 2 && Place::$user && Place::$user['entry_type'] > 2) {
             # 邀请码、购买、密码等等
-            $data['entry'] = true;
+            $data['e'] = true;
         } else {
             # 需要注册、购买、输入密码等等
             if (Place::$info['type'] == 2) {
-                $data['button'] = array
+                $data['b'] = array
                 (
                     'name' => '注册',
                     'type' => 2,
                 );
             } elseif (Place::$info['type'] == 3) {
-                $data['button'] = array
+                $data['b'] = array
                 (
                     'name' => '邀请码',
                     'type' => 3,
                 );
             } elseif (Place::$info['type'] == 4) {
-                $data['button'] = array
+                $data['b'] = array
                 (
                     'name' => '密码',
                     'type' => 4,
                 );
             } elseif (Place::$info['type'] == 5) {
-                $data['button'] = array
+                $data['b'] = array
                 (
                     'name' => '购买',
                     'type' => 5,
                 );
             }
         }
-        return Place::result($data);
+        //$data['i'] = htmlspecialchars_decode(Place::$info['content']);
+        $data['n'] = Place::$info['name'];
+        $data['l'] = Place::$info['logo'];
+        $data['u'] = Place::$info['update'];
+        $data['m'] = Place::nav();
+        return $data;
     }
 
     # 验证码登录或者注册
     public function login_commit(){}
     public function login()
     {
-        $account = Dever::input('account', 'is_string', '账户信息');
+        $account = Dever::input('account', 'is_string', '账户信息', 'wechat');
         $env = Dever::input('env', 'is_numeric', '环境信息', 3);
         $mobile = Dever::input('mobile', 'is_numeric', '手机号');
         $pwd = Dever::input('pwd');
-        $invite = Dever::input('invite');
         if (!$pwd) {
             $code = Dever::input('code', 'is_numeric', '验证码');
-            #Dever::load('template', 'msg')->check('reg_code', $mobile, $code);
+            Dever::load('template', 'msg')->check('reg_code', $mobile, $code);
         }
         $where['mobile'] = $mobile;
         $db = Dever::db('info', 'place_user');
@@ -71,9 +75,28 @@ class Main extends Core
             # 已注册,登录
             $uid = $user['id'];
         } else {
-            if ($pwd) {
-                Dever::error('登录失败,账户无效');
-            }
+            Dever::error('登录失败,账户无效');
+        }
+        return $this->result($account, $env, $uid);
+    }
+
+    # 注册
+    public function reg_commit(){}
+    public function reg()
+    {
+        $account = Dever::input('account', 'is_string', '账户信息', 'wechat');
+        $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) {
@@ -82,6 +105,8 @@ class Main extends Core
             }
             $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);
@@ -90,7 +115,13 @@ class Main extends Core
                     $db->update($uid, array('parent_uid' => $parent_uid));
                 }
             }
+            //Dever::load('log', 'place_score')->add($uid, '用户', '注册');
         }
+        return $this->result($account, $env, $uid);
+    }
+
+    private function result($account, $env, $uid)
+    {
         $result['t'] = \Dever\Helper\Secure::login($uid);
         # 获取openid
         $result = Dever::load('util', 'api')->openid($account, $env, $uid, $result);
@@ -107,4 +138,15 @@ class Main extends Core
         $data = Dever::load('template', 'msg')->send('reg_code', array('mobile' => $mobile));
         return $data;
     }
+
+    # 获取单页信息
+    public function page()
+    {
+        $name = Dever::input('name', 'is_string', '单页名称');
+        $info = Dever::db('page', 'sector')->find(['name' => $name]);
+        if ($info) {
+            $info['content'] = htmlspecialchars_decode($info['content']);
+        }
+        return $info;
+    }
 }

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

@@ -0,0 +1,9 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+class Order extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+}

+ 2 - 0
src/place/interface/api/Review.php

@@ -14,12 +14,14 @@ class Review extends Core
         $this->act = new Act('review');
     }
 
+    public function up_commit(){}
     public function up()
     {
         $data['content'] = Dever::input('content', 'is_string', '内容');
         return $this->act->up($data, '请不要发布相同内容');
     }
 
+    public function cancel_commit(){}
     public function cancel()
     {
         $data['id'] = Dever::input('review_id', 'is_numeric', '评论');

+ 1 - 1
src/place/interface/api/Role.php

@@ -4,7 +4,7 @@ use Place;
 use Place_interface\Lib\Core;
 class Role extends Core
 {
-    //protected $login = true;
+    protected $login = false;
     protected $entry = true;
 
     # 我的信息

+ 52 - 0
src/place/interface/api/Saler.php

@@ -0,0 +1,52 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+use Place\Lib\Role;
+class Saler extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->role = new Role('saler', 2);
+    }
+
+    # 分销中心
+    public function home()
+    {
+        $data = Dever::db('saler', 'place_user')->find(array('uid' => Place::$uid));
+        return $data;
+    }
+
+    # 基本信息
+    public function getList()
+    {
+        return $this->role->getList();
+    }
+
+    # 确认支付
+    public function pay_confirm()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::error('分销员不存在');
+        }
+        $info = $this->role->getList($id);
+        if (!$info['list']) {
+            Dever::error('分销员不存在');
+        }
+        $data = Dever::load('role/pay', 'place_order')->get($info['list']);
+        $data['money'] = Place::money();
+        return $data;
+    }
+
+    # 拉起支付
+    public function pay()
+    {
+        $this->pay_confirm();
+        return Dever::load('role/pay', 'place_order')->act();
+    }
+}

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

@@ -0,0 +1,9 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+class Score extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+}

+ 106 - 190
src/place/interface/api/Source.php

@@ -2,207 +2,160 @@
 use Dever;
 use Place;
 use Place_interface\Lib\Core;
+use Place_act\Lib\Core as Act;
 class Source extends Core
 {
-    private $channel_id = 0;
-    private $field = array
-    (
-        'info' => 'id,name,info,pic,type,spec_type',
-        'cate' => 'id,parent_id,score_id,buy,name,status,`desc`',
-    );
-
     # 首页
     public function home()
     {
-        $this->channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
+        $channel_id = Dever::input('channel_id', 'is_numeric', '频道ID');
         # 获取频道信息
-        $data['channel'] = Dever::db('channel', 'place_source')->find(array('id' => $this->channel_id, 'status' => 1), array('col' => 'id,type,name,`desc`'));
-        if (!$data['channel']) {
-            Dever::error('频道不存在');
-        }
-
+        $channel = Dever::load('channel', 'place_source')->getInfo($channel_id);
+
+        $data['channel'] = array
+        (
+            'id'    => $channel['id'],
+            'name'  => $channel['name'],
+            'desc'  => $channel['desc'],
+        );
         # 分类信息
+        $top_id = 0;
         $data['top'] = array();
-        if ($data['channel']['type'] == 1) {
+        if ($channel['type'] == 1) {
             # 显示子分类
             # 根据频道获取主分类
-            $top = Dever::input('top_id');
-            $data['top'] = $this->getCate(0);
-            if ($top) {
-                $data['cate'] = $this->getData($top);
-            } elseif ($data['top']) {
-                $data['cate'] = $this->getData($data['top'][0]['id']);
+            $data['top'] = Dever::load('cate', 'place_source')->getTop($channel_id, 0);
+            $top_id = Dever::input('top_id');
+            if (!$top_id && $data['top']) {
+                $top_id = $data['top'][0]['id'];
             }
-        } else {
-            # 不显示子分类
-            $data['cate'] = $this->getData(0);
         }
+        $data['cate'] = Dever::load('cate', 'place_source')->getData($channel, $top_id);
 
-        # 广告和推荐位信息
-        $data['ad'] = array();
+        # 主页轮播、主页小导航、主页信息流
+        $data['ad'] = Dever::load('ad', 'place_source')->gets(array(1,2,3,4,5), $channel_id, $top_id);
 
         return $data;
     }
 
-    # 获取分类及其资源
-    private function getData($parent_id)
-    {
-        $data = $this->getCate($parent_id);
-        if (!$data && $parent_id > 0) {
-            $data = $this->getCate(0, $parent_id);
-        }
-        if ($data) {
-            foreach ($data as &$v) {
-                $v['list'] = $this->getSource($v, 5);
-            }
-        }
-        return $data;
-    }
-
-    # 获取分类信息
-    private function getCate($parent_id = 0, $id = false)
-    {
-        if ($id) {
-            $where['id'] = $id;
-        }
-        $where['channel_id'] = $this->channel_id;
-        $where['parent_id'] = $parent_id;
-        return Dever::db('cate', 'place_source')->select($where, array('col' => $this->field['cate']));
-    }
-
-    # 获取资源信息
-    private function getSource($cate, $limit, $page = false)
+    # 分类列表页
+    public function cate()
     {
-        $key = 'cate_parent_id';
-        if ($cate['parent_id'] > 0) {
-            $key = 'cate_child_id';
-        }
-        $where = array($key => $cate['id'], 'status' => 1);
-        $search = Dever::input('search');
-        if ($search) {
-            $where['name'] = array('like', $search);
-        }
-        $set = array('col' => $this->field['info']);
-        if ($limit) {
-            $set['limit'] = $limit;
-        }
-        if ($page) {
-            $set['num'] = $page;
+        $cate_id = Dever::input('id', 'is_numeric', '分类ID');
+        $cate = Dever::load('cate', 'place_source')->getInfo($cate_id);
+        $data['cate'] = array
+        (
+            'id'    => $cate['id'],
+            'name'  => $cate['name'],
+            'desc'  => $cate['desc'],
+        );
+        $data['list'] = Dever::load('info', 'place_source')->getList($cate, false, 10);
+
+        $data['child'] = array();
+        if ($cate['parent_id'] == 0) {
+            $cate_id = $cate['id'];
+            $data['child'] = Dever::load('cate', 'place_source')->getList($cate['channel_id'], $cate['id']);
+        } else {
+            $cate_id = $cate['parent_id'];
         }
-        $data = Dever::db('info', 'place_source')->select($where, $set);
 
-        # 获取详情
-        if ($data) {
-            $cate['score'] = Dever::db('info', 'place_score')->find($cate['score_id']);
-            foreach ($data as &$v) {
-                $v = Dever::load('info', 'place_source')->get($v, $cate);
-            }
-        }
-        return $data;
-    }
+        # 列表页轮播图、列表页信息流
+        $data['ad'] = Dever::load('ad', 'place_source')->gets(array(11,12), $cate['channel_id'], $cate_id);
 
-
-    # 某个分类的列表页
-    public function cate()
-    {
-        $cate_id = Dever::input('cate_id', 'is_numeric', '分类ID');
-        $data['cate'] = Dever::db('cate', 'place_source')->find($cate_id, array('col' => $this->field['cate']));
-        if (!$data['cate']) {
-            Dever::error('分类不存在');
-        }
-        if ($data['cate']['status'] != 1) {
-            Dever::error('分类不存在');
-        }
-        $data['list'] = $this->getSource($data['cate'], false, 10);
         return $data;
     }
 
-    # 详情
-    public function view()
+    # 资源介绍页
+    public function info()
     {
-        $source_id = Dever::input('source_id', 'is_numeric', '资源ID');
-        $data['info'] = Dever::load('info', 'place_source')->get($source_id, false, true);
-        $content = Dever::db('content', 'place_source')->find(array('info_id' => $source_id));
+        $source_id = Dever::input('id', 'is_numeric', '资源ID');
+        $info = Dever::load('info', 'place_source')->getInfo($source_id);
+        $data['info'] = array
+        (
+            'id'            => $info['id'],
+            'name'          => $info['name'],
+            'sku_name'      => $info['sku_name'],
+            'price'         => $info['price'],
+            'price_text'    => $info['price_text'],
+            'm_price'       => $info['m_price'],
+            'm_price_text'  => $info['m_price_text'],
+            'rebate'        => $info['rebate'],
+            'num_sell'      => $info['num_sell'],
+            'stock'         => $info['stock'],
+            'pic'           => $info['pic'],
+            'content'       => $info['content'],
+        );
+        $data['have_vip'] = $info['have_vip'];
+        $data['help'] = $info['help'];
+
+        # 是否收藏
+        $data['collect'] = $info['collect'];
         # 是否展示内容
-        $data['content'] = 2;
+        $content = Dever::db('content', 'place_source')->find(array('info_id' => $source_id));
+        $data['content'] = false;
         if ($content) {
-            $data['content'] = 1;
+            $data['content'] = true;
         }
-        # 展示说明
-        $data['desc'] = Dever::db('help', 'place_source')->select(array('type' => 1), array('col' => 'name,info,pic'));
-        $data['help'] = Dever::db('help', 'place_source')->select(array('type' => 2), array('col' => 'name,info,pic'));
 
         # 获取评价
-        $data['review'] = Dever::db('review', 'place_act')->select(array('type' => 1, 'type_id' => $source_id), array('limit' => 3));
-        if ($data['review']) {
-            foreach ($data['review'] as &$v) {
-                $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
-                $v['oper'] = 2;
-                if (Place::$uid == $v['uid']) {
-                    $v['oper'] = 1;
-                }
-                $v['user'] = Dever::db('info', 'place_user')->find($v['uid'], array('col' => 'mobile,name,avatar'));
-            }
-        }
+        $data['review'] = Act::load('review', 1, $source_id)->getList(['limit' => 3]);
+        # 评价总数
+        $data['review_total'] = Act::load('review', 1, $source_id)->getTotal();
+
+        # 详情页轮播、详情页信息流
+        $data['ad'] = Dever::load('ad', 'place_source')->gets(array(21,22), $info['channel_id'], $info['cate_parent_id']);
 
         return $data;
     }
 
-    # 详情页查看价格
-    public function view_price()
+    # 资源sku
+    public function sku()
     {
-        $source_id = Dever::input('source_id', 'is_numeric', '资源ID');
-        $sku_id = Dever::input('sku_id', 'is_numeric', '规格ID');
-        $buy_num = Dever::input('buy_num', 'is_numeric', '数量', 1);
-        $data = Dever::load('info', 'place_source')->getSkuList($source_id, $sku_id, $buy_num);
+        $source_id = Dever::input('id', 'is_numeric', '资源ID');
+        $data['sku'] = Dever::load('info', 'place_source')->getSku($source_id);
         return $data;
     }
 
-    # 详情页查看内容
-    public function view_content()
+    # 资源内容列表页
+    public function content()
     {
-        $source_id = Dever::input('source_id', 'is_numeric', '资源ID');
-        $data['cate'] = Dever::db('content_cate', 'place_source')->select(array('info_id' => $source_id, 'status' => 1));
-        $set = array('num' => 10);
-        if ($data['cate']) {
-            $cate_id = Dever::input('cate_id');
-            if (!$cate_id) {
-                $cate_id = $data['cate'][0]['id'];
-            }
-            $data['content'] = Dever::db('content', 'place_source')->select(array('info_id' => $source_id, 'cate_id' => $cate_id), $set);
-        } else {
-            $data['content'] = Dever::db('content', 'place_source')->select(array('info_id' => $source_id), $set);
-        }
-        if (Place::$uid && $data['content']) {
-            # 检测是否购买过
-            foreach ($data['content'] as $k => $v) {
+        $source_id = Dever::input('id', 'is_numeric', '资源ID');
+        $source = Dever::load('info', 'place_source')->getBaseInfo($source_id);
+        list($data['cate'], $data['cate_id']) = Dever::load('content', 'place_source')->getCate($source_id);
+        $data['content'] = Dever::load('content', 'place_source')->getList($source_id, $data['cate_id']);
 
-            }
-        }
+        # 内容页轮播、内容页信息流
+        $data['ad'] = Dever::load('ad', 'place_source')->gets(array(31,32), $source['channel_id'], $source['cate_parent_id']);
         return $data;
     }
 
-    # 详情页查看内容
-    public function view_content_info()
+    # 资源内容列表详情页
+    public function content_info()
     {
-        $content_id = Dever::input('content_id', 'is_numeric', '内容ID');
-        $data['info'] = Dever::db('content', 'place_source')->find($content_id);
-        # 检测是否购买过
+        $content_id = Dever::input('id', 'is_numeric', '内容ID');
+        $data['content'] = Dever::load('content', 'place_source')->getInfo($content_id);
+        $data['source'] = Dever::load('info', 'place_source')->getBaseInfo($data['content']['info_id']);
         return $data;
     }
 
-    # 拉起支付
-    public function pay()
+    # 确认支付
+    public function pay_confirm()
     {
         if (!Place::$uid) {
             $this->showLogin();
         }
-        $info = $this->view_price();
-        if ($info['sku']['buy'] == 1) {
-            return Dever::load('info', 'place_source')->pay($info);
-        } else {
-            Dever::error('您当前的身份角色无法购买');
-        }
+        //[{"id":6,"sku_id":10,"num":2}]
+        $source = Dever::input('source', 'is_string', '资源');
+        $source = Dever::json_decode($source);
+        $data = Dever::load('source/pay', 'place_order')->get($source);
+        return $data;
+    }
+
+    # 拉起支付
+    public function pay()
+    {
+        $this->pay_confirm();
+        return Dever::load('source/pay', 'place_order')->act();
     }
 
     # 重新支付
@@ -214,21 +167,9 @@ class Source extends Core
     # 资源评论列表
     public function getReviewList()
     {
-        $where['type'] = 1;
-        $where['type_id'] = Dever::input('source_id', 'is_numeric', '资源ID');
-        # 每页10条
-        $set['num'] = Dever::input('num', 'is_numeric', '分页条数', 10);
-        $data = Dever::db('review', 'place_act')->select($where, $set);
-        if ($data) {
-            foreach ($data as &$v) {
-                $v['cdate_str'] = date('Y-m-d H:i:s', $v['cdate']);
-                $v['oper'] = 2;
-                if (Place::$uid == $v['uid']) {
-                    $v['oper'] = 1;
-                }
-                $v['user'] = Dever::db('info', 'place_user')->find($v['uid'], array('col' => 'mobile,name,avatar'));
-            }
-        }
+        $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]);
         $result['list'] = $data;
         $result['total'] = Dever::page('total');
         return $result;
@@ -265,29 +206,4 @@ class Source extends Core
         }
         return $result;
     }
-
-    private function getOrderInfo($order, $view = false)
-    {
-        if ($order) {
-            $info = Dever::db('info', 'place_source')->find($order['source_id'], array('col' => 'id,name,pic,info'));
-            $info['pic'] = explode(',', $info['pic']);
-            $order['pic'] = $info['pic'][0] ?? '';
-            $order['status_name'] = Dever::db('source', 'place_order')->value('status', $order['status']);
-            $order['cdate_str'] = date('Y-m-d H:i:s', $order['cdate']);
-            if (isset($order['pdate']) && $order['pdate']) {
-                $order['pdate_str'] = date('Y-m-d H:i:s', $order['pdate']);
-            }
-            if (isset($order['ddate']) && $order['ddate']) {
-                $order['ddate_str'] = date('Y-m-d H:i:s', $order['ddate']);
-            }
-            if (isset($order['qdate']) && $order['qdate']) {
-                $order['qdate_str'] = date('Y-m-d H:i:s', $order['qdate']);
-            }
-            if (isset($order['fdate']) && $order['fdate']) {
-                $order['fdate_str'] = date('Y-m-d H:i:s', $order['fdate']);
-            }
-            $order = Dever::load('source/order', 'place_order')->getInfo($order, $view);
-        }
-        return $order;
-    }
 }

+ 11 - 2
src/place/interface/api/Tool.php

@@ -2,7 +2,7 @@
 use Dever;
 use Place;
 use Place_interface\Lib\Core;
-class Tool extends Core
+class Tool
 {
     # 根据身份码获取入口
     public function code()
@@ -15,6 +15,15 @@ class Tool extends Core
         if (!$code) {
             Dever::error('身份码错误');
         }
-        return array('p' => Place::entry($code['sector_id'], $code['module_id'], $code['user_id'], $code['place_id']));
+        $entry = Place::entry($code['sector_id'], $code['module_id'], $code['user_id'], $code['place_id']);
+        return $entry;
+    }
+
+    # 根据身份码获取入口
+    public function go()
+    {
+        $entry = $this->code();
+        $url = 'http://localhost:8080/#/?p=' . $entry;
+        header('location:' . $url);
     }
 }

+ 26 - 17
src/place/interface/api/User.php

@@ -10,27 +10,28 @@ class User extends Core
     # 我的信息
     public function info()
     {
-        $data = array();
-        # 获取角色
-        $data['role'] = Dever::db('role', 'place_user')->select(array('status' => 1), array('col' => 'id,name,icon'));
-
-        if ($data['role']) {
-            foreach ($data['role'] as &$role) {
-                $user_role = Dever::db('user_role', 'place_user')->find(array('role_id' => $role['id']));
-                if ($user_role) {
-                    $role['level'] = Dever::db('role_level', 'place_user')->find($user_role['level_id'], array('col' => 'id,name,icon'));
-                }
+        $data['user'] = Place::$user;
+        $data['user']['coupon'] = 0;
+        $data['user']['vip_name'] = $data['user']['saler_name'] = $data['user']['agent_name'] = '';
+        if ($data['user']['vip_id'] > 0) {
+            $vip = Dever::db('vip', 'place')->find(['id' => $data['user']['vip_id']]);
+            if ($vip) {
+                $data['user']['vip_name'] = $vip['name'];
+            }
+        }
+        if ($data['user']['saler_id'] > 0) {
+            $saler = Dever::db('saler', 'place')->find(['id' => $data['user']['saler_id']]);
+            if ($saler) {
+                $data['user']['saler_name'] = $saler['name'];
             }
         }
-        # 获取积分
-        $score = Dever::db('user', 'place_score')->select(array('uid' => Place::$uid), array('col' => 'info_id,total,used,balance'));
-        if ($score) {
-            foreach ($score as $k => $v) {
-                $data['score'][$k] = Dever::db('info', 'place_score')->find($v['info_id'], array('col' => 'id,name,symbol,symbol_location'));
-                $data['score'][$k] += $v;
+        if ($data['user']['agent_id'] > 0) {
+            $agent = Dever::db('agent', 'place')->find(['id' => $data['user']['agent_id']]);
+            if ($agent) {
+                $data['user']['agent_name'] = $agent['name'];
             }
         }
-        return Place::result($data);
+        return $data;
     }
 
     # 更新我的信息
@@ -45,6 +46,14 @@ class User extends Core
         if ($avatar) {
             Place::$user['avatar'] = $update['avatar'] = $avatar;
         }
+        $sign = Dever::input('sign');
+        if ($sign) {
+            Place::$user['sign'] = $update['sign'] = $sign;
+        }
+        $sex = Dever::input('sex');
+        if ($sex) {
+            Place::$user['sex'] = $update['sex'] = $sex;
+        }
         if ($update) {
             Dever::db('info', 'place_user')->update(Place::$uid, $update);
         }

+ 45 - 0
src/place/interface/api/Vip.php

@@ -0,0 +1,45 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+use Place\Lib\Role;
+class Vip extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->role = new Role('vip', 1);
+    }
+
+    # 基本信息
+    public function getList()
+    {
+        return $this->role->getList();
+    }
+
+    # 确认支付
+    public function pay_confirm()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::error('会员不存在');
+        }
+        $info = $this->role->getList($id);
+        if (!$info['list']) {
+            Dever::error('会员不存在');
+        }
+        $data = Dever::load('role/pay', 'place_order')->get($info['list']);
+        $data['money'] = Place::money();
+        return $data;
+    }
+
+    # 拉起支付
+    public function pay()
+    {
+        $this->pay_confirm();
+        return Dever::load('role/pay', 'place_order')->act();
+    }
+}

+ 9 - 0
src/place/interface/api/Wallet.php

@@ -0,0 +1,9 @@
+<?php namespace Place_interface\Api;
+use Dever;
+use Place;
+use Place_interface\Lib\Core;
+class Wallet extends Core
+{
+    protected $login = true;
+    protected $entry = true;
+}

+ 6 - 1
src/place/interface/lib/Core.php

@@ -38,6 +38,11 @@ class Core
 
     protected function showLogin()
     {
-        Dever::error('请先登录', 300);
+        Dever::error('请先登录', -2);
+    }
+
+    public function getUpdate()
+    {
+        return Place::$info['update'];
     }
 }

+ 0 - 25
src/place/order/api/Manage.php

@@ -1,25 +0,0 @@
-<?php namespace Place_source\Api;
-use Dever;
-use Manage\Lib\Auth;
-class Manage extends Auth
-{
-    public function getInfo()
-    {
-        return Dever::load('common', 'manage')->cascader(2, function($level, $parent) {
-            if ($level == 1) {
-                $data = Dever::db('info', 'place_source')->select([]);
-            } elseif ($level == 2) {
-                $data = Dever::db('sku', 'place_source')->select(array('info_id' => $parent));
-                if ($data) {
-                    foreach ($data as &$v) {
-                        $v['name'] = Dever::load('sku', 'api')->getName($v['key'], 'place_source');
-                        if (!$v['name']) {
-                            $v['name'] = '无规格';
-                        }
-                    }
-                }
-            }
-            return $data;
-        });
-    }
-}

+ 160 - 0
src/place/order/lib/Pay.php

@@ -0,0 +1,160 @@
+<?php namespace Place_order\Lib;
+use Dever;
+use Place;
+
+class Pay
+{
+    protected $type = '';
+    protected $order = array();
+    protected $detail = array();
+    protected $user = array();
+    protected $coupon = array();
+
+    # 获取支付需要的信息
+    public function get($detail)
+    {
+        $this->order['cash'] = $this->order['num'] = 0;
+        $this->order['name'] = array();
+        foreach ($detail as $k => $v) {
+            $this->getDetail($v);
+        }
+        $this->getUser();
+        $this->getOrder();
+        return ['order' => $this->order, 'detail' => $this->detail, 'user' => $this->user];
+    }
+
+    # 获取用户信息
+    private function getUser()
+    {
+        $address_id = Dever::input('address_id');
+        $user_coupon_id = Dever::input('user_coupon_id');
+        $coupon_cash = Dever::input('coupon_cash');
+
+        # 获取当前余额
+        $this->user['wallet'] = Dever::number(Place::$user['wallet']);
+        # 获取当前可用的优惠券
+        $this->user['coupon'] = Dever::load('coupon', 'place_user')->getUseList($this->detail, $user_coupon_id, $coupon_cash);
+
+        # 获取地址
+        if ($address_id) {
+            $this->user['address'] = Dever::load('address', 'place_user')->getInfo($address_id, Place::$uid);
+        } else {
+            $this->user['address'] = Dever::load('address', 'place_user')->getDefault();
+        }
+    }
+
+    # 获取订单信息
+    private function getOrder()
+    {
+        $this->order['uid'] = Place::$uid;
+        if (is_array($this->order['name'])) {
+            $this->order['name'] = implode('、', $this->order['name']);
+        }
+        $this->order['cash'] = Dever::number($this->order['cash']);
+        # 支付金额
+        $this->order['pay_cash'] = $this->order['cash'];
+        # 使用的钱包金额和优惠券金额
+        $this->order['user_coupon_id'] = $this->order['wallet_cash'] = $this->order['coupon_cash'] = 0;
+
+        # 优惠券
+        $this->getCoupon();
+
+        # 钱包
+        $this->getWallet();
+
+        $this->order['pay_cash'] = Dever::number($this->order['pay_cash']);
+
+        if ($this->user['address']) {
+            $this->order['address_id'] = $this->user['address']['id'];
+        }
+    }
+
+    # 优惠券
+    private function getCoupon()
+    {
+        $this->coupon = array();
+        if ($this->user['coupon']) {
+            $this->coupon = $this->user['coupon'][0];
+            $this->order['user_coupon_id'] = $this->coupon['id'];
+            $this->order['coupon_cash'] = Dever::number($this->coupon['cash']);
+            $this->order['pay_cash'] -= $this->order['coupon_cash'];
+        }
+    }
+
+    # 钱包
+    private function getWallet()
+    {
+        $wallet = Dever::input('wallet');
+        if ($wallet > 0 && Place::$user['wallet'] >= $wallet) {
+            $this->order['wallet_cash'] = Dever::number($wallet);
+            $this->order['pay_cash'] -= $this->order['wallet_cash'];
+        }
+    }
+
+    # 下单
+    public function act_commit(){}
+    public function act($detail = false)
+    {
+        if ($detail) {
+            $this->get($detail);
+        }
+        if (!$this->order) {
+            Dever::error('订单不存在');
+        }
+        $this->check();
+        
+        $table = 'place_order/' . $this->type;
+        $prefix = strtoupper(substr($this->type, 0, 2));
+
+        $this->order['uid'] = Place::$uid;
+        $this->order['order_num'] = Dever::load('util', 'api')->createNumber($prefix, $table);
+        $this->order['notify'] = $table . '/pay.notify|' . Dever::input('p') . '|' . $this->order['order_num'];
+        $this->order['info'] = Dever::input('remark');
+
+        $result = array();
+        if ($this->order['pay_cash'] > 0) {
+            $result['pay'] = Dever::load('account', 'place')->pay($this->order);
+            if (isset($result['pay']['link']) && $result['pay']['link']) {
+                return $result;
+            }
+        } else {
+            $result['pay'] = true;
+        }
+        if ($result['pay']) {
+            $result['order_id'] = Dever::db($table)->insert($this->order);
+
+            if ($result['order_id']) {
+                # 使用优惠券
+                if ($this->coupon) {
+                    Dever::load('coupon', 'place_user')->use(1, $result['order_id'], $this->coupon);
+                }
+                # 使用钱包支付
+                if ($this->order['wallet_cash'] > 0) {
+                    if ($this->type == 'source') {
+                        $type = 11;
+                    } else {
+                        $type = 12;
+                    }
+                    Dever::load('wallet', 'place_user')->up($this->order['uid'], 2, $type, $result['order_id'], $this->order['wallet_cash']);
+                }
+                $result['order_num'] = $this->order['order_num'];
+                $this->success($result['order_id']);
+
+                if ($result['pay'] === true) {
+                    $this->notify(Dever::input('p'), $result['order_num'], 1);
+                }
+            }
+        }
+        return $result;
+    }
+
+    # 支付回调
+    public function notify($place, $order_num, $status, $body = array())
+    {
+        Dever::input('authorization', 'is_string', '入口码', $place);
+        $order = Dever::db('place_order/' . $this->type)->find(array('order_num' => $order_num));
+        if ($order && $order['status'] == 1) {
+            $this->callback($order, $status);
+        }
+    }
+}

+ 71 - 0
src/place/order/lib/Role/Pay.php

@@ -0,0 +1,71 @@
+<?php namespace Place_order\Lib\Role;
+use Dever;
+use Place;
+use Place_order\Lib\Pay as Core;
+class Pay extends Core
+{
+    protected $type = 'role';
+
+    # 获取明细
+    protected function getDetail($info)
+    {
+        $this->order['type'] = $info['type'];
+        $this->order['type_id'] = $info['id'];
+        $this->order['name'] = $info['name'];
+        $this->order['cash'] = $info['price'];
+        $this->order['num'] = 1;
+        $this->order['coupon_type'] = '2,' . $info['type'];
+        $this->order['coupon_type_id'] = $info['id'];
+
+        $this->detail[] = $this->order;
+    }
+
+    # 验证
+    protected function check(){}
+    # 下单成功
+    protected function success(){}
+    # 支付回调
+    protected function callback($order, $status)
+    {
+        if ($status == 1) {
+            $update['status'] = 2;
+        } else {
+            $update['status'] = 3;
+        }
+        
+        $update['pdate'] = time();
+        $state = Dever::db('role', 'place_order')->update($order['id'], $update);
+        if (!$state) {
+            return '订单更新失败';
+        }
+        if ($status == 1) {
+            $data = array('uid' => $order['uid'], 'type' => $order['type']);
+            $user = Dever::db('role', 'place_user')->find($data);
+            if ($order['type'] == 1) {
+                $table = 'vip';
+            } elseif ($order['type'] == 2) {
+                $table = 'saler';
+            } elseif ($order['type'] == 3) {
+                $table = 'agent';
+            }
+            $info = Dever::db($table, 'place')->find($order['type_id']);
+            if ($info) {
+                $data['type_id'] = $order['type_id'];
+                $data['edate'] = $info['day']*86400;
+                $date = time();
+                if ($user) {
+                    if ($user['status'] == 2 || $user['edate'] <= $date) {
+                        $data['edate'] += $date;
+                    } else {
+                        $data['edate'] += $user['edate'];
+                    }
+                    Dever::db('role', 'place_user')->update($user['id'], $data);
+                } else {
+                    $data['edate'] += $date;
+                    Dever::db('role', 'place_user')->insert($data);
+                }
+                Dever::db('info', 'place_user')->update($order['uid'], [$table . '_id' => $info['id']]);
+            }
+        }
+    }
+}

+ 0 - 0
src/place/order/lib/source/Cart.php → src/place/order/lib/Source/Cart.php


+ 3 - 16
src/place/order/lib/source/Express.php → src/place/order/lib/Source/Express.php

@@ -3,19 +3,6 @@ use Dever;
 use Place;
 class Express
 {
-    public function update($db, $data)
-    {
-        $order = Dever::db('source', 'place_order')->find($data['order_id']);
-        if ($order && $order['status'] <= 3) {
-            $auth = new \Manage\Lib\Auth();
-            $uid = $auth->uid;
-            $log['type'] = 2;
-            $log['uid'] = $uid;
-            $this->up($data['id'], $order['id'], $data['express_id'], $data['number'], $log);
-        }
-        return 'end';
-    }
-
     public function up($id, $order_id, $express_id, $number, $log = false)
     {
         $update['order_id'] = $order_id;
@@ -24,10 +11,10 @@ class Express
         if ($id) {
             $express = Dever::db('source_express', 'place_order')->find($id);
             if ($express) {
-                Dever::db('order_express', 'place_order')->update($express['id'], $update);
+                Dever::db('source_express', 'place_order')->update($express['id'], $update);
             }
         } else {
-            Dever::db('order_express', 'place_order')->insert($update);
+            Dever::db('source_express', 'place_order')->insert($update);
             Dever::db('source', 'place_order')->update($order_id, array('status' => 3, 'ddate' => time()));
         }
         if ($log) {
@@ -64,7 +51,7 @@ class Express
                     }
                 }
             } else {
-                $address = Dever::db('address', 'place')->find($address_id);
+                $address = Dever::db('address', 'place_user')->find($address_id);
                 list($info['log'], $order['status']) = $this->get($order, $info['express_id'], $info['number'], $address['phone'], false, $type);
             }
             $order['express'] = $info;

+ 0 - 0
src/place/order/lib/source/Log.php → src/place/order/lib/Source/Log.php


+ 277 - 0
src/place/order/lib/Source/Order.php

@@ -0,0 +1,277 @@
+<?php namespace Place_order\Lib\Source;
+use Dever;
+use Place;
+class Order
+{
+    # 获取订单信息
+    public function getInfo($info, $view = false)
+    {
+        if ($info['status'] == 1) {
+            $m = 3600;
+            # 支付倒计时
+            $info['time'] = time() - $info['cdate'];
+            if ($info['time'] >= $m) {
+                # 已过期,自动取消
+                $info['time'] = -1;
+                $this->cancel($info);
+                $info['status'] = 9;
+            } else {
+                $info['time'] = $m - $info['time'];
+            }
+        }
+        $info['scash'] = $info['cash'];
+        $info['cash'] = $info['cash'];
+        $info['detail'] = $this->getDetail($info['id']);
+        $info['info'] = '共' . intval($info['num']) . '件商品';
+        if ($view) {
+            $this->getView($info);
+        }
+        return $info;
+    }
+
+    # 获取订单里每个商品
+    public function getDetail($id)
+    {
+        $result = Dever::db('source_detail', 'place_order')->select(array('order_id' => $id), array('col' => 'id,name,pic,sku_name,sku_id,cash,num'));
+        if ($result) {
+            foreach ($result as &$v) {
+                $v['cash'] = Dever::load('price', 'place')->getText($v['cash'], 3);
+            }
+        }
+        return $result;
+    }
+
+    # 获取订单详情
+    public function getView(&$info)
+    {
+        # 收货地址
+        if ($info['address_id']) {
+            $info['address'] = Dever::load('address', 'place_user')->getInfo($info['address_id'], $info['uid']);
+        }
+        if (in_array($info['status'], array(3,4,5))) {
+            $info = Dever::load('source/express', 'place_order')->getInfo($info, $info['address_id']);
+            $info['status_name'] = Dever::db('source', 'place_order')->value('status', $info['status']);
+        }
+        $info['status_list'] = array
+        (
+            1 => array
+            (
+                'selected' => false,
+                'name' => '待付款',
+                'time' => $info['cdate_str'],
+            ),
+            2 => array
+            (
+                'selected' => false,
+                'name' => '待发货',
+                'time' => $info['pdate_str'] ?? '',
+            ),
+            3 => array
+            (
+                'selected' => false,
+                'name' => '待签收',
+                'time' => $info['ddate_str'] ?? '',
+            ),
+            4 => array
+            (
+                'selected' => false,
+                'name' => '待收货',
+                'time' => $info['qdate_str'] ?? '',
+            ),
+            5 => array
+            (
+                'selected' => false,
+                'name' => '已完成',
+                'time' => $info['fdate_str'] ?? '',
+            ),
+        );
+        foreach ($info['status_list'] as $k => &$status_list) {
+            if ($info['status'] >= $k) {
+                $status_list['selected'] = true;
+            }
+        }
+        if ($info['status'] == 1) {
+            $info['status_msg'] = '下单成功,待支付';
+        } elseif ($info['status'] == 2) {
+            $info['status_msg'] = '支付成功,待发货';
+        } elseif ($info['status'] == 3) {
+            $info['status_msg'] = '配送中,等待签收';
+        } elseif ($info['status'] == 4) {
+            $info['status_msg'] = '已签收,等待确认';
+        } elseif ($info['status'] == 5 || $info['status'] == 6) {
+            $info['status_msg'] = '订单已完成';
+        } elseif ($info['status'] > 6) {
+            $info['status_msg'] = '订单已取消';
+        }
+        
+        $info['refund'] = false;
+        $info['refund_list'] = Dever::db('source_refund', 'place_order')->select(array('order_id' => $info['id']));
+        if ($info['refund_list']) {
+            foreach ($info['refund_list'] as $k => $v) {
+                if ($v['status'] < 4) {
+                    $info['refund'] = $v;
+                }
+            }
+        }
+        if ($info['refund']) {
+            if ($info['refund']['status'] > 2) {
+                $info['refund'] = Dever::load('source/express', 'place_order')->getInfo($info['refund'], $info['address_id'], 2);
+            }
+            $info['refund']['cdate_str'] = date('Y-m-d H:i:s', $info['refund']['cdate']);
+            if (isset($info['refund']['sdate']) && $info['refund']['sdate']) {
+                $info['refund']['sdate_str'] = date('Y-m-d H:i:s', $info['refund']['sdate']);
+            }
+            if (isset($info['refund']['ddate']) && $info['refund']['ddate']) {
+                $info['refund']['ddate_str'] = date('Y-m-d H:i:s', $info['refund']['ddate']);
+            }
+            if (isset($info['refund']['fdate']) && $info['refund']['fdate']) {
+                $info['refund']['fdate_str'] = date('Y-m-d H:i:s', $info['refund']['fdate']);
+            }
+            if ($info['refund']['type'] == 1) {
+                $info['refund_status_list'] = array
+                (
+                    1 => array
+                    (
+                        'selected' => false,
+                        'name' => '退货退款',
+                        'time' => $info['refund']['cdate_str'],
+                    ),
+                    2 => array
+                    (
+                        'selected' => false,
+                        'name' => '已审核',
+                        'time' => $info['refund']['sdate_str'] ?? '',
+                    ),
+                    3 => array
+                    (
+                        'selected' => false,
+                        'name' => '买家已发货',
+                        'time' => $info['refund']['ddate_str'] ?? '',
+                    ),
+                    4 => array
+                    (
+                        'selected' => false,
+                        'name' => '已完成',
+                        'time' => $info['refund']['fdate_str'] ?? '',
+                    ),
+                );
+            }
+            if ($info['refund']['type'] == 2) {
+                $info['refund_status_list'] = array
+                (
+                    1 => array
+                    (
+                        'selected' => false,
+                        'name' => '仅退款',
+                        'time' => $info['cdate_str'],
+                    ),
+                    2 => array
+                    (
+                        'selected' => false,
+                        'name' => '已审核',
+                        'time' => $info['sdate_str'] ?? '',
+                    ),
+                    4 => array
+                    (
+                        'selected' => false,
+                        'name' => '已完成',
+                        'time' => $info['fdate_str'] ?? '',
+                    ),
+                );
+            }
+            foreach ($info['refund_status_list'] as $k => $v) {
+                if ($info['refund']['status'] >= $k) {
+                    $info['refund_status_list'][$k]['selected'] = true;
+                }
+            }
+        }
+    }
+
+    # 取消订单
+    public function cancel($order, $status = 9)
+    {
+        if ($order['status'] == 1) {
+            $state = Dever::db('source', 'place_order')->update($order['id'], array('status' => $status, 'fdate' => time()));
+            if ($state) {
+                # 恢复库存
+                $this->resell($order['id']);
+            }
+            return 'ok';
+        }
+    }
+
+    # 支付成功
+    public function success($order, $status)
+    {
+        if ($status == 1) {
+            $update['status'] = 2;
+            $msg = '支付成功';
+            
+        } else {
+            $update['status'] = 7;
+            $msg = '支付失败';
+        }
+        $update['pdate'] = time();
+        $state = Dever::db('source', 'place_order')->update($order['id'], $update);
+        Dever::load('source/log', 'place_order')->up(1, $order['uid'], $data['order_id'], $msg);
+        if ($state && $update['status'] == 7) {
+            # 恢复库存
+            $this->resell($order['id']);
+        }
+        return $state;
+    }
+
+    # 确认收货
+    public function finish_commit(){}
+    public function finish($type = 1, $order, $yes = false)
+    {
+        if ($yes || ($order['status'] >= 3 && $order['status'] <= 6)) {
+            if ($type == 1) {
+                $uid = $order['uid'];
+            } else {
+                $uid = '';
+            }
+            # 检查有没有退款
+            $refund = Dever::db('source_refund', 'place_order')->find(array('order_id' => $order['id'], 'refund_status' => 1));
+            $status = 5;
+            if ($refund) {
+                $status = 6;
+            }
+            Dever::db('source', 'place_order')->update($order['id'], array('status' => $status, 'fdate' => time()));
+            Dever::load('source/log', 'place_order')->up($type, $uid, $order['id'], '确认收货,订单完成');
+
+            # 增加次数
+            if ($status) {
+                $detail = Dever::db('source_detail', 'place_order')->select(array('order_id' => $order['id']));
+                if ($detail) {
+                    foreach ($detail as $k => $v) {
+                        $refund_detail = Dever::db('source_refund_detail', 'place_order')->select(array('detail_id' => $v['id'], 'refund_status' => 1));
+                        $unum = $v['unum'];
+                        if ($refund_detail) {
+                            foreach ($refund_detail as $v1) {
+                                $unum -= $v1['num'];
+                            }
+                        }
+                        if ($unum > 0) {
+                            Dever::load('source/user', 'place_order')->up($order['uid'], $v['source_id'], $v['sku_id'], 1, $unum);
+                        }
+                    }
+                }
+
+                # 获取当前用户上级 增加佣金 获取实付款
+                //Dever::load('log', 'place_score')->add(Place::$uid, '推广', '购买');
+            }
+        }
+    }
+
+    # 恢复库存
+    public function resell($id)
+    {
+        $result = Dever::db('source_detail', 'place_order')->select(array('order_id' => $id));
+        if ($result) {
+            foreach ($result as $v) {
+                $state = Dever::load('stock', 'place_source')->sell($v['info_id'], $v['sku_id'], $v['num']*-1);
+            }
+        }  
+    }
+}

+ 113 - 0
src/place/order/lib/Source/Pay.php

@@ -0,0 +1,113 @@
+<?php namespace Place_order\Lib\Source;
+use Dever;
+use Place;
+use Place_order\Lib\Pay as Core;
+class Pay extends Core
+{
+    protected $type = 'source';
+    # 获取明细
+    protected function getDetail($info)
+    {
+        $source = Dever::db('info', 'place_source')->find(array('id' => $info['id']), array('col' => 'id,name,pic,cate_id,channel_id,cate_parent_id,type,have_vip'));
+        if (!$source) {
+            Dever::error('资源不存在');
+        }
+        $sku = Dever::load('sku', 'api')->getList(array('info_id' => $source['id']), $info['sku_id'], 'place_source');
+        if ($sku['info']) {
+            $cate = Dever::load('cate', 'place_source')->getInfo($source['cate_id']);
+            $sku = Dever::load('price', 'place_source')->get($sku['info'], $cate, $info['num']);
+        } else {
+            Dever::error('规格不存在');
+        }
+        $have = Dever::load('price', 'place_source')->getHave($source);
+        if ($have['status'] != 1) {
+            Dever::error('专享资源无法购买');
+        }
+        
+        if (!$sku['pic']) {
+            $source['pic'] = explode(',', $source['pic']);
+            $sku['pic'] = $source['pic'][0];
+        }
+
+        $this->detail[] = array
+        (
+            'source_id' => $source['id'],
+            'sku_id' => $sku['id'],
+            'coupon_type' => '1,'.$source['channel_id'].','.$source['cate_parent_id'],
+            'coupon_type_id' => $source['id'],
+            'name' => $source['name'],
+            'sku_name' => $sku['name'],
+            'pic' => $sku['pic'],
+            'cash' => Dever::number($sku['price']),
+            'num' => $sku['buy_num'],
+            'unum' => $sku['unum'],
+        );
+        if (count($this->detail) < 3) {
+            $this->order['name'][$source['id']] = $source['name'];
+        }
+        $this->order['cash'] += $sku['price'] * $sku['buy_num'];
+        $this->order['num'] += $sku['buy_num'];
+    }
+
+    # 下单成功
+    protected function success($order_id)
+    {
+        Dever::load('source/log', 'place_order')->up(1, $this->order['uid'], $order_id, '下单成功');
+        foreach ($this->detail as $v) {
+            $v['order_id'] = $order_id;
+            Dever::db('source_detail', 'place_order')->insert($v);
+        }
+    }
+
+    # 支付成功回调
+    protected function callback($order, $status)
+    {
+        if ($status == 1) {
+            $update['status'] = 2;
+            $msg = '支付成功';
+        } else {
+            $update['status'] = 7;
+            $msg = '支付失败';
+        }
+        $update['pdate'] = time();
+        $state = Dever::db('source', 'place_order')->update($order['id'], $update);
+        Dever::load('source/log', 'place_order')->up(1, $order['uid'], $order['id'], $msg);
+        if ($state && $update['status'] == 7) {
+            # 恢复库存
+            $this->resell($order['id']);
+        } elseif ($state && $update['status'] == 2 && $order['source_type'] == 3) {
+            Dever::load('source/order', 'place_order')->finish(1, $order, true);
+        } else {
+            //Dever::load('log', 'place_score')->add(Place::$uid, '推广', '购买', 2);
+        }
+    }
+
+    # 验证库存
+    protected function check()
+    {
+        foreach ($this->detail as $v) {
+            $stock = Dever::load('stock', 'place_source')->yue($v['source_id'], $v['sku_id']);
+            if ($stock !== false) {
+                if ($stock < $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']);
+                    if (!$state) {
+                        Dever::error('库存不足');
+                    }
+                }
+            }
+        }
+    }
+
+    # 恢复库存
+    protected function resell($id)
+    {
+        $result = Dever::db('source_detail', 'place_order')->select(array('order_id' => $id));
+        if ($result) {
+            foreach ($result as $v) {
+                $state = Dever::load('stock', 'place_source')->sell($v['source_id'], $v['sku_id'], $v['num']*-1);
+            }
+        }  
+    }
+}

+ 143 - 0
src/place/order/lib/Source/Refund.php

@@ -0,0 +1,143 @@
+<?php namespace Place_order\Lib\Source;
+use Dever;
+use Place;
+class Refund
+{
+    # 买家发货
+    public function express($order, $refund, $express_id, $number)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($refund['id']);
+        if ($refund['status'] == 2) {
+            $update['status'] = 3;
+            $update['ddate'] = time();
+            $where = array('source_refund_id' => $refund['id']);
+            $info = Dever::db('source_refund_express', 'place_order')->find($where);
+            if (!$info) {
+                $where['order_id'] = $order['id'];
+                $where['express_id'] = $express_id;
+                $where['number'] = $number;
+                Dever::db('source_refund_express', 'place_order')->insert($where);
+                Dever::load('source/log', 'place_order')->up(1, $order['uid'], $order['id'], '退款:买家已发货');
+            }
+            Dever::db('source_refund', 'place_order')->update($refund['id'], $update);
+        }
+    }
+
+    # 完成退款 如果是支付订单,原路退回
+    public function finish($order, $refund)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($refund['id']);
+        if ($refund['status'] == 2 || $refund['status'] == 3) {
+            $update['status'] = 4;
+            $update['fdate'] = time();
+            $update['refund_status'] = 1;
+            Dever::db('source_refund', 'place_order')->update($refund['id'], $update);
+            Dever::load('source/log', 'place_order')->up(1, $order['uid'], $order['id'], '退款:已完成退款');
+
+            # 检测订单是否全都退了
+            $refund = Dever::db('source_refund', 'place_order')->select(array('order_id' => $order['id']));
+            $cash = 0;
+            foreach ($refund as $k => $v) {
+                $cash += $v['cash'];
+            }
+
+            if ($cash >= $order['cash']) {
+                $refund = Dever::db('source', 'place_order')->update($order['id'], array('status' => 8, 'fdate' => time(), 'refund_status' => 2));
+
+                Dever::load('source/log', 'place_order')->up(1, $order['uid'], $order['id'], '订单已退款');
+                # 恢复库存
+                Dever::load('source', 'place_order')->resell($order['id']);
+            }
+
+            # 判断是否支付订单,如果是,走退款流程
+            if ($order['type'] == 1) {
+
+            }
+        }
+    }
+
+    public function up($detail, $order, $type, $desc_type, $cash, $desc, $log = false)
+    {
+        if ($detail) {
+            foreach ($detail as $k => $v) {
+                $info = Dever::db('source_detail', 'place_order')->find($v['detail_id']);
+                $refund = Dever::db('source_refund_detail', 'place_order')->find(array('detail_id' => $v['detail_id'], 'refund_status' => 1), array('col' => 'sum(num) as num'));
+                if ($refund && $refund['num']) {
+                    $info['num'] -= $refund['num'];
+                }
+                if ($v['num'] > $info['num']) {
+                    Dever::error('退款数量不能大于下单商品数量');
+                }
+            }
+        }
+        $where = array('order_id' => $order['id'], 'refund_status' => 1);
+        $refund = Dever::db('source_refund', 'place_order')->find($where, array('col' => 'sum(cash) as cash'));
+        if ($refund && $refund['cash']) {
+            $order['cash'] -= $refund['cash'];
+        }
+        if ($cash > $order['cash']) {
+            Dever::error('退款金额不能大于订单金额');
+        }
+        $update = $where;
+        $update['refund_status'] = 2;
+        $update['status'] = array('<', '5');
+        $refund = Dever::db('source_refund', 'place_order')->find($update);
+        $update['type'] = $type;
+        $update['desc_type'] = $desc_type;
+        $update['cash'] = $cash;
+        $update['desc'] = $desc;
+        $update['status'] = 1;
+        if ($refund) {
+            Dever::error('您有退款进行中,请先处理');
+        } else {
+            $id = Dever::db('source_refund', 'place_order')->insert($update);
+            if ($id) {
+                Dever::db('source', 'place_order')->update($order['id'], array('refund_status' => 1));
+                if ($detail) {
+                    foreach ($detail as $k => $v) {
+                        $v['source_refund_id'] = $id;
+                        Dever::db('source_refund_detail', 'place_order')->insert($v);
+                    }
+                }
+                if ($log) {
+                    $type = $log['type'];
+                    $uid = $log['uid'];
+                    $msg = '退款:提交退款申请单';
+                    Dever::load('source/log', 'place_order')->up($type, $uid, $order['id'], $msg);
+                }
+            }
+        }
+    }
+
+    # 获取信息
+    public function getList($order_id)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->select(array('order_id' => $order_id));
+        if ($refund) {
+            foreach ($refund as &$v) {
+                $v = $this->getInfo($v);
+            }
+        }
+        return $refund;
+    }
+
+    # 获取信息
+    public function getInfo($info)
+    {
+        print_r($info);die;
+        if ($info['type'] == 1) {
+            $user = Dever::db('info', 'place_user')->find($info['type_id']);
+        } elseif ($info['type'] == 2) {
+            $user = Dever::db('user', 'sector')->find($info['type_id']);
+        } elseif ($info['type'] == 3) {
+            $user = Dever::db('supplier', 'place')->find($info['type_id']);
+        } else {
+            $user['name'] = $user['mobile'] = '-';
+        }
+        $info['type'] = Dever::db('source_log', 'place_order')->value('type', $info);
+        $info['name'] = $user['name'];
+        $info['mobile'] = $user['mobile'];
+        $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
+        return $info;
+    }
+}

+ 89 - 0
src/place/order/lib/Source/User.php

@@ -0,0 +1,89 @@
+<?php namespace Place_order\Lib\Source;
+use Dever;
+use Place;
+class User
+{
+    public function up_commit(){}
+    public function up($uid, $source_id, $sku_id, $type, $amount)
+    {
+        if ($amount <= 0) {
+            return true;
+        }
+        $data['uid'] = $uid;
+        $data['source_id'] = $source_id;
+        $data['sku_id'] = $sku_id;
+        $data['type'] = $type;
+        $data['amount'] = $amount;
+
+        $state = Dever::db('user_source_log', 'place_order')->insert($data);
+        if ($state) {
+            $this->sync($uid, $source_id, $sku_id);
+        }
+        return $state;
+    }
+
+    # 扣减使用次数
+    public function use($uid, $source_id, $sku_id, $amount = 1)
+    {
+        $this->check($uid, $source_id, $sku_id, $amoun);
+        return $this->up($uid, $source_id, $sku_id, 2, $amount);
+    }
+
+    # 检测余额
+    public function check($uid, $source_id, $sku_id, $amount)
+    {
+        if ($amount <= 0) {
+            Dever::error('数量不正确');
+        }
+        $info = $this->get($uid, $source_id, $sku_id);
+        if (!$info) {
+            Dever::error('余额不足');
+        }
+        $yue = $info['unum_balance'];
+        if ($yue < $amount) {
+            Dever::error('余额不足');
+        }
+    }
+
+    # 获取余额
+    public function get($uid, $source_id, $sku_id)
+    {
+        $data['uid'] = $uid;
+        $data['source_id'] = $source_id;
+        $data['sku_id'] = $sku_id;
+        $info = Dever::db('user_source', 'place_order')->find($data);
+        return $info;
+    }
+
+    # 更新余额
+    public function sync($uid, $source_id, $sku_id)
+    {
+        $where = array
+        (
+            'uid' => $uid,
+            'source_id' => $source_id,
+            'sku_id' => $sku_id,
+            'type' => 1,
+        );
+        $data['unum_total'] = Dever::db('user_source_log', 'place_order')->sum($where, 'amount');
+        $where['type'] = 2;
+        $data['unum_used'] = Dever::db('user_source_log', 'place_order')->sum($where, 'amount');
+        $data['unum_balance'] = $data['unum_total'] - $data['unum_used'];
+        return Dever::db('user_source', 'place_order')->update(['uid' => $uid, 'source_id' => $source_id, 'sku_id' => $sku_id], $data);
+
+        /*
+        $data['uid'] = $uid;
+        $data['source_id'] = $source_id;
+        $data['sku_id'] = $sku_id;
+        $info = Dever::db('user_source', 'place_order')->find($data);
+        if (!$info) {
+            $data['unum_total'] = $amount;
+            $data['unum_balance'] = array('unum_total', '-', 'unum_used');
+            $state = Dever::db('user_source', 'place_order')->insert($data);
+        } else {
+            $data['unum_total'] = array('+', $amount);
+            $data['unum_balance'] = array('unum_total', '-', 'unum_used');
+            $state = Dever::db('user_source', 'place_order')->update($info['id'], $data);
+        }*/
+    }
+}

+ 26 - 0
src/place/order/lib/Source/Virtual.php

@@ -0,0 +1,26 @@
+<?php namespace Place_order\Lib\Source;
+use Dever;
+use Place;
+class Virtual
+{
+    public function up($id, $order_id, $content, $log = false)
+    {
+        $update['order_id'] = $order_id;
+        $update['content'] = $content;
+        if ($id) {
+            $info = Dever::db('source_virtual', 'place_order')->find($id);
+            if ($info) {
+                Dever::db('source_virtual', 'place_order')->update($info['id'], $update);
+            }
+        } else {
+            Dever::db('source_virtual', 'place_order')->insert($update);
+            Dever::db('source', 'place_order')->update($order_id, array('status' => 4, 'ddate' => time()));
+        }
+        if ($log) {
+            $type = $log['type'];
+            $uid = $log['uid'];
+            $msg = '已发货:' . $update['content'];
+            Dever::load('source/log', 'place_order')->up($type, $uid, $order_id, $msg);
+        }
+    }
+}

+ 0 - 547
src/place/order/lib/source/Order.php

@@ -1,547 +0,0 @@
-<?php namespace Place_order\Lib\Source;
-use Dever;
-use Place;
-class Order
-{
-    # 获取订单信息
-    public function getInfo($info, $view = false)
-    {
-        if ($info['status'] == 1) {
-            $m = 3600;
-            # 支付倒计时
-            $info['time'] = time() - $info['cdate'];
-            if ($info['time'] >= $m) {
-                # 已过期,自动取消
-                $info['time'] = -1;
-                $this->cancel($info);
-                $info['status'] = 9;
-            } else {
-                $info['time'] = $m - $info['time'];
-            }
-        }
-        $info['scash'] = $info['cash'];
-        $info['cash'] = $info['cash'];
-        $info['detail'] = $this->getDetail($info['id']);
-        $info['info'] = '共' . intval($info['num']) . '件商品';
-        if ($view) {
-            $this->getView($info);
-        }
-        return $info;
-    }
-
-    # 获取订单里每个商品
-    public function getDetail($id)
-    {
-        $result = Dever::db('source_detail', 'place_order')->select(array('order_id' => $id), array('col' => 'id,name,pic,sku_name,sku_id,cash,num'));
-        if ($result) {
-            foreach ($result as &$v) {
-                $v['cash'] = Dever::load('price', 'place')->getText($v['cash'], 3);
-            }
-        }
-        return $result;
-    }
-
-    # 获取订单详情
-    public function getView(&$info)
-    {
-        # 收货地址
-        $info['address'] = Dever::load('address', 'place')->getInfo($info['address_id'], $info['uid']);
-        # 运费
-        $info['yun'] = Dever::load('price', 'place')->getText(0, 3);
-        if (in_array($info['status'], array(3,4,5))) {
-            $info = Dever::load('express', 'goods')->getInfo($info, $info['address_id']);
-            $info['status_name'] = Dever::db('order', 'goods')->value('status', $info['status']);
-        }
-        $info['status_list'] = array
-        (
-            1 => array
-            (
-                'selected' => false,
-                'name' => '待付款',
-                'time' => $info['cdate_str'],
-            ),
-            2 => array
-            (
-                'selected' => false,
-                'name' => '待发货',
-                'time' => $info['pdate_str'] ?? '',
-            ),
-            3 => array
-            (
-                'selected' => false,
-                'name' => '待签收',
-                'time' => $info['ddate_str'] ?? '',
-            ),
-            4 => array
-            (
-                'selected' => false,
-                'name' => '待收货',
-                'time' => $info['qdate_str'] ?? '',
-            ),
-            5 => array
-            (
-                'selected' => false,
-                'name' => '已完成',
-                'time' => $info['fdate_str'] ?? '',
-            ),
-        );
-        foreach ($info['status_list'] as $k => &$status_list) {
-            if ($info['status'] >= $k) {
-                $status_list['selected'] = true;
-            }
-        }
-        if ($info['status'] == 1) {
-            $info['status_msg'] = '下单成功,待支付';
-        } elseif ($info['status'] == 2) {
-            $info['status_msg'] = '支付成功,待发货';
-        } elseif ($info['status'] == 3) {
-            $info['status_msg'] = '配送中,等待签收';
-        } elseif ($info['status'] == 4) {
-            $info['status_msg'] = '已签收,等待确认';
-        } elseif ($info['status'] == 5 || $info['status'] == 6) {
-            $info['status_msg'] = '订单已完成';
-        } elseif ($info['status'] > 6) {
-            $info['status_msg'] = '订单已取消';
-        }
-        
-        $info['refund'] = false;
-        $info['refund_list'] = Dever::db('order_refund', 'goods')->select(array('order_id' => $info['id']));
-        if ($info['refund_list']) {
-            foreach ($info['refund_list'] as $k => $v) {
-                if ($v['status'] < 4) {
-                    $info['refund'] = $v;
-                }
-            }
-        }
-        if ($info['refund']) {
-            if ($info['refund']['status'] > 2) {
-                $info['refund'] = Dever::load('express', 'goods')->getInfo($info['refund'], $info['address_id'], 2);
-            }
-            $info['refund']['cdate_str'] = date('Y-m-d H:i:s', $info['refund']['cdate']);
-            if (isset($info['refund']['sdate']) && $info['refund']['sdate']) {
-                $info['refund']['sdate_str'] = date('Y-m-d H:i:s', $info['refund']['sdate']);
-            }
-            if (isset($info['refund']['ddate']) && $info['refund']['ddate']) {
-                $info['refund']['ddate_str'] = date('Y-m-d H:i:s', $info['refund']['ddate']);
-            }
-            if (isset($info['refund']['fdate']) && $info['refund']['fdate']) {
-                $info['refund']['fdate_str'] = date('Y-m-d H:i:s', $info['refund']['fdate']);
-            }
-            if ($info['refund']['type'] == 1) {
-                $info['refund_status_list'] = array
-                (
-                    1 => array
-                    (
-                        'selected' => false,
-                        'name' => '退货退款',
-                        'time' => $info['refund']['cdate_str'],
-                    ),
-                    2 => array
-                    (
-                        'selected' => false,
-                        'name' => '已审核',
-                        'time' => $info['refund']['sdate_str'] ?? '',
-                    ),
-                    3 => array
-                    (
-                        'selected' => false,
-                        'name' => '买家已发货',
-                        'time' => $info['refund']['ddate_str'] ?? '',
-                    ),
-                    4 => array
-                    (
-                        'selected' => false,
-                        'name' => '已完成',
-                        'time' => $info['refund']['fdate_str'] ?? '',
-                    ),
-                );
-            }
-            if ($info['refund']['type'] == 2) {
-                $info['refund_status_list'] = array
-                (
-                    1 => array
-                    (
-                        'selected' => false,
-                        'name' => '仅退款',
-                        'time' => $info['cdate_str'],
-                    ),
-                    2 => array
-                    (
-                        'selected' => false,
-                        'name' => '已审核',
-                        'time' => $info['sdate_str'] ?? '',
-                    ),
-                    4 => array
-                    (
-                        'selected' => false,
-                        'name' => '已完成',
-                        'time' => $info['fdate_str'] ?? '',
-                    ),
-                );
-            }
-            foreach ($info['refund_status_list'] as $k => $v) {
-                if ($info['refund']['status'] >= $k) {
-                    $info['refund_status_list'][$k]['selected'] = true;
-                }
-            }
-        }
-    }
-
-    # 取消订单
-    public function cancel($order, $status = 9)
-    {
-        if ($order['status'] == 1) {
-            $state = Dever::db('order', 'goods')->update($order['id'], array('status' => $status, 'fdate' => time()));
-            if ($state) {
-                # 恢复库存
-                $this->resell($order['id']);
-            }
-            return 'ok';
-        }
-    }
-
-    # 支付成功
-    public function success($order, $status)
-    {
-        if ($status == 1) {
-            $update['status'] = 2;
-            $msg = '支付成功';
-            
-        } else {
-            $update['status'] = 7;
-            $msg = '支付失败';
-        }
-        $update['pdate'] = time();
-        $state = Dever::db('order', 'goods')->update($order['id'], $update);
-        Dever::load('log', 'goods')->up(1, $order['uid'], $data['order_id'], $msg);
-        if ($state && $update['status'] == 7) {
-            # 恢复库存
-            $this->resell($order['id']);
-        }
-        return $state;
-    }
-
-    # 确认收货
-    public function finish_commit(){}
-    public function finish($type = 1, $order)
-    {
-        if ($order['status'] >= 3 && $order['status'] <= 6) {
-            if ($type == 1) {
-                $uid = $order['uid'];
-            } else {
-                $uid = '';
-            }
-            # 检查有没有退款
-            $refund = Dever::db('order_refund', 'goods')->find(array('order_id' => $order['id'], 'refund_status' => 1));
-            $status = 5;
-            if ($refund) {
-                $status = 6;
-            }
-            Dever::db('order', 'goods')->update($order['id'], array('status' => $status, 'fdate' => time()));
-            Dever::load('log', 'goods')->up($type, $uid, $order['id'], '确认收货,订单完成');
-        }
-    }
-
-    # 恢复库存
-    public function resell($id)
-    {
-        $result = Dever::db('order_detail', 'goods')->select(array('order_id' => $id));
-        if ($result) {
-            foreach ($result as $v) {
-                $state = Dever::load('stock', 'goods')->sell($v['info_id'], $v['sku_id'], $v['num']*-1);
-            }
-        }  
-    }
-
-    # 后台详情页
-    public function showManageView($page)
-    {
-        # 这里获取基本信息
-        $db = Dever::db('order', 'goods');
-        $address = Dever::load('address', 'place')->getInfo($page->info['address_id'], $page->info['uid']);
-        $user = Dever::db('member', 'place')->find($page->info['uid']);
-        $desc = '';
-        $status = $db->value('status', $page->info);
-        if ($page->info['info']) {
-            $desc = '备注:' . $page->info['info'];
-        }
-        $timeline = array();
-        $page->info['cdate_str'] = date('Y-m-d H:i:s', $page->info['cdate']);
-        if (isset($page->info['pdate']) && $page->info['pdate']) {
-            $page->info['pdate_str'] = date('Y-m-d H:i:s', $page->info['pdate']);
-        }
-        if (isset($page->info['ddate']) && $page->info['ddate']) {
-            $page->info['ddate_str'] = date('Y-m-d H:i:s', $page->info['ddate']);
-        }
-        if (isset($page->info['qdate']) && $page->info['qdate']) {
-            $page->info['qdate_str'] = date('Y-m-d H:i:s', $page->info['qdate']);
-        }
-        if (isset($page->info['fdate']) && $page->info['fdate']) {
-            $page->info['fdate_str'] = date('Y-m-d H:i:s', $page->info['fdate']);
-        }
-        $this->getView($page->info);
-
-        foreach ($page->info['status_list'] as $k => $v) {
-            $v['name'] = '['.$v['name'].']';
-            if ($k == 1) {
-                $v['name'] .= ' 下单人:' . $user['name'] . '('.$user['mobile'].')' . ' 付款:' . $page->info['cash'] . '元 '. $desc;
-            } elseif ($k == 2) {
-                $v['name'] .= ' 收货地址:' . $address['full'];
-            } elseif ($k == 3) {
-                if (isset($page->info['express'])) {
-                    $v['name'] .= ' 已发货:' . $page->info['express']['name'] . ',' . $page->info['express']['number'];
-                }
-            } elseif ($k == 4) {
-                if (isset($page->info['express']['log'][0])) {
-                    $v['name'] .= ' ' . $page->info['express']['log'][0]['status'];
-                }
-            } elseif ($k == 5 && $page->info['status'] > 6) {
-                $v['name'] .= ' 订单'.$status.'';
-            }
-            if ($v['selected']) {
-                $v['hollow'] = true;
-                $v['color'] = '#0bbd87';
-                $v['type'] = 'primary';
-                $v['size'] = 'large';
-            }
-            $timeline[] = $v;
-        }
-
-        $button = array();
-
-        if ($page->info['status'] == 2) {
-            $button[] = array
-            (
-                'name' => '修改收货信息',
-                'type' => 'fastedit',
-                'path' => 'sector_place_order/goods_order_address',
-                'row' => array
-                (
-                    'id' => $page->info['id'],
-                ),
-            );
-            $button[] = array
-            (
-                'name' => '发货',
-                # fastedit、fastadd、oper、api、link、route
-                'type' => 'fastadd',
-                'path' => 'sector_place_order/goods_order_express',
-                'row' => array
-                (
-                    'id' => $page->info['id'],
-                ),
-                'param' => array
-                (
-                    'order_id' => $page->info['id'],
-                ),
-            );
-        } elseif ($page->info['status'] == 3 && isset($express)) {
-            $button[] = array
-            (
-                'name' => '修改快递单号',
-                # fastedit、fastadd、oper、api、link、route
-                'type' => 'fastedit',
-                'path' => 'sector_place_order/goods_order_express',
-                'row' => array
-                (
-                    'id' => $express['id'],
-                ),
-                'param' => array
-                (
-                    'order_id' => $page->info['id'],
-                ),
-            );
-        }
-        if (!$page->info['refund'] && $page->info['status'] >= 2 && $page->info['status'] < 7) {
-            $button[] = array
-            (
-                'name' => '退款',
-                'type' => 'fastadd',
-                'path' => 'sector_place_order/goods_order_refund',
-                'row' => array
-                (
-                    'id' => $page->info['id'],
-                ),
-                'param' => array
-                (
-                    'order_id' => $page->info['id'],
-                ),
-            );
-        }
-        $desc = '';
-        if ($page->info['refund']) {
-            $desc = '[退款中]';
-            $refund = array();
-            foreach ($page->info['refund_status_list'] as $k => $v) {
-                $v['name'] = '['.$v['name'].']';
-                if ($k == 1) {
-                    $v['name'] .= ' 申请原因:' . Dever::db('order_refund', 'goods')->value('desc_type', $page->info['refund']['desc_type']) . ' 申请说明:' . $page->info['refund']['desc'];
-                } elseif ($k == 2) {
-                    $v['name'] .= ' 审核备注:' . $page->info['refund']['audit_desc'];
-                } elseif ($k == 3) {
-                    if (isset($page->info['refund']['express'])) {
-                        $v['name'] .= ' 已发货:' . $page->info['refund']['express']['name'] . ',' . $page->info['refund']['express']['number'];
-                    }
-                }
-                if ($v['selected']) {
-                    $v['hollow'] = true;
-                    $v['color'] = 'red';
-                    $v['type'] = 'primary';
-                    $v['size'] = 'large';
-                }
-                $refund[] = $v;
-            }
-            $content[] = array
-            (
-                'name' => '退款进度',
-                'type' => 'timeline',
-                'content' => $refund,
-            );
-            $button = array();
-            if ($page->info['refund']['status'] == 1) {
-                $button[] = array
-                (
-                    'name' => '退款审核',
-                    'type' => 'fastedit',
-                    'path' => 'sector_place_order/goods_order_refund_audit',
-                    'row' => array
-                    (
-                        'id' => $page->info['refund']['id'],
-                    ),
-                    'param' => array
-                    (
-                        'order_id' => $page->info['id'],
-                    ),
-                );
-            }
-        }
-
-        $content[] = array
-        (
-            'name' => '订单进度' . $desc,
-            'type' => 'timeline',
-            'content' => $timeline,
-        );
-
-        $info[] = array
-        (
-            # 类型,desc描述 table表格,表格有head和body即可
-            'type' => 'desc',
-            'name' => $page->info['order_num'],
-            # 每行展示数量
-            'column' => 1,
-            # 是否有边框
-            'border' => true,
-            # 排列方向:horizontal横向 vertical纵向
-            'direction' => 'horizontal',
-            # 右侧按钮
-            'button' => $button,
-            # 具体内容
-            'content' => $content,
-        );
-
-        $detail = Dever::db('order_detail', 'goods')->select(array('order_id' => $page->info['id']));
-        if ($detail) {
-            foreach ($detail as &$v) {
-                $v['status'] = '正常';
-            }
-        }
-
-        $log = Dever::load('log', 'goods')->getList($page->info['id']);
-        
-        $tab = array
-        (
-            'active' => 't1',
-            'content' => array
-            (
-                't1' => array
-                (
-                    'name' => '商品清单',
-                    'type' => 'table',
-                    'border' => true,
-                    #'height' => '200',
-                    'head' => array
-                    (
-                        array
-                        (
-                            'key' => 'name',
-                            'name' => '名称',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'sku_name',
-                            'name' => '规格',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'cash',
-                            'name' => '金额',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'num',
-                            'name' => '数量',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'status',
-                            'name' => '状态',
-                            'fixed' => 'fixed',
-                        ),
-                    ),
-                    'button' => array(),
-                    'body' => $detail,
-                ),
-
-                't2' => array
-                (
-                    'name' => '操作记录',
-                    'type' => 'table',
-                    'border' => true,
-                    #'height' => '200',
-                    'head' => array
-                    (
-                        array
-                        (
-                            'key' => 'type',
-                            'name' => '身份',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'name',
-                            'name' => '名称',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'mobile',
-                            'name' => '联系电话',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'desc',
-                            'name' => '详情',
-                            'fixed' => 'fixed',
-                        ),
-                        array
-                        (
-                            'key' => 'cdate_str',
-                            'name' => '时间',
-                            'fixed' => 'fixed',
-                        ),
-                    ),
-                    'button' => array(),
-                    'body' => $log,
-                ),
-            )
-        );
-        
-        return array('info' => $info, 'tab' => $tab);
-    }
-}

+ 0 - 184
src/place/order/lib/source/Refund.php

@@ -1,184 +0,0 @@
-<?php namespace Place_order\Lib\Source;
-use Dever;
-use Place;
-class Refund
-{
-    # 后台提交
-    public function update($db, $data)
-    {
-        $detail = Dever::input('place_source/order_refund_detail');
-        $order = Dever::db('order', 'place_source')->find($data['order_id']);
-        if ($order && $order['type'] == 1 && $order['status'] <= 4) {
-            $auth = new \Manage\Lib\Auth();
-            $uid = $auth->uid;
-            $log['type'] = 2;
-            $log['uid'] = $uid;
-            $this->up($detail, $order, $data['type'], $data['desc_type'], $data['cash'], $data['desc'], $log);
-        }
-        return 'end';
-    }
-
-    # 后台审核
-    public function audit($db, $data)
-    {
-        $refund = Dever::db('order_refund', 'place_source')->find($data['id']);
-        if ($refund['status'] == 1) {
-            if ($data['audit'] == 1) {
-                $refund['status'] = $update['status'] = 2;
-                $update['sdate'] = time();
-            } else {
-                $update['status'] = 5;
-                $update['sdate'] = time();
-                $update['fdate'] = time();
-            }
-            $update['audit_desc'] = $data['audit_desc'];
-            Dever::db('order_refund', 'place_source')->update($data['id'], $update);
-            $auth = new \Manage\Lib\Auth();
-            $msg = '退款:' . $update['audit_desc'];
-            Dever::load('log', 'place_source')->up(2, $auth->uid, $refund['order_id'], $msg);
-            if ($refund['type'] == 2 && $refund['status'] == 2) {
-                # 仅退款
-                $order = Dever::db('order', 'place_source')->find($refund['order_id']);
-                $this->finish($order, $refund);
-            }
-        }
-        return 'end';
-    }
-
-    # 买家发货
-    public function express($order, $refund, $express_id, $number)
-    {
-        $refund = Dever::db('order_refund', 'place_source')->find($refund['id']);
-        if ($refund['status'] == 2) {
-            $update['status'] = 3;
-            $update['ddate'] = time();
-            $where = array('order_refund_id' => $refund['id']);
-            $info = Dever::db('order_refund_express', 'place_source')->find($where);
-            if (!$info) {
-                $where['order_id'] = $order['id'];
-                $where['express_id'] = $express_id;
-                $where['number'] = $number;
-                Dever::db('order_refund_express', 'place_source')->insert($where);
-                Dever::load('log', 'place_source')->up(1, $order['uid'], $order['id'], '退款:买家已发货');
-            }
-            Dever::db('order_refund', 'place_source')->update($refund['id'], $update);
-        }
-    }
-
-    # 完成退款 如果是支付订单,原路退回
-    public function finish($order, $refund)
-    {
-        $refund = Dever::db('order_refund', 'place_source')->find($refund['id']);
-        if ($refund['status'] == 2 || $refund['status'] == 3) {
-            $update['status'] = 4;
-            $update['fdate'] = time();
-            $update['refund_status'] = 1;
-            Dever::db('order_refund', 'place_source')->update($refund['id'], $update);
-            Dever::load('log', 'place_source')->up(1, $order['uid'], $order['id'], '退款:已完成退款');
-
-            # 检测订单是否全都退了
-            $refund = Dever::db('order_refund', 'place_source')->select(array('order_id' => $order['id']));
-            $cash = 0;
-            foreach ($refund as $k => $v) {
-                $cash += $v['cash'];
-            }
-
-            if ($cash >= $order['cash']) {
-                $refund = Dever::db('order', 'place_source')->update($order['id'], array('status' => 8, 'fdate' => time(), 'refund_status' => 2));
-
-                Dever::load('log', 'place_source')->up(1, $order['uid'], $order['id'], '订单已退款');
-                # 恢复库存
-                Dever::load('order', 'place_source')->resell($order['id']);
-            }
-
-            # 判断是否支付订单,如果是,走退款流程
-            if ($order['type'] == 1) {
-
-            }
-        }
-    }
-
-    public function up($detail, $order, $type, $desc_type, $cash, $desc, $log = false)
-    {
-        if ($detail) {
-            foreach ($detail as $k => $v) {
-                $info = Dever::db('order_detail', 'place_source')->find($v['detail_id']);
-                $refund = Dever::db('order_refund_detail', 'place_source')->find(array('detail_id' => $v['detail_id'], 'refund_status' => 1), array('col' => 'sum(num) as num'));
-                if ($refund && $refund['num']) {
-                    $info['num'] -= $refund['num'];
-                }
-                if ($v['num'] > $info['num']) {
-                    Dever::error('退款数量不能大于下单商品数量');
-                }
-            }
-        }
-        $where = array('order_id' => $order['id'], 'refund_status' => 1);
-        $refund = Dever::db('order_refund', 'place_source')->find($where, array('col' => 'sum(cash) as cash'));
-        if ($refund && $refund['cash']) {
-            $order['cash'] -= $refund['cash'];
-        }
-        if ($cash > $order['cash']) {
-            Dever::error('退款金额不能大于订单金额');
-        }
-        $update = $where;
-        $update['refund_status'] = 2;
-        $update['status'] = array('<', '5');
-        $refund = Dever::db('order_refund', 'place_source')->find($update);
-        $update['type'] = $type;
-        $update['desc_type'] = $desc_type;
-        $update['cash'] = $cash;
-        $update['desc'] = $desc;
-        $update['status'] = 1;
-        if ($refund) {
-            Dever::error('您有退款进行中,请先处理');
-        } else {
-            $id = Dever::db('order_refund', 'place_source')->insert($update);
-            if ($id) {
-                Dever::db('order', 'place_source')->update($order['id'], array('refund_status' => 1));
-                if ($detail) {
-                    foreach ($detail as $k => $v) {
-                        $v['order_refund_id'] = $id;
-                        Dever::db('order_refund_detail', 'place_source')->insert($v);
-                    }
-                }
-                if ($log) {
-                    $type = $log['type'];
-                    $uid = $log['uid'];
-                    $msg = '退款:提交退款申请单';
-                    Dever::load('log', 'place_source')->up($type, $uid, $order['id'], $msg);
-                }
-            }
-        }
-    }
-
-    # 获取信息
-    public function getList($order_id)
-    {
-        $log = Dever::db('order_log', 'place_source')->select(array('order_id' => $order_id));
-        if ($log) {
-            foreach ($log as &$v) {
-                $v = $this->getInfo($v);
-            }
-        }
-        return $log;
-    }
-
-    # 获取信息
-    public function getInfo($info)
-    {
-        if ($info['type'] == 1) {
-            $user = Dever::db('member', 'place')->find($info['type_id']);
-        } elseif ($info['type'] == 2) {
-            $user = Dever::db('user', 'sector')->find($info['type_id']);
-        } elseif ($info['type'] == 3) {
-            $user = Dever::db('supplier', 'place')->find($info['type_id']);
-        } else {
-            $user['name'] = $user['mobile'] = '-';
-        }
-        $info['type'] = Dever::db('order_log', 'place_source')->value('type', $info);
-        $info['name'] = $user['name'];
-        $info['mobile'] = $user['mobile'];
-        $info['cdate_str'] = date('Y-m-d H:i:s', $info['cdate']);
-        return $info;
-    }
-}

+ 7 - 6
src/place/order/lib/source/Address.php → src/place/order/manage/Lib/Source/Address.php

@@ -1,14 +1,12 @@
-<?php namespace Place_order\Lib\Source;
+<?php namespace Place_order\Manage\Lib\Source;
 use Dever;
-use Place;
 class Address
 {
     public function update($db, $data)
     {
         $order = Dever::db('source', 'place_order')->find($data['id']);
         if ($order) {
-            $auth = new \Manage\Lib\Auth();
-            $uid = $auth->uid;
+            $uid = Dever::$data['muser']['id'];
             $log['type'] = 2;
             $log['uid'] = $uid;
             $this->up($order['id'], $order['uid'], $order['address_id'], $data['address_name'], $data['address_phone'], $data['address_area'], $data['address_address'], $log);
@@ -25,10 +23,13 @@ class Address
         $update['area'] = $area;
         list($update['province_id'], $update['city_id'], $update['county_id']) = explode(',', $update['area']);
         $update['address'] = $address;
-        $address = Dever::db('address', 'place_user')->find($address_id);
+        $address = array();
+        if ($address_id) {
+            $address = Dever::db('address', 'place_user')->find($address_id);
+        }
         if ($address && $address['type'] == 3) {
             # 更新
-            Dever::db('address', 'place')->update($address['id'], $update);
+            Dever::db('address', 'place_user')->update($address['id'], $update);
         } else {
             $id = Dever::db('address', 'place_user')->insert($update);
             Dever::db('source', 'place_order')->update($order_id, array('address_id' => $id));

+ 16 - 0
src/place/order/manage/Lib/Source/Express.php

@@ -0,0 +1,16 @@
+<?php namespace Place_order\Manage\Lib\Source;
+use Dever;
+class Express
+{
+    public function update($db, $data)
+    {
+        $order = Dever::db('source', 'place_order')->find($data['order_id']);
+        if ($order && $order['status'] <= 3) {
+            $uid = Dever::$data['muser']['id'];
+            $log['type'] = 2;
+            $log['uid'] = $uid;
+            Dever::load('source/express', 'source_order')->up($data['id'], $order['id'], $data['express_id'], $data['number'], $log);
+        }
+        return 'end';
+    }
+}

+ 365 - 0
src/place/order/manage/Lib/Source/Order.php

@@ -0,0 +1,365 @@
+<?php namespace Place_order\Manage\Lib\Source;
+use Dever;
+class Order
+{
+    # 后台详情页
+    public function getView($page)
+    {
+        # 这里获取基本信息
+        $db = Dever::db('sourcce', 'place_order');
+        $address = array();
+        if ($page->info['address_id']) {
+            $address = Dever::load('address', 'place_user')->getInfo($page->info['address_id'], $page->info['uid']);
+        }
+        $user = Dever::db('info', 'place_user')->find($page->info['uid']);
+        $desc = '';
+        $status = $db->value('status', $page->info);
+        if ($page->info['info']) {
+            $desc = '备注:' . $page->info['info'];
+        }
+        $timeline = array();
+        $page->info['cdate_str'] = date('Y-m-d H:i:s', $page->info['cdate']);
+        if (isset($page->info['pdate']) && $page->info['pdate']) {
+            $page->info['pdate_str'] = date('Y-m-d H:i:s', $page->info['pdate']);
+        }
+        if (isset($page->info['ddate']) && $page->info['ddate']) {
+            $page->info['ddate_str'] = date('Y-m-d H:i:s', $page->info['ddate']);
+        }
+        if (isset($page->info['qdate']) && $page->info['qdate']) {
+            $page->info['qdate_str'] = date('Y-m-d H:i:s', $page->info['qdate']);
+        }
+        if (isset($page->info['fdate']) && $page->info['fdate']) {
+            $page->info['fdate_str'] = date('Y-m-d H:i:s', $page->info['fdate']);
+        }
+        Dever::load('source/order', 'place_order')->getView($page->info);
+
+        foreach ($page->info['status_list'] as $k => $v) {
+            $v['name'] = '['.$v['name'].']';
+            if ($k == 1) {
+                $v['name'] .= ' 下单人:' . $user['name'] . '('.$user['mobile'].')' . ' 付款:' . $page->info['cash'] . '元 '. $desc;
+            } elseif ($k == 2) {
+                if ($address) {
+                    $v['name'] .= ' 收货地址:' . $address['full'];
+                }
+            } elseif ($k == 3) {
+                if (isset($page->info['express'])) {
+                    $v['name'] .= ' 已发货:' . $page->info['express']['name'] . ',' . $page->info['express']['number'];
+                }
+            } elseif ($k == 4) {
+                if (isset($page->info['express']['log'][0])) {
+                    $v['name'] .= ' ' . $page->info['express']['log'][0]['status'];
+                }
+            } elseif ($k == 5 && $page->info['status'] > 6) {
+                $v['name'] .= ' 订单'.$status.'';
+            }
+            if ($v['selected']) {
+                $v['hollow'] = true;
+                $v['color'] = '#0bbd87';
+                $v['type'] = 'primary';
+                $v['size'] = 'large';
+            }
+            $timeline[] = $v;
+        }
+        $button = array();
+
+        if ($page->info['status'] == 2) {
+            if ($page->info['source_type'] == 1) {
+                $button[] = array
+                (
+                    'name' => '修改收货信息',
+                    'type' => 'fastedit',
+                    'path' => 'sector_place_order/source_address',
+                    'row' => array
+                    (
+                        'id' => $page->info['id'],
+                    ),
+                );
+                $button[] = array
+                (
+                    'name' => '快递发货',
+                    # fastedit、fastadd、oper、api、link、route
+                    'type' => 'fastadd',
+                    'path' => 'sector_place_order/source_express',
+                    'row' => array
+                    (
+                        'id' => $page->info['id'],
+                    ),
+                    'param' => array
+                    (
+                        'order_id' => $page->info['id'],
+                    ),
+                );
+            } elseif ($page->info['source_type'] == 2) {
+                $button[] = array
+                (
+                    'name' => '虚拟发货',
+                    'type' => 'fastadd',
+                    'path' => 'sector_place_order/source_virtual',
+                    'row' => array
+                    (
+                        'id' => $page->info['id'],
+                    ),
+                    'param' => array
+                    (
+                        'order_id' => $page->info['id'],
+                    ),
+                );
+            }
+            
+        } elseif ($page->info['status'] == 3 && isset($express)) {
+            $button[] = array
+            (
+                'name' => '修改快递单号',
+                # fastedit、fastadd、oper、api、link、route
+                'type' => 'fastedit',
+                'path' => 'sector_place_order/source_express',
+                'row' => array
+                (
+                    'id' => $express['id'],
+                ),
+                'param' => array
+                (
+                    'order_id' => $page->info['id'],
+                ),
+            );
+        }
+        if (!$page->info['refund'] && $page->info['status'] >= 2 && $page->info['status'] < 7 && $page->info['source_type'] == 1) {
+            $button[] = array
+            (
+                'name' => '退款',
+                'type' => 'fastadd',
+                'path' => 'sector_place_order/source_refund',
+                'row' => array
+                (
+                    'id' => $page->info['id'],
+                ),
+                'param' => array
+                (
+                    'order_id' => $page->info['id'],
+                ),
+            );
+        }
+        $desc = '';
+        if ($page->info['refund']) {
+            $desc = '[退款中]';
+            $refund = array();
+            foreach ($page->info['refund_status_list'] as $k => $v) {
+                $v['name'] = '['.$v['name'].']';
+                if ($k == 1) {
+                    $v['name'] .= ' 申请原因:' . Dever::db('source_refund', 'place_order')->value('desc_type', $page->info['refund']['desc_type']) . ' 申请说明:' . $page->info['refund']['desc'];
+                } elseif ($k == 2) {
+                    $v['name'] .= ' 审核备注:' . $page->info['refund']['audit_desc'];
+                } elseif ($k == 3) {
+                    if (isset($page->info['refund']['express'])) {
+                        $v['name'] .= ' 已发货:' . $page->info['refund']['express']['name'] . ',' . $page->info['refund']['express']['number'];
+                    }
+                }
+                if ($v['selected']) {
+                    $v['hollow'] = true;
+                    $v['color'] = 'red';
+                    $v['type'] = 'primary';
+                    $v['size'] = 'large';
+                }
+                $refund[] = $v;
+            }
+            $content[] = array
+            (
+                'name' => '退款进度',
+                'type' => 'timeline',
+                'content' => $refund,
+            );
+            $button = array();
+            if ($page->info['refund']['status'] == 1) {
+                $button[] = array
+                (
+                    'name' => '退款审核',
+                    'type' => 'fastedit',
+                    'path' => 'sector_place_order/source_refund_audit',
+                    'row' => array
+                    (
+                        'id' => $page->info['refund']['id'],
+                    ),
+                    'param' => array
+                    (
+                        'order_id' => $page->info['id'],
+                    ),
+                );
+            }
+        }
+
+        $content[] = array
+        (
+            'name' => '订单进度' . $desc,
+            'type' => 'timeline',
+            'content' => $timeline,
+        );
+
+        $info[] = array
+        (
+            # 类型,desc描述 table表格,表格有head和body即可
+            'type' => 'desc',
+            'name' => $page->info['order_num'],
+            # 每行展示数量
+            'column' => 1,
+            # 是否有边框
+            'border' => true,
+            # 排列方向:horizontal横向 vertical纵向
+            'direction' => 'horizontal',
+            # 右侧按钮
+            'button' => $button,
+            # 具体内容
+            'content' => $content,
+        );
+
+        $detail = Dever::db('source_detail', 'place_order')->select(array('order_id' => $page->info['id']));
+        if ($detail) {
+            foreach ($detail as &$v) {
+                $v['status'] = '正常';
+            }
+        }
+
+        $log = Dever::load('source/log', 'place_order')->getList($page->info['id']);
+
+        # 退款信息
+        $refund = array();
+        //$refund = Dever::load('source/refund', 'place_order')->getList($page->info['id']);
+        
+        $tab = array
+        (
+            'active' => 't1',
+        );
+
+        $tab['content']['t1'] = array
+        (
+            'name' => '商品清单',
+            'type' => 'table',
+            'border' => true,
+            #'height' => '200',
+            'head' => array
+            (
+                array
+                (
+                    'key' => 'name',
+                    'name' => '名称',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'sku_name',
+                    'name' => '规格',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'cash',
+                    'name' => '金额',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'num',
+                    'name' => '数量',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'status',
+                    'name' => '状态',
+                    'fixed' => 'fixed',
+                ),
+            ),
+            'button' => array(),
+            'body' => $detail,
+        );
+
+        if ($refund) {
+            $tab['content']['t2'] = array
+            (
+                'name' => '退款记录',
+                'type' => 'table',
+                'border' => true,
+                #'height' => '200',
+                'head' => array
+                (
+                    array
+                    (
+                        'key' => 'name',
+                        'name' => '名称',
+                        'fixed' => 'fixed',
+                    ),
+                    array
+                    (
+                        'key' => 'sku_name',
+                        'name' => '规格',
+                        'fixed' => 'fixed',
+                    ),
+                    array
+                    (
+                        'key' => 'cash',
+                        'name' => '金额',
+                        'fixed' => 'fixed',
+                    ),
+                    array
+                    (
+                        'key' => 'status',
+                        'name' => '状态',
+                        'fixed' => 'fixed',
+                    ),
+                    array
+                    (
+                        'key' => 'cdate_str',
+                        'name' => '时间',
+                        'fixed' => 'fixed',
+                    ),
+                ),
+                'button' => array(),
+                'body' => $refund,
+            );
+        }
+
+        $tab['content']['t3'] = array
+        (
+            'name' => '操作记录',
+            'type' => 'table',
+            'border' => true,
+            #'height' => '200',
+            'head' => array
+            (
+                array
+                (
+                    'key' => 'type',
+                    'name' => '身份',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'name',
+                    'name' => '名称',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'mobile',
+                    'name' => '联系电话',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'desc',
+                    'name' => '详情',
+                    'fixed' => 'fixed',
+                ),
+                array
+                (
+                    'key' => 'cdate_str',
+                    'name' => '时间',
+                    'fixed' => 'fixed',
+                ),
+            ),
+            'button' => array(),
+            'body' => $log,
+        );
+        
+        return array('info' => $info, 'tab' => $tab);
+    }
+}

+ 44 - 0
src/place/order/manage/Lib/Source/Refund.php

@@ -0,0 +1,44 @@
+<?php namespace Place_order\Manage\Lib\Source;
+use Dever;
+class Refund
+{
+    # 后台提交
+    public function update($db, $data)
+    {
+        $detail = Dever::input('place_order/source_refund_detail');
+        $order = Dever::db('source', 'place_order')->find($data['order_id']);
+        if ($order && $order['type'] == 1 && $order['status'] <= 4) {
+            $uid = Dever::$data['muser']['id'];
+            $log['type'] = 2;
+            $log['uid'] = $uid;
+            Dever::load('source/refund', 'place_order')->up($detail, $order, $data['type'], $data['desc_type'], $data['cash'], $data['desc'], $log);
+        }
+        return 'end';
+    }
+
+    # 后台审核
+    public function audit($db, $data)
+    {
+        $refund = Dever::db('source_refund', 'place_order')->find($data['id']);
+        if ($refund['status'] == 1) {
+            if ($data['audit'] == 1) {
+                $refund['status'] = $update['status'] = 2;
+                $update['sdate'] = time();
+            } else {
+                $update['status'] = 5;
+                $update['sdate'] = time();
+                $update['fdate'] = time();
+            }
+            $update['audit_desc'] = $data['audit_desc'];
+            Dever::db('source_refund', 'place_order')->update($data['id'], $update);
+            $msg = '退款:' . $update['audit_desc'];
+            Dever::load('source/log', 'place_order')->up(2, $this->uid, $refund['order_id'], $msg);
+            if ($refund['type'] == 2 && $refund['status'] == 2) {
+                # 仅退款
+                $order = Dever::db('source', 'place_order')->find($refund['order_id']);
+                $this->finish($order, $refund);
+            }
+        }
+        return 'end';
+    }
+}

+ 16 - 0
src/place/order/manage/Lib/Source/Virtual.php

@@ -0,0 +1,16 @@
+<?php namespace Place_order\Manage\Lib\Source;
+use Dever;
+class Virtual
+{
+    public function update($db, $data)
+    {
+        $order = Dever::db('source', 'place_order')->find($data['order_id']);
+        if ($order && $order['status'] <= 3) {
+            $uid = Dever::$data['muser']['id'];
+            $log['type'] = 2;
+            $log['uid'] = $uid;
+            Dever::load('source/virtual', 'place_order')->up($data['id'], $order['id'], $data['content'], $log);
+        }
+        return 'end';
+    }
+}

+ 10 - 1
src/place/order/manage/core.php

@@ -23,7 +23,16 @@ return array
         'source_express' => array
         (
             'parent'    => 'sector_place_order',
-            'name'      => '订单发货',
+            'name'      => '快递发货',
+            'icon'      => 'product-hunt-line',
+            'sort'      => '10',
+            'show'      => 3,
+        ),
+
+        'source_virtual' => array
+        (
+            'parent'    => 'sector_place_order',
+            'name'      => '虚拟发货',
             'icon'      => 'product-hunt-line',
             'sort'      => '10',
             'show'      => 3,

+ 6 - 0
src/place/order/manage/role.php

@@ -7,6 +7,11 @@ $config = array
         (
             'order_num',
             'name',
+            'uid' => array
+            (
+                'name' => '用户信息',
+                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
+            ),
             'cash',
             'status',
             'cdate',
@@ -22,6 +27,7 @@ $config = array
         'search'    => array
         (
             'order_num',
+            'uid',
             'name' => 'like',
             'cdate' => array
             (

+ 5 - 4
src/place/order/manage/source.php

@@ -7,11 +7,11 @@ $config = array
         (
             'order_num',
             'name',
-            /*
             'uid' => array
             (
-                'show' => 'Dever::call("place/member-find", array({uid}))["name"]',
-            ),*/
+                'name' => '用户信息',
+                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
+            ),
             'cash',
             'num',
             'status',
@@ -39,6 +39,7 @@ $config = array
         'search'    => array
         (
             'order_num',
+            'uid',
             'name' => 'like',
             'cdate' => array
             (
@@ -55,6 +56,6 @@ $config = array
         ),
     ),
     # 详情页配置
-    'view' => 'place_order/source/order.showManageView',
+    'view' => 'place_order/manage/source/order.getView',
 );
 return $config;

+ 10 - 7
src/place/order/manage/source_address.php

@@ -1,43 +1,46 @@
 <?php
 $id = Dever::input('id');
 $info = Dever::db('source', 'place_order')->find($id);
-$address = Dever::db('address', 'place_user')->find($info['address_id']);
+if ($info['address_id']) {
+    $address = Dever::db('address', 'place_user')->find($info['address_id']);
+}
+
 $config = array
 (
     'source' => 'place_order/source',
     'update' => array
     (
-        'start' => 'place_order/source/address.update',
+        'start' => 'place_order/manage/source/address.update',
         'field'    => array
         (
             'address_id' => array
             (
-                'value' => $address['id'],
+                'value' => $address['id'] ?? '',
                 'type' => 'hidden',
             ),
             'address_name' => array
             (
                 'name' => '联系人',
-                'value' => $address['name'],
+                'value' => $address['name'] ?? '',
             ),
             'address_phone' => array
             (
                 'name' => '联系电话',
-                'value' => $address['phone'],
+                'value' => $address['phone'] ?? '',
             ),
             'address_area' => array
             (
                 'name' => '城市地区',
                 'type' => 'cascader',
                 'remote'    => Dever::url('area/data.get&total=3'),
-                'value'     => $address['area'],
+                'value'     => $address['area'] ?? '',
             ),
             'address_address' => array
             (
                 'name' => '详细地址',
                 'type' => 'textarea',
                 'autosize' => array('minRows' => 2),
-                'value' => $address['address'],
+                'value' => $address['address'] ?? '',
             ),
         ),
     ),

+ 1 - 1
src/place/order/manage/source_express.php

@@ -4,7 +4,7 @@ $config = array
 (
     'update' => array
     (
-        'start' => 'place_order/source/express.update',
+        'start' => 'place_order/manage/source/express.update',
         'field'    => array
         (
             'order_id' => array

+ 1 - 1
src/place/order/manage/source_refund.php

@@ -4,7 +4,7 @@ $config = array
 (
     'update' => array
     (
-        'start' => 'place_order/source/refund.update',
+        'start' => 'place_order/manage/source/refund.update',
         'field'    => array
         (
             'order_id' => array

+ 2 - 1
src/place/order/manage/source_refund_audit.php

@@ -1,9 +1,10 @@
 <?php
 $config = array
 (
+    'source' => 'place_order/source_refund',
     'update' => array
     (
-        'start' => 'place_order/source/refund.audit',
+        'start' => 'place_order/manage/source/refund.audit',
         'field'    => array
         (
             'audit' => array

+ 26 - 0
src/place/order/manage/source_virtual.php

@@ -0,0 +1,26 @@
+<?php
+$id = Dever::input('field')['order_id'];
+$config = array
+(
+    'update' => array
+    (
+        'start' => 'place_order/manage/source/virtual.update',
+        'field'    => array
+        (
+            'order_id' => array
+            (
+                'value' => $id,
+                'type' => 'hidden',
+            ),
+            'content' => array
+            (
+                'rules' => true,
+                'type' => 'textarea',
+                'autosize' => array('minRows' => 6),
+                'tips' => '',
+            ),
+        ),
+    ),
+);
+
+return $config;

+ 31 - 7
src/place/order/table/role.php

@@ -5,15 +5,15 @@ return array
     'partition' => 'Dever::call("manage/common.system")',
     'struct' => array
     (
-        'role_id' => array
+        'type' => array
         (
-            'name'      => '角色ID',
-            'type'      => 'int(11)',
+            'name'      => '角色',
+            'type'      => 'tinyint(1)',
         ),
 
-        'level_id' => array
+        'type_id' => array
         (
-            'name'      => '角色等级ID',
+            'name'      => '角色id',
             'type'      => 'int(11)',
         ),
 
@@ -25,7 +25,7 @@ return array
 
         'name'      => array
         (
-            'type'      => 'varchar(80)',
+            'type'      => 'varchar(255)',
             'name'      => '订单名称',
         ),
 
@@ -37,10 +37,34 @@ return array
 
         'cash'      => array
         (
-            'type'      => 'decimal(11,2)',
+            'type'      => 'decimal(20,2)',
             'name'      => '订单金额',
         ),
 
+        'pay_cash'      => array
+        (
+            'type'      => 'decimal(20,2)',
+            'name'      => '支付金额',
+        ),
+
+        'wallet_cash'      => array
+        (
+            'type'      => 'decimal(20,2)',
+            'name'      => '钱包金额',
+        ),
+
+        'user_coupon_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '用户优惠券id',
+        ),
+
+        'coupon_cash'      => array
+        (
+            'type'      => 'decimal(20,2)',
+            'name'      => '优惠券金额',
+        ),
+
         'status'        => array
         (
             'type'      => 'tinyint(1)',

+ 38 - 13
src/place/order/table/source.php

@@ -5,10 +5,11 @@ return array
     'partition' => 'Dever::call("manage/common.system")',
     'struct' => array
     (
-        'source_id' => array
+        'source_type' => array
         (
-            'name'      => '资源ID',
-            'type'      => 'int(11)',
+            'name'      => '资源类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
         ),
 
         'address_id' => array
@@ -20,31 +21,55 @@ return array
         'uid'       => array
         (
             'type'      => 'int(11)',
-            'name'      => '用户',
+            'name'      => '用户ID',
+        ),
+
+        'order_num'        => array
+        (
+            'type'      => 'varchar(60)',
+            'name'      => '订单号',
         ),
 
         'name'      => array
         (
-            'type'      => 'varchar(80)',
+            'type'      => 'varchar(255)',
             'name'      => '订单名称',
         ),
 
-        'order_num'        => array
+        'cash'      => array
         (
-            'type'      => 'varchar(60)',
-            'name'      => '订单号',
+            'type'      => 'decimal(20,2)',
+            'name'      => '金额',
         ),
 
-        'cash'      => array
+        'pay_cash'      => array
+        (
+            'type'      => 'decimal(20,2)',
+            'name'      => '支付金额',
+        ),
+
+        'wallet_cash'      => array
+        (
+            'type'      => 'decimal(20,2)',
+            'name'      => '钱包金额',
+        ),
+
+        'user_coupon_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '用户优惠券id',
+        ),
+
+        'coupon_cash'      => array
         (
-            'type'      => 'decimal(11,2)',
-            'name'      => '订单金额',
+            'type'      => 'decimal(20,2)',
+            'name'      => '优惠券金额',
         ),
 
         'num'      => array
         (
-            'type'      => 'decimal(11,2)',
-            'name'      => '订单数量',
+            'type'      => 'int(11)',
+            'name'      => '数量',
         ),
 
         'info'      => array

+ 11 - 1
src/place/order/table/source_detail.php

@@ -49,10 +49,16 @@ return array
 
         'num'      => array
         (
-            'type'      => 'decimal(11,2)',
+            'type'      => 'int(11)',
             'name'      => '明细数量',
         ),
 
+        'unum'      => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '使用次数',
+        ),
+
         'status'        => array
         (
             'type'      => 'tinyint(1)',
@@ -66,4 +72,8 @@ return array
             ),
         ),
     ),
+    'index' => array
+    (
+        'search' => 'order_id,source_id,sku_id',
+    ),
 );

+ 20 - 0
src/place/order/table/source_virtual.php

@@ -0,0 +1,20 @@
+<?php
+return array
+(
+    'name' => '资源虚拟信息表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => array
+    (
+        'order_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '订单ID',
+        ),
+
+        'content'       => array
+        (
+            'type'      => 'varchar(500)',
+            'name'      => '虚拟信息',
+        ),
+    ),
+);

+ 13 - 27
src/place/order/table/user_source.php

@@ -23,40 +23,26 @@ return array
             'name'      => '价格ID',
         ),
 
-        'name'      => array
+        'unum_total'      => array
         (
-            'type'      => 'varchar(80)',
-            'name'      => '名称',
-        ),
-
-        'pic' => array
-        (
-            'name'      => '图片',
-            'type'      => 'varchar(150)',
-        ),
-
-        'sku_name'      => array
-        (
-            'type'      => 'varchar(200)',
-            'name'      => '价格的规格名称',
-        ),
-
-        'cash'      => array
-        (
-            'type'      => 'decimal(11,2)',
-            'name'      => '总金额',
+            'type'      => 'int(11)',
+            'name'      => '总次数',
         ),
 
-        'num'      => array
+        'unum_used'      => array
         (
-            'type'      => 'decimal(11,2)',
-            'name'      => '总数量',
+            'type'      => 'int(11)',
+            'name'      => '使用次数',
         ),
 
-        'yue'      => array
+        'unum_balance'      => array
         (
-            'type'      => 'decimal(11,2)',
-            'name'      => '剩余数',
+            'type'      => 'int(11)',
+            'name'      => '剩余次数',
         ),
     ),
+    'index' => array
+    (
+        'search' => 'uid,source_id,sku_id',
+    ),
 );

+ 71 - 0
src/place/order/table/user_source_log.php

@@ -0,0 +1,71 @@
+<?php
+return array
+(
+    'name' => '用户资源记录表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => array
+    (
+        'uid'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '用户',
+        ),
+        'source_id' => array
+        (
+            'name'      => '资源ID',
+            'type'      => 'int(11)',
+        ),
+
+        'sku_id'        => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '价格ID',
+        ),
+        'type' => array
+        (
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '收入',
+                2 => '支出',
+            ),
+        ),
+        'source_type' => array
+        (
+            'name'      => '交易类型',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '购买资源增加次数',
+                2 => '查看内容消耗次数',
+
+                100 => '赠送',
+            ),
+        ),
+        'amount'        => array
+        (
+            'name'      => '变动次数',
+            'type'      => 'int(11)',
+        ),
+
+        'status' => array
+        (
+            'name'      => '入账状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '已入账',
+                2 => '待入账',
+            ),
+        ),
+    ),
+
+    'index' => array
+    (
+        'search' => 'uid,source_id,sku_id,type,source_type',
+    ),
+);

+ 5 - 0
src/place/role/index.php

@@ -0,0 +1,5 @@
+<?php
+define('DEVER_APP_NAME', 'place_role');
+define('DEVER_APP_LANG', '角色');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(DEVER_APP_PATH . '../boot.php');

+ 23 - 0
src/place/role/manage/Lib/Api.php

@@ -0,0 +1,23 @@
+<?php namespace Place_role\Manage\Lib;
+use Dever;
+class Api
+{
+    public function test()
+    {
+        return Dever::$data['muser'];
+    }
+    public function getRoleLevel($value)
+    {
+        if (is_array($value)) {
+            $value = end($value);
+        }
+        $result = array();
+        $result['level_id']['value'] = '';
+        if (!$value) {
+            $result['level_id']['option'] = array();
+            return $result;
+        }
+        $result['level_id']['option'] = Dever::db('level', 'place_role')->select(array('info_id' => $value));
+        return $result;
+    }
+}

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

@@ -0,0 +1,18 @@
+<?php namespace Place_role\Manage\Lib;
+use Dever;
+class Data
+{
+    public function getList()
+    {
+        $result = array();
+        $set = ['col' => 'id as value,name as label'];
+        $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['value'], 'status' => 1], $set);
+            if ($v['children']) {
+                $result[] = $v;
+            }
+        }
+        return $result;
+    }
+}

+ 32 - 0
src/place/role/manage/core.php

@@ -0,0 +1,32 @@
+<?php
+return array
+(
+    'menu' => array
+    (
+        # 某个账户下角色设置
+        'set_role_manage' => array
+        (
+            'parent'    => 'sector_place_set',
+            'name'      => '角色配置',
+            'icon'      => 'folder-user-line',
+            'sort'      => '101',
+        ),
+
+        'info' => array
+        (
+            'parent'    => 'set_role_manage',
+            'name'      => '角色管理',
+            'icon'      => 'user-2-line',
+            'sort'      => '1',
+        ),
+
+        'level' => array
+        (
+            'parent'    => 'set_role_manage',
+            'name'      => '角色等级',
+            'icon'      => 'user-2-line',
+            'sort'      => '1',
+            'show'      => 3,
+        ),
+    ),
+);

+ 65 - 0
src/place/role/manage/info.php

@@ -0,0 +1,65 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'score_id',
+            'sort' => array
+            (
+                'type' => 'input',
+                'tips' => '双击修改排序,正序排序',
+            ),
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+        ),
+        'button' => array
+        (
+            '新增' => array('fastadd'),
+        ),
+        'data_button' => array
+        (
+            '编辑' => 'fastedit',
+            '等级设置' => array('route', array
+            (
+                'path' => 'set_role_manage/level',
+                'param' => array
+                (
+                    'set' => array('info_id' => 'id', 'menu' => 'set_role_manage/info', 'parent' => 'set_role_manage/info'),
+                ),
+            )),
+        ),
+        'search'    => array
+        (
+            'name',
+        ),
+    ),
+    'update' => array
+    (
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            'score_id' => array
+            (
+                'rules' => true,
+                'tips' => '购买该角色所需的积分',
+            ),
+            'place_score/rebate' => array
+            (
+                'name' => '返利积分',
+                'tips' => '选择返利积分后,当用户购买该角色后,将按照规则返利',
+                'where'  => array('type' => 4,'type_id' => 'id'),
+            ),
+        ),
+    ),
+);

+ 23 - 23
src/place/user/manage/role_level.php → src/place/role/manage/level.php

@@ -1,15 +1,16 @@
 <?php
-$role_id = Dever::input('set')['role_id'] ?? 0;
+$info_id = Dever::input('set')['info_id'] ?? 0;
 return array
 (
     'list' => array
     (
-        'where' => array('role_id' => $role_id),
+        'where' => array('info_id' => $info_id),
         'field'      => array
         (
             'name',
             'level',
             'price',
+            'day_desc',
             'status' => array
             (
                 'type' => 'switch',
@@ -20,28 +21,28 @@ return array
         ),
         'button' => array
         (
-            '新增' => array('add', array('role_id' => $role_id)),
+            '新增' => array('add', array('info_id' => $info_id)),
         ),
         'data_button' => array
         (
-            '编辑' => array('edit', array('role_id' => $role_id)),
+            '编辑' => array('edit', array('info_id' => $info_id)),
         ),
         'search'    => array
         (
             'name',
-            'role_id' => 'hidden',
+            'info_id' => 'hidden',
         ),
     ),
     'update' => array
     (
         'tab' => array
         (
-            '基本信息' => 'name,level,price,pay,day_desc,day,icon,content',
-            '权益设置' => 'place_user/role_level_profit',
+            '基本信息' => 'name,level,price,pay,day_desc,day,content',
+            '权益设置' => 'place_role/profit_buy,place_role/profit_sale,place_role/profit_partner',
         ),
         'field'    => array
         (
-            'role_id',
+            'info_id',
             'name' => array
             (
                 'rules' => true,
@@ -54,7 +55,7 @@ return array
             'price' => array
             (
                 'rules' => true,
-                'tips' => '购买当前等级所需支付的积分金额',
+                'tips' => '购买当前等级所需支付的积分金额,填写0则免费',
             ),
             'pay' => array
             (
@@ -72,13 +73,7 @@ return array
                 'rules' => true,
                 'desc' => '设置时长天数,如365,如果填写-1就是永久有效',
             ),
-            'icon' => array
-            (
-                'type' => 'upload',
-                'upload' => '1',
-                'multiple' => true,
-                'style' => 'pic',
-            ),
+            /*
             'content' => array
             (
                 'type' => 'editor',
@@ -87,15 +82,20 @@ return array
                     'uploadImage' => 1,
                     'uploadVideo' => 3,
                 ),
-                /*
-                'type' => 'textarea',
-                'autosize' => array('minRows' => 4),
-                */
+            ),*/
+            'place_role/profit_buy' => array
+            (
+                'name' => '购买权益',
+                'where'  => array('level_id' => 'id'),
+            ),
+            'place_role/profit_sale' => array
+            (
+                'name' => '分销佣金',
+                'where'  => array('level_id' => 'id'),
             ),
-
-            'place_user/role_level_profit' => array
+            'place_role/profit_partner' => array
             (
-                'name' => '权益设置',
+                'name' => '合作分成',
                 'where'  => array('level_id' => 'id'),
             ),
         ),

+ 36 - 0
src/place/role/manage/profit_buy.php

@@ -0,0 +1,36 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'type' => array
+            (
+                'type' => 'cascader',
+                'option'    => 'Dever::call("place/manage/profit.getInfo")',
+            ),
+            'discount' => array
+            (
+                'tips' => '购买当前权益的折扣,直接填写数字即可,填写9就是9折
+                    <br />权益当前价格*(购买折扣/10)=权益实付价格
+                    <br />如:此处购买折扣填写为8,则权益实付价格=权益当前价格*(8/10)
+                    <br />不填写则无折扣,填写0则免费',
+                'placeholder' => '权益当前价格*(购买折扣/10)=权益实付价格',
+            ),
+            'limit' => array
+            (
+                'tips' => '填写每日上限数值,不填写不限制<br />该限制为查看收费内容或功能的次数<br />如填写100,则每日只能查看100次,一般适合长期会员',
+                'placeholder' => '填写每日上限数值',
+            ),
+            'status' => array
+            (
+                'width' => '40',
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+        ),
+    ),
+);

+ 46 - 0
src/place/role/manage/profit_partner.php

@@ -0,0 +1,46 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'type' => array
+            (
+                'type' => 'cascader',
+                'option'    => 'Dever::call("place/manage/profit.getInfo")',
+            ),
+            'period' => array
+            (
+                'type' => 'select',
+                'tips' => '选择结算周期,将按照周期结算代理分成',
+            ),
+            'period_day' => array
+            (
+                'type' => 'text',
+                'tips' => '输入结算时间,如输入2
+                    <br />结算周期选择按天时,就是每天2点结算昨天数据
+                    <br />结算周期选择按周时,就是每周星期2凌晨1点结算前一周数据
+                    <br />结算周期选择按月时,就是每月2号凌晨1点结算上个月数据
+                    <br />结算周期选择按季时,就是每季度第2天凌晨1点结算上一季度数据
+                    <br />结算周期选择按年时,就是每年第2天凌晨1点结算上一年数据',
+            ),
+            'percent' => array
+            (
+                'tips' => '代理团队周期内当前权益所产生的利润的分成比例,直接填写数字即可
+                    <br />周期内利润*分成比例%=分成
+                    <br />如:此处分成比例填写为10,则分成=周期内利润*10%
+                    <br />不填写则无分成',
+                'placeholder' => '周期内利润*分成比例%=分成',
+            ),
+            'status' => array
+            (
+                'width' => '40',
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+        ),
+    ),
+);

+ 37 - 0
src/place/role/manage/profit_sale.php

@@ -0,0 +1,37 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        //'end' => 'place/manage/profit.update',
+        'field'    => array
+        (
+            'type' => array
+            (
+                'type' => 'cascader',
+                'option'    => 'Dever::call("place/manage/profit.getInfo")',
+            ),
+            'score_id' => array
+            (
+                'type' => 'select',
+                'tips' => '选择发放佣金的积分',
+            ),
+            'percent' => array
+            (
+                'tips' => '邀请他人购买当前权益可以获得的佣金,直接填写数字即可
+                    <br />权益实付价格*佣金比例%=佣金
+                    <br />如:此处佣金比例填写为10,则佣金=权益实付价格*10%
+                    <br />不填写则无佣金',
+                'placeholder' => '权益实付价格*佣金比例%=佣金',
+            ),
+            'status' => array
+            (
+                'width' => '40',
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+        ),
+    ),
+);

+ 44 - 0
src/place/role/table/info.php

@@ -0,0 +1,44 @@
+<?php
+return array
+(
+    'name' => '角色表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc,id asc',
+    'struct' => array
+    (
+        'name' => array
+        (
+            'name'      => '角色名称',
+            'type'      => 'varchar(32)',
+        ),
+        'desc' => array
+        (
+            'name'      => '介绍',
+            'type'      => 'varchar(800)',
+        ),
+        'score_id'        => array
+        (
+            'name'      => '购买积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+            'default'   => '1',
+        ),
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ),
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '开启',
+                2 => '禁用',
+            ),
+        ),
+    ),
+);

+ 3 - 9
src/place/user/table/role_level.php → src/place/role/table/level.php

@@ -3,10 +3,10 @@ return array
 (
     'name' => '角色等级设置',
     'partition' => 'Dever::call("manage/common.system")',
-    'order' => 'level asc',
+    'order' => 'level asc,id asc',
     'struct' => array
     (
-        'role_id'        => array
+        'info_id'        => array
         (
             'name'      => '角色ID',
             'type'      => 'int(11)',
@@ -25,12 +25,6 @@ return array
             'default'   => 1,
         ),
 
-        'icon' => array
-        (
-            'name'      => '等级图标',
-            'type'      => 'varchar(150)',
-        ),
-
         'price' => array
         (
             'name'      => '等级价格',
@@ -45,7 +39,7 @@ return array
 
         'day_desc' => array
         (
-            'name'      => '时长描述',
+            'name'      => '时长名称',
             'type'      => 'varchar(32)',
         ),
 

+ 6 - 12
src/place/user/table/role_level_profit.php → src/place/role/table/profit_buy.php

@@ -1,7 +1,7 @@
 <?php
 return array
 (
-    'name' => '角色等级权益设置表',
+    'name' => '角色等级购买权益设置表',
     'partition' => 'Dever::call("manage/common.system")',
     'order' => 'sort asc,id asc',
     'struct' => array
@@ -12,29 +12,23 @@ return array
             'type'      => 'int(11)',
         ),
 
-        # 如果是资源 则可以选择频道 如果是角色 则可以选择角色
+        # 选择的权益类型 如果是资源 则可以选择频道 如果是角色 则可以选择角色
         'type' => array
         (
             'name'      => '权益',
             'type'      => 'varchar(100)',
         ),
 
-        'buy' => array
+        'discount' => array
         (
             'name'      => '购买折扣',
-            'type'      => 'varchar(11)',
+            'type'      => 'decimal(11,1)',
         ),
 
-        'fee' => array
-        (
-            'name'      => '佣金比例',
-            'type'      => 'varchar(11)',
-        ),
-
-        'total' => array
+        'limit' => array
         (
             'name'      => '上限',
-            'type'      => 'varchar(11)',
+            'type'      => 'int(11)',
         ),
 
         'sort' => array

+ 69 - 0
src/place/role/table/profit_partner.php

@@ -0,0 +1,69 @@
+<?php
+return array
+(
+    'name' => '角色等级利润分成权益设置表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc,id asc',
+    'struct' => array
+    (
+        'level_id' => array
+        (
+            'name'      => '角色等级id',
+            'type'      => 'int(11)',
+        ),
+
+        # 选择的权益类型 如果是资源 则可以选择频道 如果是角色 则可以选择角色
+        'type' => array
+        (
+            'name'      => '权益',
+            'type'      => 'varchar(100)',
+        ),
+
+        'percent' => array
+        (
+            'name'      => '分成比例',
+            'type'      => 'decimal(11,1)',
+        ),
+
+        'period' => array
+        (
+            'name'      => '结算周期',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '每天',
+                2 => '每周',
+                3 => '每月',
+                4 => '每季',
+                4 => '每年',
+            ),
+        ),
+
+        'period_day' => array
+        (
+            'name'      => '结算时间',
+            'type'      => 'int(11)',
+            'default'   => '1',
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ),
+        
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '开启',
+                2 => '禁用',
+            ),
+        ),
+    ),
+);

+ 54 - 0
src/place/role/table/profit_sale.php

@@ -0,0 +1,54 @@
+<?php
+return array
+(
+    'name' => '角色等级销售佣金权益设置表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'order' => 'sort asc,id asc',
+    'struct' => array
+    (
+        'level_id' => array
+        (
+            'name'      => '角色等级id',
+            'type'      => 'int(11)',
+        ),
+
+        # 选择的权益类型 如果是资源 则可以选择频道 如果是角色 则可以选择角色
+        'type' => array
+        (
+            'name'      => '权益',
+            'type'      => 'varchar(100)',
+        ),
+
+        'score_id'        => array
+        (
+            'name'      => '佣金积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+        ),
+
+        'percent' => array
+        (
+            'name'      => '佣金比例',
+            'type'      => 'decimal(11,1)',
+        ),
+
+        'sort' => array
+        (
+            'name'      => '排序',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ),
+        
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '开启',
+                2 => '禁用',
+            ),
+        ),
+    ),
+);

+ 5 - 5
src/place/score/lib/Action.php

@@ -1,19 +1,19 @@
-<?php namespace Score\Lib;
+<?php namespace Place_score\Lib;
 use Dever;
 class Action
 {
     public function get($cate_name, $name)
     {
         $data['name'] = $name;
-        $action = Dever::db('action', 'score')->find($data);
+        $action = Dever::db('action', 'place_score')->find($data);
         if (!$action) {
             $cate_data['name'] = $cate_name;
-            $action_cate = Dever::db('action_cate', 'score')->find($cate_data);
+            $action_cate = Dever::db('action_cate', 'place_score')->find($cate_data);
             if (!$action_cate) {
-                $data['cate_id'] = Dever::db('action_cate', 'score')->insert($cate_data);
+                $data['cate_id'] = Dever::db('action_cate', 'place_score')->insert($cate_data);
             }
             $action = array();
-            $action['id'] = Dever::db('action', 'score')->insert($data);
+            $action['id'] = Dever::db('action', 'place_score')->insert($data);
         }
         return $action;
     }

+ 38 - 40
src/place/score/lib/Log.php

@@ -1,46 +1,39 @@
-<?php namespace Score\Lib;
+<?php namespace Place_score\Lib;
 use Dever;
 class Log
 {
     /**
-     * 增加行为日志 Dever::load('score/log')->add(1, '订单', '下单', 100);
+     * 增加行为日志 Dever::load('log', 'place_score')->add(1, '订单', '下单', 100);
      *
      * @return mixed
      */
-    public function log_commit(){}
-    public function log($uid, $cate_name, $name, $num = 0)
+    public function add_commit(){}
+    public function add($uid, $cate_name, $name, $status = 1, $num = 0)
     {
-        $action = Dever::load('action', 'score')->get($cate_name, $name);
+        $action = Dever::load('action', 'place_score')->get($cate_name, $name);
         if ($action && $action['id'] > 0) {
             $insert = array();
             $insert['uid'] = $uid;
             $insert['action_id'] = $action['id'];
             //$insert['ip'] = Dever::ip();
-            $action_log_id = Dever::db('action_log', 'score')->insert($insert);
+            $action_log_id = Dever::db('action_log', 'place_score')->insert($insert);
 
             if ($action_log_id) {
-                $rule = Dever::db('rule', 'score')->select(array('action_id' => $action['id']));
+                $rule = Dever::db('rule', 'place_score')->select(array('action_id' => $action['id']));
                 $name = $cate_name . $name;
                 if ($rule) {
                     foreach ($rule as $k => $v) {
                         if ($num > 0) {
                             $v['num'] = $num;
                         }
-                        $this->rule($uid, $v, $action_log_id, $name);
+                        $this->rule($uid, $v, $action_log_id, $name, $status);
                     }
-                } elseif ($num > 0) {
-                    $info = Dever::db('info', 'score')->find(array('type' => 1));
-                    $rule = array();
-                    $rule['info_id'] = $info['id'];
-                    $rule['action_id'] = $action['id'];
-                    $rule['num'] = $num;
-                    $this->rule($uid, $rule, $action_log_id, $name);
                 }
             }
         }
     }
 
-    private function rule($uid, $rule, $action_log_id, $name)
+    private function rule($uid, $rule, $action_log_id, $name, $status = 1)
     {
         if (isset($rule['upper']) && $rule['upper'] == 2 && $rule['upper_limit'] >= 1) {
             $upper = $this->upper($uid, $rule);
@@ -49,7 +42,7 @@ class Log
                 return;
             }
         }
-        $log = $this->add($uid, $rule, $action_log_id, $name);
+        $log = $this->inc($uid, $rule, $action_log_id, $name, $status);
 
         if (!$log['id']) {
             return;
@@ -72,7 +65,7 @@ class Log
         $where['uid'] = $uid;
         $where['info_id'] = $rule['info_id'];
         $where['action_id'] = $rule['action_id'];
-        $user_log = Dever::db('user_log', 'score')->find($where);
+        $user_log = Dever::db('user_log', 'place_score')->find($where);
         if ($user_log) {
             if ($rule['upper_type'] == 1) {
                 # 按天
@@ -95,49 +88,54 @@ class Log
     }
 
     # 增加积分
-    private function add($uid, $rule, $action_log_id, $name, $user_log_id = false)
+    private function inc($uid, $rule, $action_log_id, $name, $status = 1, $user_log_id = false)
     {
         $where = array();
         $where['uid'] = $uid;
         $where['info_id'] = $rule['info_id'];
-        $user = Dever::db('user', 'score')->find($where);
+        $user = Dever::db('user', 'place_score')->find($where);
 
         if (!$user) {
             $user = array();
-            $user['id'] = Dever::db('user', 'score')->insert($where);
+            $user['id'] = Dever::db('user', 'place_score')->insert($where);
             $user['balance'] = 0;
             $user['udate'] = 0;
         }
 
         $update = array();
 
-        $insert = $where;
-        $insert['action_id'] = $rule['action_id'];
-        $insert['action_log_id'] = $action_log_id;
-        $insert['num'] = $rule['num'];
+        $log = $where;
+        $log['user_id'] = $user['id'];
+        $log['action_id'] = $rule['action_id'];
+        $log['action_log_id'] = $action_log_id;
+        $log['num'] = $rule['num'];
         if ($user_log_id) {
-            $insert['user_log_id'] = $user_log_id;
-            $insert['mode'] = 2;
+            $log['user_log_id'] = $user_log_id;
+            $log['mode'] = 2;
         }
-
-        if ($rule['num'] > 0) {
-            $update['total'] = array('+', $rule['num']);
-        } elseif ($rule['num'] < 0) {
-            $update['used'] = array('+', $rule['num']);
+        if ($status == 2) {
+            $log['balance'] = $user['balance'];
+        } else {
+            $log['balance'] = $user['balance'] + $rule['num'];
         }
-        $update['balance'] = array('+', $rule['num']);
-        $insert['balance'] = $user['balance'] + $rule['num'];
-        $insert['name'] = $name;
-        $insert['id'] = Dever::db('user_log', 'score')->insert($insert);
+        $log['name'] = $name;
+        $log['status'] = $status;
+        $log['id'] = Dever::db('user_log', 'place_score')->insert($log);
 
-        if ($insert['id']) {
-            $state = Dever::db('user', 'score')->update(array('id' => $user['id'], 'udate' => $user['udate']), $update);
+        if ($log['id'] && $status == 1) {
+            if ($rule['num'] > 0) {
+                $update['total'] = array('+', $rule['num']);
+            } elseif ($rule['num'] < 0) {
+                $update['used'] = array('-', $rule['num']);
+            }
+            $update['balance'] = array('total', '-', 'used');
+            $state = Dever::db('user', 'place_score')->update(array('id' => $user['id'], 'udate' => $user['udate']), $update);
             if (!$state) {
                 Dever::error('请求失败请重试');
             }
         }
 
-        return $insert;
+        return $log;
     }
 
     # 返利
@@ -159,7 +157,7 @@ class Log
             $parent_uid = Dever::load('relation', 'invite')->getParent($uid, $level);
             if ($parent_uid && $parent_uid > 0) {
                 $rule['num'] = $value;
-                $this->add($parent_uid, $rule, $log['action_log_id'], $name, $log['id']);
+                $this->inc($parent_uid, $rule, $log['action_log_id'], $name, 1, $log['id']);
             }
         }
     }

+ 33 - 0
src/place/score/lib/Rebate.php

@@ -0,0 +1,33 @@
+<?php namespace Place_score\Lib;
+use Dever;
+class Rebate
+{
+    public function getInfo($type, $type_id)
+    {
+        $html = array();
+        $data = $this->get($type, $type_id);
+        if ($data) {
+            foreach ($data as $v) {
+                $html[] = $v['name'] . '('.$v['percent'].'%)';
+            }
+        }
+        $html = implode('、', $html);
+        return $html;
+    }
+
+    public function get($type, $type_id)
+    {
+        $where['type'] = $type;
+        $where['type_id'] = $type_id;
+        $data = Dever::db('rebate', 'place_score')->select($where, ['col' => 'id,info_id,percent']);
+        if ($data) {
+            foreach ($data as &$v) {
+                $info = Dever::db('info', 'place_score')->find($v['info_id']);
+                $v['name'] = $info['name'];
+                $v['symbol'] = $info['symbol'];
+                $v['symbol_location'] = $info['symbol_location'];
+            }
+        }
+        return $data;
+    }
+}

+ 28 - 0
src/place/score/manage/convert.php

@@ -0,0 +1,28 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'convert_info_id' => array
+            (
+                'type' => 'select',
+                'tips' => '选择要转换的目标积分',
+            ),
+            'value' => array
+            (
+                'tips' => '直接输入要转换的数值,如输入100,就是当前积分100个可以转换1个目标积分',
+                'placeholder' => '输入转换数值',
+            ),
+            'status' => array
+            (
+                'width' => '40',
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+        ),
+    ),
+);

+ 19 - 1
src/place/score/manage/core.php

@@ -8,7 +8,7 @@ return array
             'parent'    => 'sector_place_set',
             'name'      => '积分配置',
             'icon'      => 'currency-fill',
-            'sort'      => '90',
+            'sort'      => '102',
         ),
 
         'info' => array
@@ -19,6 +19,15 @@ return array
             'sort'      => '2',
         ),
 
+        'rule' => array
+        (
+            'parent'    => 'set_score',
+            'name'      => '规则设置',
+            'icon'      => 'currency-line',
+            'sort'      => '100',
+            'show'      => 3,
+        ),
+
         'user' => array
         (
             'parent'    => 'set_score',
@@ -26,5 +35,14 @@ return array
             'icon'      => 'honor-of-kings-line',
             'sort'      => '1',
         ),
+
+        'user_log' => array
+        (
+            'parent'    => 'set_score',
+            'name'      => '积分日志',
+            'icon'      => 'honor-of-kings-line',
+            'sort'      => '100',
+            'show'      => 3,
+        ),
     ),
 );

+ 18 - 7
src/place/score/manage/info.php

@@ -6,7 +6,7 @@ return array
         'field'      => array
         (
             'name',
-            'unit',
+            'exp',
             'symbol',
             'symbol_location',
             'sort' => array
@@ -29,6 +29,14 @@ return array
         'data_button' => array
         (
             '编辑'  => array('fastedit'),
+            '规则设置' => array('route', array
+            (
+                'path' => 'set_score/rule',
+                'param' => array
+                (
+                    'set' => array('info_id' => 'id', 'menu' => 'set_score/info', 'parent' => 'set_score/info'),
+                ),
+            )),
         ),
         'search'    => array
         (
@@ -46,22 +54,25 @@ return array
             'exp' => array
             (
                 'rules' => true,
-                'tips' => '当前积分与支付货币之间的换算关系,填写100,则100积分等于1支付货币<br />当使用该积分进行支付时,将根据换算关系自动转换成支付货币,用以拉起支付',
-            ),
-            'unit' => array
-            (
-                'rules' => true,
+                'tips' => '当前积分与支付货币之间的换算关系,填写100,则100积分等于1支付货币<br />当使用该积分进行支付时,将根据换算关系自动转换成支付货币,用以拉起支付<br />填写0,无法与支付货币自动换算',
             ),
             'symbol' => array
             (
+                'tips' => '将展示在待支付的价格里',
                 'rules' => true,
             ),
             'symbol_location' => array
             (
+                'tips' => '展示在待支付的价格前面还是后面',
                 'rules' => true,
                 'type' => 'radio',
             ),
+            'place_score/convert' => array
+            (
+                'tips' => '设置可以转换成的目标积分,设置之后,可以在积分管理中进行转换',
+                'name' => '转换设置',
+                'where'  => array('info_id' => 'id'),
+            ),
         ),
-        //'end' => ['manage/system.update?system=sector', 'place/manage.updatePlaceCode'],
     ),
 );

+ 29 - 0
src/place/score/manage/rebate.php

@@ -0,0 +1,29 @@
+<?php
+return array
+(
+    'update' => array
+    (
+        'field'    => array
+        (
+            'info_id' => array
+            (
+                'type' => 'select',
+                'tips' => '选择购买当前项目,返利的积分',
+            ),
+            'percent' => array
+            (
+                'tips' => '支持多层级返利,半角逗号隔开<br />第一个为当前用户<br />第二个为当前用户上级<br />第三个为当前用户上上级,以此类推<br />如输入:0,1,2,就是给当前用户返利0%,上级返1%,上上级返2%<br /><span style="color:red">注意:本功能仅返积分,目前仅支持三层返利,请勿违反法律法规</span>',
+                'placeholder' => '输入返利比例数值',
+            ),
+            /*
+            'status' => array
+            (
+                'width' => '40',
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),*/
+        ),
+    ),
+);

+ 90 - 0
src/place/score/manage/rule.php

@@ -0,0 +1,90 @@
+<?php
+$info_id = Dever::input(['set', 'field'])['info_id'] ?? 0;
+return array
+(
+    'list' => array
+    (
+        'where' => array('info_id' => $info_id),
+        'field'      => array
+        (
+            'action_id',
+            'num',
+            'upper',
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+        ),
+        'button' => array
+        (
+            '新增' => array('fastadd', array('info_id' => $info_id)),
+        ),
+        'data_button' => array
+        (
+            '编辑'  => array('fastedit'),
+        ),
+        'search'    => array
+        (
+            'action_id',
+        ),
+    ),
+    'update' => array
+    (
+        'control' => array
+        (
+            'upper_type' => array
+            (
+                'upper' => 2,
+            ),
+            'upper_time' => array
+            (
+                'upper' => 2,
+                'upper_type' => 2,
+            ),
+            'upper_limit' => array
+            (
+                'upper' => 2,
+            ),
+        ),
+        'field'    => array
+        (
+            'info_id',
+            'action_id' => array
+            (
+                'rules' => true,
+            ),
+            'num' => array
+            (
+                'rules' => true,
+            ),
+            'upper' => array
+            (
+                'rules' => true,
+                'type' => 'radio',
+            ),
+            'upper_type' => array
+            (
+                'rules' => true,
+                'type' => 'radio',
+            ),
+            'upper_time' => array
+            (
+                'rules' => true,
+            ),
+            'upper_limit' => array
+            (
+                'rules' => true,
+                'tips' => '按照所选的限制类型设置限制次数<br />如限制类型为按8小时,限制次数填写2,则该积分规则每8个小时仅能生效2次',
+            ),
+            'place_score/rebate' => array
+            (
+                'name' => '返利积分',
+                'tips' => '选择返利积分后,当用户获得积分后,将按照规则返利',
+                'where'  => array('type' => 5,'type_id' => 'id'),
+            ),
+        ),
+    ),
+);

+ 14 - 3
src/place/score/manage/user.php

@@ -5,7 +5,11 @@ return array
     (
         'field'      => array
         (
-            'uid',
+            'uid' => array
+            (
+                'name' => '用户信息',
+                'show' => 'Dever::call("place_user/manage/user.getInfo", {uid})',
+            ),
             'info_id',
             'total',
             'used',
@@ -24,11 +28,18 @@ return array
         ),
         'data_button' => array
         (
-            
+            '积分日志' => array('route', array
+            (
+                'path' => 'set_score/user_log',
+                'param' => array
+                (
+                    'set' => array('user_id' => 'id', 'menu' => 'set_score/user', 'parent' => 'set_score/user'),
+                ),
+            )),
         ),
         'search'    => array
         (
-            'uid',
+            'uid' => 'input',
             'info_id',
         ),
     ),

+ 33 - 0
src/place/score/manage/user_log.php

@@ -0,0 +1,33 @@
+<?php
+$user_id = Dever::input(['set', 'field'])['user_id'] ?? 0;
+return array
+(
+    'list' => array
+    (
+        'where' => array('user_id' => $user_id),
+        'field'      => array
+        (
+            'info_id',
+            'action_id',
+            'mode',
+            'name',
+            'num',
+            'balance',
+            'status',
+            'cdate',
+        ),
+        'button' => array
+        (
+            
+        ),
+        'data_button' => array
+        (
+            
+        ),
+        'search'    => array
+        (
+            'action_id',
+            'status',
+        ),
+    ),
+);

+ 2 - 0
src/place/score/table/action_log.php

@@ -16,11 +16,13 @@ return array
             'type'      => 'int(11)',
             'name'      => '所属行为',
         ),
+        /*
         'ip'       => array
         (
             'type'      => 'varchar(32)',
             'name'      => 'IP地址',
         ),
+        */
     ),
 
     'index' => array

+ 41 - 0
src/place/score/table/convert.php

@@ -0,0 +1,41 @@
+<?php
+return array
+(
+    'name' => '用户积分转换规则表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => array
+    (
+        'info_id'        => array
+        (
+            'name'      => '转换积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+        ),
+
+        'convert_info_id'        => array
+        (
+            'name'      => '目标积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+        ),
+
+        'value' => array
+        (
+            'name'      => '转换数值',
+            'type'      => 'varchar(50)',
+            'default'   => '1',
+        ),
+
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '正常',
+                2 => '封禁',
+            ),
+        ),
+    ),
+);

+ 15 - 7
src/place/score/table/info.php

@@ -3,7 +3,7 @@ return array
 (
     'name' => '用户积分设置表',
     'partition' => 'Dever::call("manage/common.system")',
-    'order' => 'sort asc',
+    'order' => 'sort asc,id asc',
     'struct' => array
     (
         'name' => array
@@ -11,21 +11,29 @@ return array
             'name'      => '积分名称',
             'type'      => 'varchar(32)',
         ),
+        'desc' => array
+        (
+            'name'      => '介绍',
+            'type'      => 'varchar(800)',
+        ),
         'exp' => array
         (
-            'name'      => '积分换算',
-            'type'      => 'varchar(10)',
-            'default'   => '1',
+            'name'      => '货币换算',
+            'type'      => 'varchar(50)',
+            'default'   => '0',
         ),
+        /*
         'unit' => array
         (
             'name'      => '积分单位',
             'type'      => 'varchar(32)',
-        ),
+            'default'   => '元',
+        ),*/
         'symbol' => array
         (
             'name'      => '积分符号',
             'type'      => 'varchar(32)',
+            'default'   => '¥',
         ),
         'symbol_location' => array
         (
@@ -59,10 +67,10 @@ return array
 
     'default' => array
     (
-        'field' => 'name,exp,unit,symbol,cdate',
+        'field' => 'name,exp,symbol,cdate',
         'value' => array
         (
-            '"金币",1,"个","¥",' . DEVER_TIME,
+            '"余额",1,"¥",' . DEVER_TIME,
         ),
         'num' => 1,
     ),

+ 53 - 0
src/place/score/table/rebate.php

@@ -0,0 +1,53 @@
+<?php
+return array
+(
+    'name' => '用户积分返利设置表',
+    'partition' => 'Dever::call("manage/common.system")',
+    'struct' => array
+    (
+        'type'        => array
+        (
+            'name'      => '类型',
+            'type'      => 'tinyint(1)',
+            'value'     => array
+            (
+                1 => '门票',
+                2 => '资源频道',
+                3 => '资源分类',
+                4 => '角色',
+                5 => '积分',
+            ),
+        ),
+
+        'type_id'        => array
+        (
+            'name'      => '类型id',
+            'type'      => 'int(11)',
+        ),
+
+        'info_id'        => array
+        (
+            'name'      => '返利积分',
+            'type'      => 'int(11)',
+            'value'     => 'place_score/info',
+        ),
+
+        'percent' => array
+        (
+            'name'      => '返利比例',
+            'type'      => 'varchar(100)',
+        ),
+
+        'status' => array
+        (
+            'name'      => '状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '正常',
+                2 => '封禁',
+            ),
+        ),
+    ),
+);

+ 10 - 25
src/place/score/table/rule.php

@@ -9,19 +9,19 @@ return array
         (
             'name'      => '积分名称',
             'type'      => 'int(11)',
-            'value'     => 'score/info',
+            'value'     => 'place_score/info',
         ),
 
         'action_id'        => array
         (
             'name'      => '用户行为',
             'type'      => 'int(11)',
-            'value'     => 'score/action',
+            'value'     => 'place_score/action',
         ),
 
         'num'        => array
         (
-            'name'      => '积分数',
+            'name'      => '积分数',
             'type'      => 'varchar(80)',
         ),
 
@@ -39,7 +39,7 @@ return array
 
         'upper_type' => array
         (
-            'name'      => '上限限制类型',
+            'name'      => '限制类型',
             'type'      => 'tinyint(1)',
             'default'   => 1,
             'value'     => array
@@ -60,35 +60,20 @@ return array
         'upper_limit'       => array
         (
             'type'      => 'int(11)',
-            'name'      => '上限限制次数',
+            'name'      => '限制次数',
             'default'   => '2',
         ),
 
-        'rebate'      => array
+        'status' => array
         (
+            'name'      => '状态',
             'type'      => 'tinyint(1)',
-            'name'      => '返利设置',
-            'default'   => '1',
+            'default'   => 1,
             'value'     => array
             (
-                1 => '无返利',
-                2 => '百分比',
-                3 => '数值',
+                1 => '正常',
+                2 => '封禁',
             ),
         ),
-
-        'rebate_info_id'      => array
-        (
-            'type'      => 'int(11)',
-            'name'      => '返利积分名称',
-            'value'     => 'score/info',
-        ),
-        
-        'rebate_value'     => array
-        (
-            'type'      => 'varchar(500)',
-            'name'      => '返利积分数',
-            'desc'      => '如果是百分比类型,这里如果填的是10,那就是当前获得积分数的10%。直接填写数字就是当前用户的上级(1级)返利,支持多层层级设置,1:20,2:30 就是1级20、2级30,同时也支持0级',
-        ),
     ),
 );

+ 2 - 1
src/place/score/table/user.php

@@ -8,7 +8,8 @@ return array
         'uid'       => array
         (
             'type'      => 'int(11)',
-            'name'      => '用户',
+            'name'      => '用户ID',
+            //'value'     => 'place_user/info',
         ),
 
         'info_id'        => array

+ 18 - 2
src/place/score/table/user_log.php

@@ -6,6 +6,11 @@ return array
     //'store' => 'log',
     'struct' => array
     (
+        'user_id'       => array
+        (
+            'type'      => 'int(11)',
+            'name'      => '用户积分数据表id',
+        ),
         'uid'       => array
         (
             'type'      => 'int(11)',
@@ -15,13 +20,13 @@ return array
         (
             'name'      => '积分',
             'type'      => 'int(11)',
-            'value'     => 'score/info',
+            'value'     => 'place_score/info',
         ),
         'action_id'       => array
         (
             'type'      => 'int(11)',
             'name'      => '用户行为',
-            'value'     => 'score/action',
+            'value'     => 'place_score/action',
         ),
         'action_log_id'       => array
         (
@@ -60,6 +65,17 @@ return array
             'name'      => '积分余额',
             'type'      => 'decimal(11,2)',
         ),
+        'status' => array
+        (
+            'name'      => '入账状态',
+            'type'      => 'tinyint(1)',
+            'default'   => 1,
+            'value'     => array
+            (
+                1 => '已入账',
+                2 => '待入账',
+            ),
+        ),
     ),
 
     'index' => array

+ 1 - 1
src/place/set/api/Url.php

@@ -11,7 +11,7 @@ class Url
         if ($info) {
             $extend = Dever::load('common', 'manage')->extend();
             $param['p'] = Place::entry($extend['info_id'], $extend['module_id'], $extend['data_id'], $id);
-            $link = str_replace('https://center.yuandaibao.com/src/place/set/', 'https://place.work.yuandaibao.com/', Dever::url('place_interface/main.home', $param));
+            $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);
         }

+ 1 - 1
src/place/set/lib/Account.php

@@ -30,7 +30,7 @@ class Account
             }
         }
 
-        $order['cash'] = $order['cash']*100;
+        $order['cash'] = $order['pay_cash']*100;
         $order['time_expire'] = time() + 3600;
 
         return Dever::load('account', 'api')->run($account, 'order', $order, $env, 'run', $project);

+ 0 - 77
src/place/set/lib/Manage.php

@@ -1,77 +0,0 @@
-<?php namespace Place\Lib;
-use Dever;
-use Manage\Lib\Auth;
-class Manage extends Auth
-{
-    # 获取身份的树形列表
-    public function getTree()
-    {
-        $extend = Dever::load('common', 'manage')->extend();
-        $data = Dever::db('info', 'place')->find(array('id' => $extend['data_id']));
-        $result = array();
-        $result[] = array
-        (
-            'id' => 'root',
-            'name' => '身份',
-            'children' => array($data),
-        );
-        return $result;
-    }
-
-    # 检测身份码
-    public function checkCode($db, $data)
-    {
-        if (isset($data['code']) && $data['code']) {
-            $code = Dever::db('code', 'place')->find(['code' => $data['code']]);
-            if ($code) {
-                if (isset($data['id']) && $data['id'] == $code['id']) {
-                    return $data;
-                }
-                Dever::error('身份码已存在');
-            }
-        }
-        return $data;
-    }
-
-    # 更新身份码
-    public function updateCode($db, $data)
-    {
-        if (isset($data['code']) && $data['code']) {
-            $code = Dever::db('code', 'place')->find(['code' => $data['code']]);
-            if (!$code) {
-                $extend = Dever::load('common', 'manage')->extend();
-                $module = Dever::db('system_module', 'manage')->find($extend['module_id']);
-                if ($module['key'] == 'sector_place') {
-                    $module = Dever::db('system_module', 'manage')->find(array('key' => 'sector_user'));
-                }
-                $update['code'] = $data['code'];
-                $update['sector_id'] = $extend['info_id'];
-                $update['module_id'] = $module['id'];
-                $update['user_id'] = $extend['data_id'];
-                $update['place_id'] = $data['id'];
-                Dever::db('code', 'place')->insert($update);
-            }
-        }
-    }
-
-    # 获取支付账户列表
-    public function getAccountList($uid = false)
-    {
-        $data = array
-        (
-            0 => array
-            (
-                'id' => -1,
-                'name' => '平台默认账户',
-            ),
-        );
-        if ($uid) {
-            $where['uid'] = $uid;
-        } else {
-            $extend = Dever::load('common', 'manage')->extend();
-            $where['uid'] = $extend['data_id'];
-        }
-        $data = array_merge($data, Dever::db('account', 'place')->select($where));
-        return $data;
-    }
-}

+ 195 - 0
src/place/set/lib/Role.php

@@ -0,0 +1,195 @@
+<?php namespace Place\Lib;
+use Dever;
+use Place;
+class Role
+{
+    public function __construct($name, $type)
+    {
+        $this->type = $type;
+        $this->name = $name;
+        $this->db = Dever::db($this->name, 'place');
+        $this->key = $this->name . '_id';
+    }
+
+    # 获取会员列表
+    public function getList($id = false)
+    {
+        $where = array('status' => 1);
+        if ($id) {
+            $where['id'] = $id;
+        }
+        # 获取当前等级
+        $user = $info = array();
+        if (Place::$user && Place::$user[$this->key]) {
+            $info = $this->db->find(Place::$user[$this->key]);
+            if ($info) {
+                $user = Dever::db('role', 'place_user')->find(array('uid' => Place::$uid, 'type' => $this->type, 'type_id' => $info['id'], 'status' => 1));
+            }
+            if ($user && $user['edate'] > time()) {
+                $where['level'] = array('>=', $info['level']);
+                if ($user['edate']) {
+                    $user['edate_str'] = date('Y-m-d H:i:s', $user['edate']); 
+                } else {
+                    $user['edate_str'] = '永久'; 
+                }
+            } else {
+                # 已过期
+                Dever::db('info', 'place_user')->update(Place::$uid, array($this->key => 0));
+                if ($user) {
+                    Dever::db('role', 'place_user')->update($user['id'], ['status' => 2]);
+                }
+                $user = array();
+            }
+        }
+        
+        $data['list'] = array();
+        $list = $this->db->select($where, array('col' => 'id,name,level,price,day_desc,day,content,pay'));
+        if ($list) {
+            foreach ($list as $v) {
+                # 获取权益
+                $v['profit'] = $this->getProfit($v['id']);
+                if ($v['profit']) {
+                    $v['content'] = htmlspecialchars_decode($v['content']);
+                    if ($user && $info) {
+                        if ($v['id'] == $info['id']) {
+                            $data['user'] = $v;
+                            $data['user']['edate_str'] = $user['edate_str'];
+                        } elseif ($v['pay'] == 1) {
+                            $v['price'] -= $info['price'];
+                        }
+                    }
+                    $v['type'] = $this->type;
+                    $data['list'][] = $v;
+                }
+            }
+        }
+        
+        return $data;
+    }
+
+    # 获取权益
+    public function getProfit($table_id)
+    {
+        $profit = Dever::db($this->name . '_profit', 'place')->select(array($this->key => $table_id, 'status' => 1));
+        if ($profit) {
+            $result = array();
+            foreach ($profit as $v) {
+                if ($v['type']) {
+                    $temp = explode(',', $v['type']);
+                    $type = $temp[0];
+                    $type_id = $temp[1];
+                    if ($type == 1) {
+                        $channel = Dever::db('channel', 'place_source')->find($type_id);
+                        $name = array();
+                        if ($channel) {
+                            $name[] = $channel['name'];
+                        }
+                        if (isset($temp[2])) {
+                            $cate = Dever::db('cate', 'place_source')->find($temp[2]);
+                            if ($cate) {
+                                $name[] = $cate['name'];
+                            }
+                        }
+                        $name = implode('-', $name);
+                    } elseif ($type == 2) {
+                        $name = Dever::db('role', 'place_user')->value('type', $type_id);
+                    }
+                    $desc = array();
+                    if ($this->name == 'vip') {
+                        if ($v['discount']) {
+                            $desc[] = $v['discount'] . '折购买';
+                        }
+                        if ($v['limit']) {
+                            $desc[] = '每日查看上限' . $v['limit'] . '次';
+                        }
+                    } elseif ($this->name == 'saler') {
+                        if ($v['percent']) {
+                            $desc[] = '佣金' . $v['percent'] . '%';
+                        }
+                    } elseif ($this->name == 'agent') {
+                        if ($v['percent']) {
+                            $desc[] = '团队利润分成' . $v['percent'] . '%';
+                        }
+                    }
+                    
+                    if ($desc) {
+                        $desc = implode('/', $desc);
+                    }
+                    $result[] = array('name' => $name, 'desc' => $desc);
+                }
+            }
+            return $result;
+        }
+        return false;
+    }
+
+    # 获取购买资源的价格列表
+    /*
+    public function getSourcePrice($price, $info_id, $type)
+    {
+        $sets = Dever::db('user_role', 'place_user')->select(array('info_id' => $info_id));
+
+        $result = array();
+        $result['list'] = array();
+        $result['alone'] = array();
+        if ($info = $this->info) {
+            $type_id = $this->type . '_id';
+            $table = $this->type . '_price';
+            $result['name'] = Place::$info[$this->type . '_name'];
+            $list = array();
+            $alone = array();
+            $func = Dever::load('price', 'place');
+            $sets = Dever::db($table, 'place_user')->select(array('info_id' => $info_id));
+            if ($sets) {
+                foreach ($sets as $set) {
+                    $set['value'] = $func->getValue($set['value'], $price, $type);
+                    $set['text'] = $func->getText($set['value'], $type);
+                    if ($set[$type_id]) {
+                        $set[$type_id] = explode(',', $set[$type_id]);
+                        foreach ($set[$type_id] as $id) {
+                            if (isset($info[$id])) {
+                                $list[$id] = array($info[$id], $set['value'], $set['text']);
+                                unset($info[$id]);
+                                if ($set['status'] == 1) {
+                                    $alone[$id] = $list[$id];
+                                }
+                            }
+                        }
+                    } elseif ($info) {
+                        foreach ($info as $id => $name) {
+                            if (empty($list[$id])) {
+                                $list[$id] = array($name, $set['value'], $set['text']);
+                                unset($info[$id]);
+                            }
+                            if ($set['status'] == 1) {
+                                $alone[$id] = $list[$id];
+                            }
+                        }
+                    }
+                }
+            }
+            if ($info) {
+                foreach ($info as $id => $name) {
+                    if (empty($list[$id])) {
+                        $info = Dever::db($table, 'place')->find(array($type_id => $id, 'type' => $type));
+                        if ($info) {
+                            $value = $func->getValue($info['per'], $price, 3);
+                            $text = $func->getText($value, $type);
+                            $list[$id] = array($name, $value, $text);
+                        }
+                    }
+                }
+            }
+            $result['list'] = $list;
+            $result['alone'] = $alone;
+        }
+        return $result;
+    }
+    */
+
+    # 获取佣金
+    public function add()
+    {
+        
+    }
+}

+ 25 - 0
src/place/set/manage/Lib/Account.php

@@ -0,0 +1,25 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Account
+{
+    # 获取支付账户列表
+    public function getList($uid = false)
+    {
+        $data = array
+        (
+            0 => array
+            (
+                'id' => -1,
+                'name' => '平台默认账户',
+            ),
+        );
+        if ($uid) {
+            $where['uid'] = $uid;
+        } else {
+            $extend = Dever::load('common', 'manage')->extend();
+            $where['uid'] = $extend['data_id'];
+        }
+        $data = array_merge($data, Dever::db('account', 'place')->select($where));
+        return $data;
+    }
+}

+ 43 - 0
src/place/set/manage/Lib/Api.php

@@ -0,0 +1,43 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Api
+{
+    # 获取权益所需要的信息:具体项目选择
+    public function getProfitInfo($value)
+    {
+        if (is_array($value)) {
+            $result = array();
+            $result['type_id']['value'] = array();
+            if ($value[0] == 1) {
+                $result['type_id']['option'] = Dever::db('info', 'place_source')->select(array('cate_parent_id' => $value[2]));
+            } else {
+                $result['type_id']['option'] = Dever::db('level', 'place_role')->select(['info_id' => $value[1]]);
+            }
+            
+            //$result['type_id']['url'] = Dever::url('place/manage.getProfitData', ['s' => $value]);
+            return $result;
+        }
+    }
+
+    # 获取权益所需要的信息:项目下的数据
+    public function getProfitData()
+    {
+        return Dever::load('common', 'manage')->cascader(2, function($level, $parent) {
+            $data = array();
+            if ($level == 1) {
+                $data = array
+                (
+                    array('id' => 1, 'name' => '资源'),
+                    array('id' => 2, 'name' => '角色'),
+                );
+            } elseif ($level == 2) {
+                if ($parent == 1) {
+                    $data = Dever::db('channel', 'place_source')->select([]);
+                } elseif ($parent == 2) {
+                    $data = Dever::db('info', 'place_role')->select(['status' => 1]);
+                }
+            }
+            return $data;
+        });
+    }
+}

+ 53 - 0
src/place/set/manage/Lib/Code.php

@@ -0,0 +1,53 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Code
+{
+    # 检测身份码
+    public function check($db, $data)
+    {
+        if (isset($data['id']) && $data['id']) {
+            $info = $db->find($data['id']);
+            if ($info['name'] != $data['name']) {
+                Dever::load('manage/place', 'place')->update($data['id']);
+            } elseif ($info['logo'] != $data['logo']) {
+                Dever::load('manage/place', 'place')->update($data['id']);
+            }
+        }
+        if (isset($data['code']) && $data['code']) {
+            $code = Dever::db('code', 'place')->find(['code' => $data['code']]);
+            if ($code) {
+                if (isset($data['id']) && $data['id'] == $code['id']) {
+                    return $data;
+                }
+                Dever::error('身份码已存在');
+            }
+        }
+        return $data;
+    }
+
+    # 更新身份码
+    public function update($db, $data)
+    {
+        if (isset($data['code']) && $data['code']) {
+            $code = Dever::db('code', 'place')->find(['code' => $data['code']]);
+            if (!$code) {
+                $extend = Dever::load('common', 'manage')->extend();
+                $module = Dever::db('system_module', 'manage')->find($extend['module_id']);
+                if ($module['key'] == 'sector_place') {
+                    $module = Dever::db('system_module', 'manage')->find(array('key' => 'sector_user'));
+                }
+                $update['sector_id'] = $extend['info_id'];
+                $update['module_id'] = $module['id'];
+                $update['user_id'] = $extend['data_id'];
+                $update['place_id'] = $data['id'];
+                $info = Dever::db('code', 'place')->find($update);
+                $update['code'] = $data['code'];
+                if ($info) {
+                    Dever::db('code', 'place')->update($info['id'], $update);
+                } else {
+                    Dever::db('code', 'place')->insert($update);
+                }
+            }
+        }
+    }
+}

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

@@ -0,0 +1,11 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Nav
+{
+    # 更新导航
+    public function update($db, $data)
+    {
+        $extend = Dever::load('common', 'manage')->extend();
+        Dever::load('manage/place', 'place')->update($extend['data_id']);
+    }
+}

+ 43 - 0
src/place/set/manage/Lib/Place.php

@@ -0,0 +1,43 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Place
+{
+    # 更新个人身份的版本号
+    public function update($id)
+    {
+        return Dever::db('info', 'place')->update($id, ['update' => time()]);
+    }
+
+    # 获取身份的树形列表
+    public function getTree()
+    {
+        $extend = Dever::load('common', 'manage')->extend();
+        $data = Dever::db('info', 'place')->find(array('id' => $extend['data_id']));
+        $result = array();
+        $result[] = array
+        (
+            'id' => 'root',
+            'name' => '身份',
+            'children' => array($data),
+        );
+        return $result;
+    }
+
+    # 获取资源默认值
+    public function getResourceDefault($field)
+    {
+        $db = Dever::db('info', 'place_source');
+        $option = array();
+        foreach ($db->value('type') as $k => $v) {
+            $info = array('type' => $v['id'], 'status' => 1);
+            foreach ($field as $k1 => $v1) {
+                if (isset($v[$v1])) {
+                    $v1 = $v[$v1];
+                }
+                $info[$k1] = $v1;
+            }
+            $option[] = $info;
+        }
+        return $option;
+    }
+}

+ 30 - 0
src/place/set/manage/Lib/Profit.php

@@ -0,0 +1,30 @@
+<?php namespace Place\Manage\Lib;
+use Dever;
+class Profit
+{
+    # 更新角色权益
+    public function update($db, $data)
+    {
+        if ($data['select']) {
+            $data['select'] = explode(',', $data['select']);
+            $update['parent_id'] = $data['select'][0];
+            $update['child_id'] = $data['select'][1];
+            $db->update($data['id'], $update);
+        }
+    }
+
+    # 获取权益需要的信息
+    public function getInfo()
+    {
+        $channel = Dever::load('manage/cate', 'place_source')->getList(false);
+        $role = Dever::db('info', 'place_role')->select(['status' => 1]);
+        $data = array
+        (
+            array('id' => 1, 'name' => '资源', 'children' => $channel),
+        );
+        if ($role) {
+            $data[] = array('id' => 2, 'name' => '角色', 'children' => $role);
+        }
+        return $data;
+    }
+}

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

@@ -62,5 +62,13 @@ return array
             'sort'      => '1',
             'path'      => 'update',
         ),
+
+        'nav' => array
+        (
+            'parent'    => 'set_manage',
+            'name'      => '导航设置',
+            'icon'      => 'menu-add-fill',
+            'sort'      => '2',
+        ),
     ),
 );

+ 7 - 6
src/place/set/manage/info.php

@@ -2,13 +2,14 @@
 $config = include('place.php');
 $config['update']['desc'] = '';
 
-$data = Dever::load('manage', 'place')->getTree();
+$data = Dever::load('manage/place', 'place')->getTree();
 $id = $data[0]['children'][0]['id'];
 $uid = $data[0]['children'][0]['uid'];
 $user = Dever::db('user', 'sector')->find($uid);
-if ($user['channel'] == 1) {
-    $config['update']['tab']['供货设置'] = 'channel,place/client_price,place/client';
-    $config['update']['field']['channel'] = array
+/*
+if ($user['supplier'] == 12) {
+    $config['update']['tab']['供货设置'] = 'supplier,place/client_price,place/client';
+    $config['update']['field']['supplier'] = array
     (
         'type' => 'radio',
         'tips' => '开启后,将拥有源主供货能力',
@@ -26,7 +27,7 @@ if ($user['channel'] == 1) {
         'where'  => array('id' => array('>', 0)),
         'desc' => '设置后,如果n天内的销量达到预设值,将在默认基础折扣上再计算折扣',
     );
-}
+}*/
 $config['update']['column'] = array
 (
     'load' => 'place/info',
@@ -37,7 +38,7 @@ $config['update']['column'] = array
     'where' => 'id',
     'hidden' => true,
 );
-$config['update']['field']['pay_account']['option'] = 'Dever::call("place/manage.getAccountList", '.$uid.')';
+$config['update']['field']['pay_account']['option'] = 'Dever::call("place/manage/account.getList", '.$uid.')';
 return array
 (
     'source' => 'place/info',

+ 92 - 0
src/place/set/manage/nav.php

@@ -0,0 +1,92 @@
+<?php
+return array
+(
+    'list' => array
+    (
+        'field'      => array
+        (
+            'name',
+            'type',
+            'sort' => array
+            (
+                'type' => 'input',
+                'tips' => '双击修改排序,正序排序',
+            ),
+            'status' => array
+            (
+                'type' => 'switch',
+                'show'  => '{status}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ),
+            //'cdate',
+        ),
+        'button' => array
+        (
+            '新增' => array('fastadd'),
+        ),
+        'data_button' => array
+        (
+            '编辑' => array('fastedit'),
+        ),
+        'search'    => array
+        (
+            'name',
+            'type',
+            'status',
+        ),
+    ),
+    'update' => array
+    (
+        'end' => 'place/manage/nav.update',
+        'control' => array
+        (
+            'type_id' => array
+            (
+                'type' => 10,
+            ),
+        ),
+
+        'field'    => array
+        (
+            'name' => array
+            (
+                'rules' => true,
+            ),
+            'pc_name' => array
+            (
+                //'rules' => true,
+            ),
+            'type' => array
+            (
+                'rules' => true,
+            ),
+            'type_id' => array
+            (
+                'name' => '资源频道',
+                'rules' => true,
+            ),
+            'icon' => array
+            (
+                'tips' => '如果未上传图标,将按照类型生成默认图标',
+                'type' => 'upload',
+                'upload' => '1',
+                'yun' => true,
+                'multiple' => false,
+                'limit' => 1,
+                'style' => 'pic',
+            ),
+            'icon_select' => array
+            (
+                'tips' => '如果未上传图标,将按照类型生成默认图标',
+                'type' => 'upload',
+                'upload' => '1',
+                'yun' => true,
+                'multiple' => false,
+                'limit' => 1,
+                'style' => 'pic',
+                'desc' => '图标可以到<a href="https://www.iconfont.cn/" target="_blank">https://www.iconfont.cn/</a>获取',
+            ),
+        ),
+    ),
+);

+ 5 - 4
src/place/set/manage/place.php

@@ -61,7 +61,7 @@ return array
             (
                 'rules' => true,
                 'type' => 'select',
-                'option'    => 'Dever::call("place/manage.getAccountList")',
+                'option'    => 'Dever::call("place/manage/account.getList")',
             ),
 
             'money_id' => array
@@ -96,6 +96,7 @@ return array
                 'tip' => '',
                 'style' => 'pic',
             ),
+            /*
             'bg' => array
             (
                 'type' => 'upload',
@@ -104,7 +105,7 @@ return array
                 'multiple' => false,
                 'tip' => '',
                 'style' => 'pic',
-            ),
+            ),*/
             'content' => array
             (
                 'type' => 'editor',
@@ -126,7 +127,7 @@ return array
                 'type' => 5,
             ),
         ),
-        'start' => 'place/manage.checkCode',
-        'end' => ['manage/system.update?system=sector', 'place/manage.updateCode'],
+        'start' => 'place/manage/code.check',
+        'end' => ['manage/system.update?system=sector', 'place/manage/code.update'],
     ),
 );

+ 6 - 0
src/place/set/table/code.php

@@ -34,4 +34,10 @@ return array
             'type'      => 'varchar(80)',
         ),
     ),
+
+    'index' => array
+    (
+        'search' => 'sector_id,module_id,user_id,place_id',
+        'code' => 'code',
+    ),
 );

+ 15 - 1
src/place/set/table/info.php

@@ -63,7 +63,7 @@ return array
             'type'      => 'decimal(11,2)',
         ),
 
-        'channel' => array
+        'supplier' => array
         (
             'name'      => '供货能力',
             'type'      => 'tinyint(1)',
@@ -89,6 +89,13 @@ return array
             'default'   => '1',
             'value'     => 'sector/money',
         ),
+        
+        'score_name' => array
+        (
+            'name'      => '积分名称',
+            'type'      => 'varchar(32)',
+            'default'   => '积分',
+        ),
 
         'status' => array
         (
@@ -101,5 +108,12 @@ return array
                 2 => '禁用',
             ),
         ),
+
+        'update' => array
+        (
+            'name'      => '更新版本号',
+            'type'      => 'int(11)',
+            'default'   => 1,
+        ),
     ),
 );

部分文件因文件數量過多而無法顯示