From 1084f165b2e821695a2bff40c9c8e674a0765310 Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Tue, 3 Aug 2021 19:13:06 +0800 Subject: [PATCH] add-api-distribution --- admin/controllers/app/liche/Main.php | 16 +- admin/controllers/app/liche/Member.php | 4 +- .../appdistribution/Distribution.php | 410 ++++++++++++++++++ admin/views/app/liche/member/lists.php | 4 +- .../appdistribution/team/get_accountlog.php | 124 ++++++ .../appdistribution/team/get_commission.php | 93 ++++ admin/views/appdistribution/team/get_team.php | 130 ++++++ admin/views/appdistribution/team/lists.php | 102 +++++ api/controllers/Hd.php | 57 +++ api/controllers/wxapp/distribution/Cash.php | 139 ++++++ .../wxapp/distribution/Commission.php | 36 ++ api/controllers/wxapp/distribution/Home.php | 232 ++++++++++ api/controllers/wxapp/distribution/Team.php | 186 ++++++++ api/controllers/wxapp/liche/User.php | 7 +- common/libraries/entity/Deal_entity.php | 308 +++++++++++++ common/models/app/App_model.php | 27 ++ common/models/app/Deal_log_model.php | 17 + common/models/app/User_account_model.php | 15 + sql/app/app.sql | 22 + sql/app/liche.sql | 3 +- 20 files changed, 1923 insertions(+), 9 deletions(-) create mode 100755 admin/controllers/appdistribution/Distribution.php create mode 100755 admin/views/appdistribution/team/get_accountlog.php create mode 100755 admin/views/appdistribution/team/get_commission.php create mode 100755 admin/views/appdistribution/team/get_team.php create mode 100755 admin/views/appdistribution/team/lists.php create mode 100755 api/controllers/wxapp/distribution/Cash.php create mode 100755 api/controllers/wxapp/distribution/Commission.php create mode 100644 api/controllers/wxapp/distribution/Home.php create mode 100755 api/controllers/wxapp/distribution/Team.php create mode 100755 common/libraries/entity/Deal_entity.php create mode 100755 common/models/app/Deal_log_model.php diff --git a/admin/controllers/app/liche/Main.php b/admin/controllers/app/liche/Main.php index b57c6a5f..fbf0d8b4 100644 --- a/admin/controllers/app/liche/Main.php +++ b/admin/controllers/app/liche/Main.php @@ -60,7 +60,18 @@ class Main extends HD_Controller 'value' => $value, 'btns' => array( array('name' => '查看详情', 'url' => '/topics/topics?app_id=' . $this->app_id), - //array('name' => '查看详情', 'url' => '/sys/company?app_id=' . $this->app_id), + ), + ); + + $conditions[] = array('icon' => 'am-icon-home', 'list' => $list); + /*小程序设置 end*/ + + $list = []; + $list[] = array( + 'title' => '分销用户(人)', + 'value' => 0, + 'btns' => array( + array('name' => '查看详情', 'url' => '/appdistribution/distribution?app_id='.$this->app_id), ), ); @@ -74,13 +85,12 @@ class Main extends HD_Controller array('name' => '查看详情', 'url' => '/order/purchase?app_id=' . $this->app_id), ), ); - $conditions[] = array('icon' => 'am-icon-home', 'list' => $list); - /*小程序设置 end*/ /*实时数据 end*/ $this->data['conditions'] = $conditions; + $conditions[] = array('icon' => 'am-icon-home', 'list' => $list); $this->data['_title'] = '狸车'; return $this->show_view('/app/main', true); diff --git a/admin/controllers/app/liche/Member.php b/admin/controllers/app/liche/Member.php index d836e461..48febcdb 100755 --- a/admin/controllers/app/liche/Member.php +++ b/admin/controllers/app/liche/Member.php @@ -110,11 +110,11 @@ class Member extends HD_Controller{ public function edit() { $id = $this->input->post('id'); - $ifdist = $this->input->post('ifdist'); + $dealer = $this->input->post('dealer'); $upd = [ - 'ifdist' => $ifdist, + 'dealer' => $dealer, ]; $this->userM->update($upd, array('id' => $id)); diff --git a/admin/controllers/appdistribution/Distribution.php b/admin/controllers/appdistribution/Distribution.php new file mode 100755 index 00000000..89456528 --- /dev/null +++ b/admin/controllers/appdistribution/Distribution.php @@ -0,0 +1,410 @@ +load->model('app/User_account_model', 'mdUserAccount'); + $this->load->model('app/User_accountlog_model', 'mdUserAccountLog'); + $this->load->model('app/Deal_log_model', 'mdDealLog'); + if ($this->app_id) { + $this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser'); + if ($this->app_info()['lock_fans'] == 1) { + $this->statisticalAry = array(1 => '团队', 2 => '粉丝'); + } else { + $this->statisticalAry = array(1 => '团队'); + } + } + } + + //首页信息 + public function index() + { + $this->lists(); + } + + //数据列表 + public function lists() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 10; + $params['statistical'] = $params['statistical'] ? intval($params['statistical']) : 1; + $res = $this->teamSelect($params); + $lists = $res['lists']; + $count = $res['count']; + $this->data['params'] = $res['params']; + + $this->data['_title'] = '分销用户列表'; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + $this->data['statistical_ary'] = $this->statisticalAry; + $this->data['statistical_name'] = $this->statisticalAry[$params['statistical']]; + $this->data['lists'] = $lists; + return $this->show_view('appdistribution/team/lists', true); + } + + /** + * Notes:分销用户 + * Created on: 2020/7/15 10:45 + * Created by: dengbw + * @param $params + * @return mixed + */ + private function teamSelect($params) + { + $lists = array(); + $count = 0; + $where = array('dealer' => 1, 'up_uid' => 0); + if ($params['nickname']) { + $where['nickname LIKE "%' . trim($params['nickname']) . '%"'] = NULL; + } + if ($params['mobile']) { + $where['mobile LIKE "%' . trim($params['mobile']) . '%"'] = NULL; + } + $res = $this->mdAppUser->select($where, "id desc", $params['page'], $params['size'], 'id,mobile,nickname'); + if ($res) { + if (!$params['export']) { + $count = $this->mdAppUser->count($where); + } + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['mobile'] = $value['mobile']; + $setValue['nickname'] = $value['nickname']; + if ($params['statistical'] == 1) { + $setValue['nums'] = $this->mdAppUser->count(array('dealer' => 1, 'up_uid' => $value['id'])) + 1; + $orders = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'])); + $orders_suc = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'status' => 1)); + $orders_suc > $orders && $orders = $orders_suc; + $setValue['orders'] = $orders; + $setValue['orders_suc'] = $orders_suc; + $sum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'status' => 1)); + $setValue['money'] = number_format_com($sum['money']); + } else if ($params['statistical'] == 2) { + $setValue['nums'] = $this->mdAppUser->count(array('dealer' => 0, 'up_uid' => $value['id'])); + $orders = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2)); + $orders_suc = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2, 'status' => 1)); + $orders_suc > $orders && $orders = $orders_suc; + $setValue['orders'] = $orders; + $setValue['orders_suc'] = $orders_suc; + $sum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2, 'status' => 1)); + $setValue['money'] = number_format_com($sum['money']); + } + $lists[] = $setValue; + } + } + $data['lists'] = $lists; + $data['count'] = $count; + $data['params'] = $params; + return $data; + } + + /** + * Notes:分销团队 + * Created on: 2020/7/20 17:48 + * Created by: dengbw + * @return bool + * @throws Hd_exception + */ + public function get_team() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 10; + $up_uid = $params['up_uid']; + $this->app_id = $params['app_id']; + if (!$up_uid || !$this->app_id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $reU = $this->mdAppUser->get(array('id' => $up_uid)); + if ($reU['dealer'] != 1 || $reU['up_uid'] != 0) { + throw new Hd_exception('不是团长', API_CODE_FAIL); + } + $this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser'); + $lists = $where = array(); + $_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】分销团队' : '分销团队'; + $where_base = array('app_id' => $this->app_id, 'app_uid' => $up_uid); + if (!$params['time']) { + $params['time'] = date('Y-m-d') . ' ~ ' . date('Y-m-d'); + } + if ($params['time']) { + $time = explode(' ~ ', $params['time']); + $time[0] && $where_base["c_time >="] = strtotime($time[0] . ' 00:00:00'); + $time[1] && $where_base["c_time <="] = strtotime($time[1] . ' 23:59:59'); + $params['time_str'] = str_replace(" ~ ", " 至 ", $params['time']); + } + if ($params['statistical'] == 1) {//团员 + $where = array('dealer' => 1, 'up_uid' => $up_uid); + if ($params['page'] == 1) { + $where1 = $where2 = $where_base; + $where1['type in(0,2)'] = null; + $where2['type in(0,2)'] = null; + $where2['status'] = 1; + $myValue['id'] = $up_uid; + $myValue['type'] = 0; + $myValue['mobile'] = $reU['mobile']; + $myValue['nickname'] = $reU['nickname'] . '(团长)'; + $myValue['orders'] = $this->mdDealLog->count($where1); + $myValue['orders_suc'] = $this->mdDealLog->count($where2); + $mySum = $this->mdDealLog->sum('money', $where2); + $myValue['bring_money'] = number_format_com($mySum['money']); + $lists[] = $myValue; + } + } else if ($params['statistical'] == 2) {//粉丝 + $where = array('dealer' => 0, 'up_uid' => $up_uid); + } + $resU = $this->mdAppUser->select($where, 'id DESC', $params['page'], $params['size'], 'id,nickname,mobile'); + $count = $this->mdAppUser->count($where); + $params['statistical'] == 1 && $count += 1; + if ($count) { + foreach ($resU as $key => $value) { + $setValue = array(); + $setValue['id'] = $value['id']; + $setValue['type'] = 1; + $setValue['mobile'] = $value['mobile']; + $setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户'; + if ($params['statistical'] == 1) { + $where1 = $where2 = $where_base; + $where1['t_uid'] = $value['id']; + $where1['type in(1,3)'] = null; + $where2['t_uid'] = $value['id']; + $where2['type in(1,3)'] = null; + $where2['status'] = 1; + $orders = $this->mdDealLog->count($where1); + $orders_suc = $this->mdDealLog->count($where2); + $orders_suc > $orders && $orders = $orders_suc; + $setValue['orders'] = $orders; + $setValue['orders_suc'] = $orders_suc; + $sum = $this->mdDealLog->sum('money', $where2); + $setValue['bring_money'] = number_format_com($sum['money']); + } else if ($params['statistical'] == 2) { + $where1 = $where_base; + $where1['t_uid'] = $value['id']; + $where1['type'] = 2; + $where1['status'] = 1; + $setValue['orders'] = $this->mdDealLog->count($where1); + $sum = $this->mdDealLog->sum('money', $where1); + $setValue['bring_money'] = number_format_com($sum['money']); + } + $lists[] = $setValue; + } + } + $this->data['team_orders'] = $this->mdDealLog->count($where_base); + $where3 = $where_base; + $where3['status'] = 1; + $this->data['team_orders_suc'] = $this->mdDealLog->count($where3); + $sum = $this->mdDealLog->sum('money', $where3); + $this->data['team_money'] = number_format_com($sum['money']); + $this->data['_title'] = $_title; + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + return $this->show_view('appdistribution/team/get_team', true); + } + + /** + * Notes:佣金明细 + * Created on: 2020/7/20 17:48 + * Created by: dengbw + * @return bool + */ + public function get_commission() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + $status = $params['status']; + $app_uid = $params['app_uid']; + $this->app_id = $params['app_id']; + if (!$app_uid || !$this->app_id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser'); + //$this->load->model('apporder/order_purchase_model', 'mdOrderPurchase'); + //$this->load->model('appitem/items_model', 'mdItems'); + + $lists = array(); + $statusAry = array(0 => '进行中', 1 => '已完成', -1 => '已失效'); + $reU = $this->mdAppUser->get(array('id' => $app_uid)); + $_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】佣金明细' : '佣金明细'; + $where['app_id'] = $this->app_id; + $where['app_uid'] = $app_uid; + if (status_verify($status)) { + $where['status'] = $status; + } + if ($params['time']) { + $time = explode(' ~ ', $params['time']); + $time[0] && $where["c_time >="] = strtotime($time[0] . ' 00:00:00'); + $time[1] && $where["c_time <="] = strtotime($time[1] . ' 23:59:59'); + } + $count = $this->mdDealLog->count($where); + if ($count) { + $res = $this->mdDealLog->select($where, 'id DESC', $params['page'], $params['size'], 'cf_sid,type,status,money,c_time'); + foreach ($res as $key => $value) { + $setValue = array(); + $reOp = $this->mdOrderPurchase->get(array('sid' => $value['cf_sid']), 'item_id,item_title,item_num + ,total_price,sku_id,app_uid'); + $source = $item_title = ''; + $item_num = 0; + $total_price = $expect_money = 0.00; + if ($reOp) { + $item_title = $reOp['item_title']; + $item_num = $reOp['item_num']; + $total_price = $reOp['total_price']; + if ($value['type'] == 0) {//自己购买 + $source .= '自己购买'; + } else if ($value['type'] == 1) {//团员购买 + $reU = $this->mdAppUser->get(array('id' => $reOp['app_uid']), 'nickname'); + $source .= '团员 ' . $reU['nickname']; + } else if ($value['type'] == 2) {//粉丝购买 + $reU = $this->mdAppUser->get(array('id' => $reOp['app_uid']), 'nickname'); + $source .= '粉丝 ' . $reU['nickname']; + } else if ($value['type'] == 3) {//团员粉丝购买 + $reU = $this->mdAppUser->get(array('id' => $reOp['app_uid']), 'nickname,up_uid'); + if ($this->app_info()['lock_fans'] == 1) { + $reU2 = $this->mdAppUser->get(array('id' => $reU['up_uid']), 'nickname'); + } else { + $reU2 = $this->mdAppUser->get(array('id' => $value['t_uid']), 'nickname'); + } + $nickname = $reU['nickname'] ? $reU['nickname'] : '神秘人'; + $nickname2 = $reU2['nickname'] ? $reU2['nickname'] : '神秘人'; + if ($reU2) { + $source .= '团粉 ' . $nickname2 . '>>' . $nickname; + } else { + $source .= '团粉 ' . $nickname; + } + } + } + $setValue['source'] = $source; + $setValue['status'] = $value['status']; + $setValue['status_name'] = $statusAry[$value['status']]; + $setValue['expect_money'] = $value['money']; + $setValue['item_title'] = $item_title; + $setValue['item_num'] = $item_num; + $setValue['total_price'] = number_format_com($total_price); + $setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']); + $lists[] = $setValue; + } + } + $this->data['_title'] = $_title; + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['statusAry'] = $statusAry; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + return $this->show_view('appdistribution/team/get_commission', true); + } + + /** + * Notes:账户资金流水 + * Created on: 2020/7/20 17:51 + * Created by: dengbw + * @return bool + */ + public function get_accountlog() + { + $trade_type_ary = array(1 => '入账', 2 => '提现', 3 => '冲正'); + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + $this->app_id = $params['app_id']; + $app_uid = $params['app_uid']; + if (!$app_uid || !$this->app_id) { + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser'); + $reAc = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $app_uid)); + $account_id = $reAc['id']; + if (!$account_id) { + return $this->show_json(SYS_CODE_FAIL, '无此用户'); + } + $reU = $this->mdAppUser->get(array('id' => $app_uid)); + $_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】资金流水' : '资金流水'; + $where['account_id'] = $account_id; + if ($params['trade_type']) { + $where['trade_type'] = $params['trade_type']; + } + if ($params['time']) { + $time = explode(' ~ ', $params['time']); + $time[0] && $where["c_time >="] = strtotime($time[0] . ' 00:00:00'); + $time[1] && $where["c_time <="] = strtotime($time[1] . ' 23:59:59'); + } + $where2 = $where3 = $where; + $where2['trade_type'] = 1; + $sum2 = $this->mdUserAccountLog->sum('money_in', $where2); + $this->data['money_in'] = number_format_com($sum2['money_in']); + $where3['trade_type'] = 2; + $sum3 = $this->mdUserAccountLog->sum('money_out', $where3); + $this->data['money_out'] = number_format_com($sum3['money_out']); + $lists = array(); + $count = $this->mdUserAccountLog->count($where); + if ($count) { + $res = $this->mdUserAccountLog->select($where, 'id DESC', $params['page'], $params['size'], ''); + foreach ($res as $key => $value) { + $setValue = array(); + $setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']); + $setValue['sid'] = $value['sid'] ? $value['sid'] : '-'; + $setValue['trade_type_name'] = $trade_type_ary[$value['trade_type']]; + $setValue['money_in'] = number_format_com($value['money_in']); + $setValue['money_out'] = number_format_com($value['money_out']); + $setValue['money_left'] = number_format_com($value['money_left']); + $lists[] = $setValue; + } + } + $this->data['_title'] = $_title; + $this->data['lists'] = $lists; + $this->data['params'] = $params; + $this->data['trade_type_ary'] = $trade_type_ary; + $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); + return $this->show_view('appdistribution/team/get_accountlog', true); + } + + //设为分销/取消分销 + public function edit_team_dealer() + { + $id = $this->input->post('id'); + $dealer = $this->input->post('dealer'); + $this->mdAppUser->update(array('dealer' => $dealer, 'up_uid' => 0), array('id' => $id)); + return $this->show_json(SYS_CODE_SUCCESS, '修改成功!'); + } + + //展示单条数据 + public function get() + { + } + + //添加单条数据 + public function add() + { + } + + //编辑单条数据 + public function edit() + { + } + + //删除单条数据 + public function del() + { + } + + //批量操作(默认修改状态) + public function batch() + { + } + + //导出数据列表 + public function export() + { + } +} diff --git a/admin/views/app/liche/member/lists.php b/admin/views/app/liche/member/lists.php index f7946ea5..e22a63f1 100755 --- a/admin/views/app/liche/member/lists.php +++ b/admin/views/app/liche/member/lists.php @@ -37,7 +37,7 @@ - onchange="set_publish(this,)"/> + onchange="set_publish(this,)"/> @@ -66,7 +66,7 @@ function set_publish(obj,id){ }else{ value = 0; } - var data = {'id':id,'ifdist':value}; + var data = {'id':id,'dealer':value}; $.post('/app/liche/member/edit',data,function(result){ if(result.code){ layer.msg(result.msg, {time: 2000,icon:1 }, function () { diff --git a/admin/views/appdistribution/team/get_accountlog.php b/admin/views/appdistribution/team/get_accountlog.php new file mode 100755 index 00000000..f081e0b6 --- /dev/null +++ b/admin/views/appdistribution/team/get_accountlog.php @@ -0,0 +1,124 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
入账时间订单号账务类型收入金额支出金额当前余额
+
+
+
+
+
+ +
+
+
+ diff --git a/admin/views/appdistribution/team/get_commission.php b/admin/views/appdistribution/team/get_commission.php new file mode 100755 index 00000000..f9facf57 --- /dev/null +++ b/admin/views/appdistribution/team/get_commission.php @@ -0,0 +1,93 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
商品标题商品价格佣金订单来源状态创建时间
+
+
+
+
+
+ +
+
+
+ diff --git a/admin/views/appdistribution/team/get_team.php b/admin/views/appdistribution/team/get_team.php new file mode 100755 index 00000000..232926d0 --- /dev/null +++ b/admin/views/appdistribution/team/get_team.php @@ -0,0 +1,130 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
ID团员名称订单数成功数带来佣金手机操作
+ 佣金明细 + 资金流水 + + 设为分销 + +
+
+
+
+
+
+ +
+
+
+ diff --git a/admin/views/appdistribution/team/lists.php b/admin/views/appdistribution/team/lists.php new file mode 100755 index 00000000..62a2ed21 --- /dev/null +++ b/admin/views/appdistribution/team/lists.php @@ -0,0 +1,102 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID团长名称人数订单数成功数佣金手机操作
取消分销
+ 查看团队 + 佣金明细 + 资金流水 +
+
+
+
+
+
+ +
+
+
+ diff --git a/api/controllers/Hd.php b/api/controllers/Hd.php index 43f5d5f2..d67c2141 100755 --- a/api/controllers/Hd.php +++ b/api/controllers/Hd.php @@ -210,6 +210,63 @@ class Hd extends CI_Controller { return $this->print_return($this->return_error($e->getCode(), $e->getMessage())); } } + /** + * 分销入口 + */ + public function distribution(){ + define('WXAPP_ITEMS', 1); + //加载输入参数 + $this->input_param(); + $app_id = $this->input_param('app_id'); + !$app_id && $app_id = $this->input_param('vipcard_id'); + $version = $this->input_param('version'); + $sversion = $this->input_param('sversion'); + + $this->log_file = get_class($this) . "_{$app_id}.log"; + + //应用ID为空 + if(!$app_id){ + debug_log("[fail]". __FUNCTION__ . ":app_id is null; uri_string:" . $this->uri->uri_string(), $this->log_file); + return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '请求丢失')); + } + //签名不正确 + if(!$this->vaild_sign()){ + debug_log("[fail]". __FUNCTION__ . ":sign check fail; uri_string:" . $this->uri->uri_string() . "; param:".json_encode($this->inputs), $this->log_file); + return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '非法请求')); + } + $app = self::$apps[$app_id]; + $class_name = ucfirst($this->uri->segment(3)); + if($this->uri->segment(4)){ + $method = $this->request . "_" . $this->uri->segment(4); + } else { + $method = $this->request; + } + //app定制ct + $file_name = APPPATH."controllers/wxapp/distribution/{$app}/{$class_name}.php"; + //ct不存在 + if(file_exists($file_name)) { + require_once $file_name; + } else { + //app定制ct不存在,使用公共ct + $file_name = APPPATH."controllers/wxapp/distribution/{$class_name}.php"; + if(file_exists($file_name)) { + require_once $file_name; + } else{ + debug_log("[fail]". __FUNCTION__ . ": file '{$file_name}' not exist; method:{$method}, app_id:".$app_id, $this->log_file); + return $this->print_return($this->return_error(API_CODE_NONE, '非法请求')); + } + } + try{ + $class = new $class_name($this->inputs, $app); + $result = $class->$method($version, $sversion); + if(!$result) { + throw new Exception('', ERR_SYS_FAIL); + } + return $this->print_return($result); + } catch (Exception $e){ + return $this->print_return($this->return_error($e->getCode(), $e->getMessage())); + } + } /** * 测试签名(开发环境) diff --git a/api/controllers/wxapp/distribution/Cash.php b/api/controllers/wxapp/distribution/Cash.php new file mode 100755 index 00000000..1f010a08 --- /dev/null +++ b/api/controllers/wxapp/distribution/Cash.php @@ -0,0 +1,139 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + + $this->uid = $this->session['uid']; + $this->log_file = 'distribution_cash.log'; + $this->load->model('app/User_account_model', 'mdUserAccount'); + $this->load->model('app/User_accountlog_model', 'mdUserAccountLog'); + } + + /** + * Notes:提现列表 + * Created on: 2020/7/01 11:47 + * Created by: dengbw + * @return array + */ + protected function get() + { + $page = $this->input_param('page'); + $size = $this->input_param('size'); + $status = $this->input_param('status'); + !$page && $page = 1; + !$size && $size = 10; + $statusAry = array(1 => '已完成', -1 => '失败'); + $tab[] = array("value" => '', 'title' => '全部'); + foreach ($statusAry as $key => $value) { + $tab[] = array("value" => $key, 'title' => $value); + } + $lists = array(); + $reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1)); + $where['account_id'] = $reUa['id'] ? $reUa['id'] : 0; + $where['trade_type'] = 2; + if (status_verify($status)) { + $where['status'] = $status; + } + $total = $this->mdUserAccountLog->count($where); + if ($total) { + $resUa = $this->mdUserAccountLog->select($where, 'id DESC', $page, $size, 'money_out,status,c_time'); + foreach ($resUa as $key => $value) { + $setValue = array(); + $setValue['name'] = '提现'; + $setValue['status'] = $value['status']; + $setValue['status_name'] = $statusAry[$value['status']]; + $setValue['money_out'] = $value['money_out']; + $setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']); + $lists[] = $setValue; + } + } + if ($page == 1) { + $img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url']; + $bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color']; + $data['tab'] = $tab; + $money_total = $cash_money = $cash_money_out = 0.00; + if ($reUa) { + $money_total = $reUa['money_total']; + $cash_money = $reUa['money_left']; + $cash_money_out = $reUa['money_total'] - $reUa['money_left']; + } + $data['title'] = '提现'; + $data['bg'] = array('color' => $bg_color, 'img' => $img_url . '/distribute/list-theme.jpg'); + $data['money_total'] = array('title' => '总收入(元)', 'value' => $money_total); + $data['cash_money'] = array('title' => '可提现金额(元)', 'value' => number_format_com($cash_money, 2, '')); + $data['cash_money_out'] = array('title' => '已提现金额(元)', 'value' => number_format_com($cash_money_out, 2, '')); + } + $data['list'] = $lists; + $data['total'] = $total; + return $data; + } + + /** + * Notes:提现审请 + * Created on: 2020/7/2 9:47 + * Created by: dengbw + * @throws Hd_exception + */ + protected function put() + { + $reU = $this->app_user_model->get(array('id' => $this->uid)); + if ($reU['dealer'] != 1) { + throw new Hd_exception('不是分销用户,不可提现', API_CODE_FAIL); + } + $reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1)); + $cash_money = $reUa['money_left']; + if ($cash_money < 1) { + throw new Hd_exception('提现金额不能少于1元', API_CODE_INVILD_PARAM); + } + $sid = create_order_no(350200, 'cash'); + //企业付款到零钱 + $this->load->library('Transfers', array('app_id' => $this->app_id)); + $result = $this->transfers->sendMoney(array('partner_trade_no' => $sid, 'amount' => $cash_money + , 'openid' => $reU['openid'], 'desc' => '分销提现', 're_user_name' => $reU['nickname'])); + //echo json_encode($result, JSON_UNESCAPED_UNICODE); + debug_log("[info] " . __FUNCTION__ . "# result:" . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file); + if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {//提现成功 + $money_left = $reUa['money_left'] - $cash_money; + $addData = array("account_id" => $reUa['id'], "sid" => $sid, "money_out" => $cash_money, "money_left" => $money_left, + "status" => 1, "trade_type" => 2, "jsondata" => json_encode($result, JSON_UNESCAPED_UNICODE) + , 'c_time' => time()); + $re1 = $this->mdUserAccountLog->add($addData); + if (!$re1) { + debug_log("[error] " . __FUNCTION__ . ":err_sql:" . $this->mdUserAccountLog->db->last_query(), $this->log_file); + } + //$money_freeze = $reUa['money_freeze'] + $cash_money; + //$updateData = array('money_freeze' => $money_freeze, 'money_left' => $money_left); + $updateData = array('money_left' => $money_left); + $this->mdUserAccount->update($updateData, array('app_id' => $this->app_id, 'app_uid' => $this->uid)); + $res2 = $this->mdUserAccount->db->affected_rows(); + if ($res2) { + debug_log("[success] " . __FUNCTION__ . ":操作成功", $this->log_file); + } else { + debug_log("[error] " . __FUNCTION__ . ":err_sql:" . $this->mdUserAccount->db->last_query(), $this->log_file); + } + throw new Hd_exception('提现成功', API_CODE_SUCCESS); + } else { + throw new Hd_exception('提现失败,请联系客服', API_CODE_FAIL); + } + } +} diff --git a/api/controllers/wxapp/distribution/Commission.php b/api/controllers/wxapp/distribution/Commission.php new file mode 100755 index 00000000..506f9dd0 --- /dev/null +++ b/api/controllers/wxapp/distribution/Commission.php @@ -0,0 +1,36 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + $this->uid = $this->session['uid']; + } + + /** + * Notes:佣金明细 + * Created on: 2020/6/30 11:47 + * Created by: dengbw + * @return array + */ + protected function get(){ + } +} diff --git a/api/controllers/wxapp/distribution/Home.php b/api/controllers/wxapp/distribution/Home.php new file mode 100644 index 00000000..f409ada4 --- /dev/null +++ b/api/controllers/wxapp/distribution/Home.php @@ -0,0 +1,232 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + + $this->uid = $this->session['uid']; + $this->load->model('app/User_account_model', 'mdUserAccount'); + } + + /** + * Notes:分销首页 + * Created on: 2020/6/30 11:47 + * Created by: dengbw + * @return array + * @throws Exception + */ + protected function get() + { + $money_total = $money_left = $money_freeze = '0.00'; + $re = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1)); + if ($re) { + $money_total = $re['money_total']; + $money_left = $re['money_left']; + } + $img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url']; + $bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color']; + $reU = $this->app_user_model->get(array('id' => $this->uid)); + if ($reU['dealer'] != 1) { + throw new Hd_exception('不是分销用户', API_CODE_FAIL); + } + $shareTitle = $shareImg = $team_title = $team_url = $team_invite = ''; + if ($reU['up_uid'] == 0) { + $shareTitle = '邀请您一起参与' . $this->cf_title . '分销'; + $shareImg = $img_url . '/distribute/share-tip.jpg'; + $team_title = '我的团队'; + $team_url = '/pages/distribute/team/index?type=1'; + $team_invite = '邀请团员'; + } else { + if ($this->app_config('lock_fans') == 1) {//锁粉才有粉丝 + $team_title = '我的粉丝'; + $team_url = '/pages/distribute/fans/index'; + } + } + $team_title && $menulist[] = array('title' => $team_title, 'url' => $team_url, 'img' => $img_url . '/distribute/index-icon-1.png'); + $menulist[] = array('title' => '佣金明细', 'url' => '/pages/distribute/reward/index', 'img' => $img_url . '/distribute/index-icon-2.png'); + $menulist[] = array('title' => '立即提现', 'url' => '/pages/distribute/cashout/index', 'img' => $img_url . '/distribute/index-icon-3.png'); + $menulist[] = array('title' => '分销商品库', 'url' => '/pages/distribute/goods/index', 'img' => $img_url . '/distribute/index-icon-4.png'); + $data = array( + "title" => '分销', + "bg" => array('color' => $bg_color, 'img' => $img_url . '/distribute/index-banner.png'), + "income" => array('title' => '总收入', 'value' => $money_total), + "cashout" => array('title' => '可提现金额', 'value' => $money_left, 'url' => '/pages/distribute/cashout/index'), + "rule" => array('title' => '佣金规则', 'value' => $this->mdUserAccount->config()[$this->app_id]['deal']['rule']), + "btn" => array('title' => $team_invite, 'shareTitle' => $shareTitle, 'shareImg' => $shareImg), + "menulist" => $menulist + ); + return $data; + } + + /** + * Notes:帐户信息 + * Created on: 2020/7/3 17:11 + * Created by: dengbw + * @return array + */ + protected function get_info() + { + $dealer = $up_uid = 0; + $money_total = $money_left = $money_freeze = 0.00; + $team_nums = 0; + $reU = $this->app_user_model->get(array('id' => $this->uid)); + if ($reU['dealer'] == 1) { + $dealer = $reU['dealer']; + $up_uid = $reU['up_uid']; + $reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid) + , 'id,money_total,money_freeze,money_left'); + if ($reUa['id']) { + $money_total = $reUa['money_total']; + $money_freeze = $reUa['money_freeze']; + $money_left = $reUa['money_left']; + if ($up_uid == 0) { + $team_nums = $this->app_user_model->count(array('dealer' => 1, 'up_uid' => $up_uid)); + } + } else { + //添加资金账户 + $addData = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1, 'c_time' => time()); + $this->mdUserAccount->add($addData); + } + } + $data = array( + "dealer" => $dealer, + "up_uid" => $up_uid, + "team_nums" => $team_nums, + "money_total" => $money_total, + "money_freeze" => $money_freeze, + "money_left" => $money_left, + ); + return $data; + } + + /** + * Notes:收到团队邀请 + * Created on: 2020/7/2 15:27 + * Created by: dengbw + * @return array + * @throws Hd_exception + */ + protected function get_invite() + { + $up_uid = $this->input_param('up_uid'); + if (!$up_uid) { + throw new Hd_exception('请求超时', API_CODE_INVILD_PARAM); + } + if ($up_uid == $this->uid) { + return array("show" => 0); + } + $re = $this->app_user_model->get(array('id' => $this->uid), 'nickname,dealer,up_uid'); + if ($re['dealer'] == 1) { + return array("show" => 0); + } + $re_up = $this->app_user_model->get(array('id' => $up_uid), 'nickname,dealer,up_uid'); + if (!$re_up) { + throw new Hd_exception('无此分销用户', API_CODE_FAIL); + } + if ($re_up['dealer'] != 1) { + throw new Hd_exception('无邀请权限', API_CODE_FAIL); + } + + $invite_name = $re_up['nickname']; + if ($re_up['up_uid'] == 0) { //一级分销邀请的团员 + $title = '一起来赚钱吧~'; + } else {//团员邀请的粉丝 + $title = $re['up_uid'] ? '更换为' . $re_up['nickname'] . '的粉丝' : '加入' . $re_up['nickname'] . '的粉丝'; + } + $data = array( + "show" => 1, + 'title' => $title, + 'content' => $invite_name . '邀请您一起参与' . $this->cf_title . '分销' + ); + return $data; + } + + /** + * Notes:加入分销团队 + * Created on: 2020/6/30 9:25 + * Created by: dengbw + * @return array + * @throws Hd_exception + */ + protected function put_invite() + { + $up_uid = $this->input_param('up_uid'); + if (!$up_uid) { + throw new Hd_exception('请求超时', API_CODE_INVILD_PARAM); + } + if ($up_uid == $this->uid) { + throw new Hd_exception('不能自己邀请自己', API_CODE_FAIL); + } + $re = $this->app_user_model->get(array('id' => $this->uid), 'nickname,dealer'); + if ($re['dealer'] == 1) { + throw new Hd_exception('您已是分销人员', API_CODE_FAIL); + } + $re_up = $this->app_user_model->get(array('id' => $up_uid), 'nickname,dealer,up_uid'); + if (!$re_up) { + throw new Hd_exception('无此分销用户', API_CODE_INVILD_PARAM); + } + if ($re_up['dealer'] != 1) { + throw new Hd_exception('无邀请权限', API_CODE_FAIL); + } + $reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid), 'id'); + if (!$reUa['id']) {//添加资金账户 + $addData = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1, 'c_time' => time()); + $this->mdUserAccount->add($addData); + } + //更新上级uid + if ($re_up['dealer'] == 1 && $re_up['up_uid'] == 0) {//一级分销邀请的团员 + $upd = array('up_uid' => $up_uid, 'dealer' => 1); + if(in_array($up_uid, array(2))){ + //特殊用户的邀请,变成一级分销 + $upd['up_uid'] = 0; + } + $this->app_user_model->update($upd, array('id' => $this->uid)); + } else {//团员邀请的粉丝 + $this->app_user_model->update(array('up_uid' => $up_uid), array('id' => $this->uid)); + } + throw new Hd_exception('加入成功', API_CODE_SUCCESS); + } + + /** + * Notes:加入粉丝 + * Created on: 2020/7/7 15:18 + * Created by: dengbw + */ + protected function put_fans() + { + if (!$this->app_config('lock_fans')) { + throw new Hd_exception('未开启锁粉', API_CODE_SUCCESS); + } + $up_uid = $this->input_param('up_uid'); + $re = $this->app_user_model->get(array('id' => $this->uid), 'dealer,up_uid'); + if ($re['dealer'] == 1 || $re['up_uid']) { + throw new Hd_exception('已是粉丝', API_CODE_SUCCESS); + } + $re_up = $this->app_user_model->get(array('id' => $up_uid), 'dealer,up_uid'); + if (!$re_up || $re_up['dealer'] != 1) { + throw new Hd_exception('无邀请权限', API_CODE_SUCCESS); + } + $this->app_user_model->update(array('up_uid' => $up_uid), array('id' => $this->uid)); + throw new Hd_exception('加入成功', API_CODE_SUCCESS); + } + +} diff --git a/api/controllers/wxapp/distribution/Team.php b/api/controllers/wxapp/distribution/Team.php new file mode 100755 index 00000000..d719383a --- /dev/null +++ b/api/controllers/wxapp/distribution/Team.php @@ -0,0 +1,186 @@ +login_white = '';// + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->majia_white = array('get');//超级管理员披上马甲可操作权限 + + $this->uid = $this->session['uid']; + $this->load->model('app/User_account_model', 'mdUserAccount'); + $this->load->model('app/User_accountlog_model', 'mdUserAccountLog'); + $this->load->model('app/Deal_log_model', 'mdDealLog'); + } + + /** + * Notes:顶部信息 + * Created on: 2020/7/20 11:34 + * Created by: dengbw + * @return mixed + * @throws Hd_exception + */ + protected function get_top() + { + $reU = $this->app_user_model->get(array('id' => $this->uid), 'id,dealer,up_uid'); + if ($reU['dealer'] != 1) { + throw new Hd_exception('不是分销用户', API_CODE_FAIL); + } + if ($reU['dealer'] == 1 && $reU['up_uid'] == 0) {//一级分销 + $up_uid = $reU['id']; + } else {//团员 + $up_uid = $reU['up_uid']; + } + $img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url']; + $bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color']; + $total = $this->app_user_model->count(array('dealer' => 1, 'up_uid' => $up_uid)); + $data['title'] = '分销团队'; + $data['bg'] = array('color' => $bg_color, 'img' => $img_url . '/distribute/zc-bg.jpg'); + $where = array('app_id' => $this->app_id, 'app_uid' => $up_uid, 'status' => 1, 'type in(1,3)' => null); + $sum = $this->mdDealLog->sum('money', $where); + $data['team_money'] = array('title' => '团队佣金(元)', 'value' => number_format_com($sum['money'], 2, '')); + $data['team_nums'] = array('title' => '团队人数', 'value' => $total); + $menulist[] = array('title' => '我', 'value' => 0); + $menulist[] = array('title' => '团员', 'value' => 1); + if ($this->app_config('lock_fans') == 1) {//锁粉才有粉丝 + $menulist[] = array('title' => '粉丝', 'value' => 2); + } + $data['menulist'] = $menulist; + return $data; + } + + /** + * Notes:分销团队列表 + * Created on: 2020/7/20 11:33 + * Created by: dengbw + * @return mixed + * @throws Hd_exception + */ + protected function get() + { + $page = $this->input_param('page'); + $size = $this->input_param('size'); + $type = intval($this->input_param('type')); + !$page && $page = 1; + !$size && $size = 10; + $lists = $where = array(); + $up_uid = 0; + $reU = $this->app_user_model->get(array('id' => $this->uid)); + if ($reU['dealer'] != 1) { + throw new Hd_exception('不是分销用户', API_CODE_FAIL); + } + if ($type == 0) { + $myValue['nickname'] = $reU['nickname'] ? $reU['nickname'] : '我'; + $myValue['orders'] = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type in(0,2)' => null)); + $myValue['orders_suc'] = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type in(0,2)' => null, 'status' => 1)); + $mySum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type in(0,2)' => null, 'status' => 1)); + $myValue['bring_money'] = number_format_com($mySum['money'], 2, ''); + $lists[] = $myValue; + $data['field'] = array(array('title' => '姓名', 'value' => 'nickname'), array('title' => '订单数', 'value' => 'orders') + , array('title' => '成功数', 'value' => 'orders_suc'), array('title' => '带来佣金', 'value' => 'bring_money')); + $data['list'] = $lists; + $data['total'] = 1; + return $data; + } else if ($type == 1) {//团员 + if ($reU['dealer'] == 1 && $reU['up_uid'] == 0) {//一级分销 + $up_uid = $reU['id']; + } else {//团员 + $up_uid = $reU['up_uid']; + } + $where = array('dealer' => 1, 'up_uid' => $up_uid); + $data['field'] = array(array('title' => '姓名', 'value' => 'nickname'), array('title' => '订单数', 'value' => 'orders') + , array('title' => '成功数', 'value' => 'orders_suc'), array('title' => '带来佣金', 'value' => 'bring_money')); + } else if ($type == 2) {//粉丝 + $where = array('dealer' => 0, 'up_uid' => $this->uid); + $data['field'] = array(array('title' => '姓名', 'value' => 'nickname'), + array('title' => '订单数', 'value' => 'orders'), array('title' => '带来佣金', 'value' => 'bring_money')); + } + $resU = $this->app_user_model->select($where, 'id DESC', $page, $size, 'id,nickname'); + $total = $this->app_user_model->count($where); + if ($total) { + foreach ($resU as $key => $value) { + $setValue = array(); + $setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户'; + if ($type == 1) { + $where1 = array('app_id' => $this->app_id, 'app_uid' => $up_uid, 't_uid' => $value['id'], 'type in(1,3)' => null); + $where2 = array('app_id' => $this->app_id, 'app_uid' => $up_uid, 't_uid' => $value['id'], 'type in(1,3)' => null, 'status' => 1); + $orders = $this->mdDealLog->count($where1); + $orders_suc = $this->mdDealLog->count($where2); + $orders_suc > $orders && $orders = $orders_suc; + $setValue['orders'] = $orders; + $setValue['orders_suc'] = $orders_suc; + $sum = $this->mdDealLog->sum('money', $where2); + $setValue['bring_money'] = number_format_com($sum['money'], 2, ''); + } else if ($type == 2) { + $where = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 't_uid' => $value['id'], 'type' => 2, 'status' => 1); + $setValue['orders'] = $this->mdDealLog->count($where); + $sum = $this->mdDealLog->sum('money', $where); + $setValue['bring_money'] = number_format_com($sum['money'], 2, ''); + } + $lists[] = $setValue; + } + } + $data['list'] = $lists; + $data['total'] = $total; + return $data; + } + + protected function get_fans() + { + $page = $this->input_param('page'); + $size = $this->input_param('size'); + !$page && $page = 1; + !$size && $size = 10; + $lists = array(); + $reU = $this->app_user_model->get(array('id' => $this->uid), 'id,dealer,up_uid'); + if ($reU['dealer'] != 1) { + throw new Hd_exception('不是分销用户', API_CODE_FAIL); + } + $where = array('dealer' => 0, 'up_uid' => $this->uid); + $resU = $this->app_user_model->select($where, 'id DESC', $page, $size, 'id,nickname'); + $total = $this->app_user_model->count($where); + if ($total) { + foreach ($resU as $key => $value) { + $setValue = array(); + $setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户'; + $where = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 't_uid' => $value['id'], 'type' => 2, 'status' => 1); + $setValue['orders'] = $this->mdDealLog->count($where); + $sum = $this->mdDealLog->sum('money', $where); + $setValue['bring_money'] = number_format_com($sum['money'], 2, ''); + $lists[] = $setValue; + } + } + if ($page == 1) { + $img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url']; + $bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color']; + $data['title'] = '分销粉丝'; + $data['bg'] = array('color' => $bg_color, 'img' => $img_url . '/distribute/list-theme.jpg'); + $where = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type' => 2, 'status' => 1); + $sum = $this->mdDealLog->sum('money', $where); + $data['team_money'] = array('title' => '粉丝佣金(元)', 'value' => number_format_com($sum['money'], 2, '')); + $data['team_nums'] = array('title' => '粉丝人数', 'value' => $total); + $menulist[] = array('title' => '粉丝', 'value' => 1, 'field' => array(array('title' => '姓名', 'value' => 'nickname'), + array('title' => '订单数', 'value' => 'orders'), array('title' => '带来佣金', 'value' => 'bring_money'))); + $data['menulist'] = $menulist; + } + $data['list'] = $lists; + $data['total'] = $total; + return $data; + } +} diff --git a/api/controllers/wxapp/liche/User.php b/api/controllers/wxapp/liche/User.php index f9bdfa92..41ed451f 100644 --- a/api/controllers/wxapp/liche/User.php +++ b/api/controllers/wxapp/liche/User.php @@ -82,6 +82,10 @@ class User extends Wxapp{ $user = $this->app_user_model->get(array('id' => $uid)); $jsondata = json_decode($user['jsondata'],true); + $istop = 0; + if($this->session['dealer'] && $this->session['up_uid']==0){ + $istop = 1; + } $data = array( 'uid' => $uid, 'mobile' => $user['mobile'], @@ -91,6 +95,7 @@ class User extends Wxapp{ 'name' => $jsondata['alipay']['name'] ? $jsondata['alipay']['name'] : '', 'account' => $jsondata['alipay']['account'] ? $jsondata['alipay']['account'] : '', ], + 'istop' => $istop, ); return $data; @@ -336,7 +341,7 @@ class User extends Wxapp{ ['title'=>'我的爱车','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-1.png','url'=>'/pages/mine/myCar/index'], ['title'=>'联系小狸','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-3.png'], ]; - $this->session['ifdist'] && $about[] = ['title'=>'推广提现','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-4.png','url'=>'/pages/distribute/index']; + $this->session['dealer'] && $about[] = ['title'=>'推广提现','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-4.png','url'=>'/pages/distribute/index']; $data = [ 'progressOpt' => $progressOpt, 'progress' => $progress, diff --git a/common/libraries/entity/Deal_entity.php b/common/libraries/entity/Deal_entity.php new file mode 100755 index 00000000..8c518c6d --- /dev/null +++ b/common/libraries/entity/Deal_entity.php @@ -0,0 +1,308 @@ +ci = &get_instance(); + $this->init($params); + $class_name = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称 + $this->log_file = "libraris_{$class_name}.log"; + } + + public function init($params) + { + if ($params['app_id']) { + $this->app_id = $params['app_id']; + $this->load->model('app/App_model', 'mdApp'); + $this->app_config = $this->ci->mdApp->appConfig()[$this->app_id]; + } + } + + /** + * Notes:增加分销记录 + * Created on: 2020/7/8 15:21 + * Created by: dengbw + * @param $params + * @return bool + */ + public function deal_log($params) + { + if (!$params['sid']) { + return array('code' => 0, 'msg' => '参数错误'); + } + $this->load->model('order/order_purchase_model', 'mdOrderPurchase'); + $this->load->model($this->app_config['model'], 'mdUser'); + $this->load->model('app/Deal_log_model', 'mdDealLog'); + $this->load->model('apporder/order_exchange_model', 'mdOrderExchange'); + $order = $this->ci->mdOrderPurchase->get(array('sid' => $params['sid'], 'app_id' => $this->app_id)); + if (!$order) { + return array('code' => 0, 'msg' => '订单不存在'); + } + $item = $this->ci->mdItems->get(array('id' => $order['item_id'], 'app_id' => $this->app_id)); + if (!$item) { + return array('code' => 0, 'msg' => '商品不存在'); + } + if (!$item['is_deal']) { + return array('code' => 0, 'msg' => '不是分销商品'); + } + if ($item['type'] == 1) {//实物 + if ($order['status_detail'] != 25) { + return array('code' => 0, 'msg' => '不是待发货'); + } + } else if ($item['type'] == 2) {//虚似商品 + if ($order['status_detail'] != 21) { + return array('code' => 0, 'msg' => '不是待核销'); + } + } + if ($order['sku_id']) { + $reIs = $this->ci->mdItemStock->get(array('id' => $order['sku_id']), 'brokerage_1,brokerage_2'); + } else { + $reIs = $this->ci->mdItemStock->get(array('item_id' => $order['item_id'], 'sku_ids' => 0), 'brokerage_1,brokerage_2'); + } + $app = $this->ci->mdApp->get(array('id' => $this->app_id)); + $json = $app['jsondata'] ? json_decode($app['jsondata'], true) : array(); + $lock_fans = $json['lock_fans'] ? $json['lock_fans'] : 0; //1锁粉 + $app_uid = $order['app_uid']; + if ($lock_fans == 0) {//没锁粉操作 + if ($order['cf_uid']) { + $app_uid = $order['cf_uid']; + } else { + $order['cf_uid'] = $app_uid; + } + } + $reU = $this->ci->mdUser->get(array('id' => $app_uid), 'dealer,up_uid'); + if (!$reU) { + //debug_log("[error] " . __FUNCTION__ . ":{$order['app_uid']}_用户不存在", $this->log_file); + return array('code' => 0, 'msg' => '用户不存在'); + } + if ($lock_fans == 0 && $reU['dealer'] == 0) {//没锁粉操作 + return array('code' => 0, 'msg' => '不是分销用户'); + } + $res = array(); + $brokerage_1 = $reIs['brokerage_1']; + $brokerage_2 = $reIs['brokerage_2']; + $brokerage = $reIs['brokerage_1'] + $reIs['brokerage_2']; //直销 + if ($item['type'] == 2 && $item['code_num'] == 1) {//虚似商品且一个核销码 + $where = array('status' => 0, 'app_id' => $this->app_id, 'sid' => $params['sid'], 'order_type' => 'purchase'); + $res = $this->ci->mdOrderExchange->select($where, 'id DESC', 0, 0, 'id');///未核销 + } else { + //商品多个核销码数量或实物商品,只算订算数 + for ($x = 0; $x < $order['item_num']; $x++) { + $res[] = array("id" => 0); + } + } + //type 0自己购买 1团员购买 2粉丝购买 3团员粉丝购买 + if ($res) { + foreach ($res as $key => $value) { + if ($lock_fans == 1) {//1锁粉 + if ($reU['dealer'] == 1) { + if ($reU['up_uid'] == 0) {//团长自己购买直销 + $this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage, $value['id'], $order['sid'], $order['app_id'])); + } else {//团员自己购买 + $this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage_1, $value['id'], $order['sid'], $order['app_id'])); + } + if ($reU['up_uid']) {//团员购买团长2级 + $reU3 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'dealer');//团长 + if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//判断是否团长 + $this->set_deal_log(array(1, $reU['up_uid'], $order['app_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id'])); + } + } + } else if ($reU['dealer'] == 0 && $reU['up_uid']) { + //粉丝购买直销 + $this->set_deal_log(array(2, $reU['up_uid'], $order['app_uid'], $brokerage, $value['id'], $order['sid'], $order['app_id'])); + $reU2 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'up_uid');//团员 + $reU3 = $this->ci->mdUser->get(array('id' => $reU2['up_uid']), 'dealer');//团长 + if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//团员粉丝购买团长2级 + $this->set_deal_log(array(3, $reU2['up_uid'], $reU['up_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id'])); + } + } + } else if ($lock_fans == 0) { + if ($order['cf_uid'] == $order['app_uid']) {//自己购买 + if ($reU['up_uid'] == 0) {//团长自己购买直销 + $this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage, $value['id'], $order['sid'], $order['app_id'])); + } else {//团员自己购买1级 + $this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage_1, $value['id'], $order['sid'], $order['app_id'])); + } + if ($reU['up_uid']) {//团员购买团长2级 + $reU3 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'dealer'); + if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//判断是否团长 + $this->set_deal_log(array(1, $reU['up_uid'], $order['app_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id'])); + } + } + } else { + if ($reU['up_uid'] == 0) {//团长自己分享出去直销 + $this->set_deal_log(array(2, $order['cf_uid'], $order['app_uid'], $brokerage, $value['id'], $order['sid'], $order['app_id'])); + } else {//团员分享出去 + //团员1级 + $this->set_deal_log(array(2, $order['cf_uid'], $order['app_uid'], $brokerage_1, $value['id'], $order['sid'], $order['app_id'])); + //团长2级 + $reU3 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'dealer'); + if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//判断是否团长 + $this->set_deal_log(array(3, $reU['up_uid'], $order['cf_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id'])); + } + } + } + } + } + } + if ($this->data) { + $res2 = $this->ci->mdDealLog->add_batch($this->data); + if (!$res2) { + debug_log("[error] " . __FUNCTION__ . ":err_sql:" . $this->ci->mdDealLog->db->last_query(), $this->log_file); + } + } + } + + private function set_deal_log($params) + { + if ($params[3]) { + $this->data[] = array('type' => $params[0], 'app_uid' => $params[1], 't_uid' => $params[2], 'money' => $params[3] + , 'ex_id' => $params[4], 'cf_sid' => $params[5], 'app_id' => $params[6], 'status' => 0, 'c_time' => time()); + } + } + + /** + * Notes:核销成功/确认收货后加佣金 + * Created on: 2020/7/9 16:30 + * Created by: dengbw + * @param $params + * @return bool + */ + public function deal_log_code($params) + { + if (!$params['sid']) { + return array('code' => 0, 'msg' => '参数错误'); + } + $this->load->model('appitem/items_model', 'mdItems'); + $this->load->model('order/order_purchase_model', 'mdOrderPurchase'); + $order = $this->ci->mdOrderPurchase->get(array('sid' => $params['sid'], 'app_id' => $this->app_id)); + $item = $this->ci->mdItems->get(array('id' => $order['item_id'], 'app_id' => $this->app_id)); + if (!$order) { + return array('code' => 0, 'msg' => '订单不存在'); + } + if (!$item) { + return array('code' => 0, 'msg' => '商品不存在'); + } + if (!$item['is_deal']) { + return array('code' => 0, 'msg' => '不是分销商品'); + } + $where = array("app_id" => $this->app_id, "cf_sid" => $params['sid'], "status" => 0); + if ($item['type'] == 1) {//实物 + if ($order['status_detail'] != 27) { + return array('code' => 0, 'msg' => '未收货'); + } + } else if ($item['type'] == 2) {//虚似商品 + if ($item['code_num'] == 1 && $params['ex_id']) { + $this->load->model('apporder/order_exchange_model', 'mdOrderExchange'); + $re_exchange = $this->ci->mdOrderExchange->get(array('id' => $params['ex_id'])); + if ($re_exchange['status'] != 1) { + return array('code' => 0, 'msg' => '未核销'); + } + $where['ex_id'] = $params['ex_id']; //虚似商品且一个核销码,根据核销码加佣金 + } + } + $this->load->model('app/User_account_model', 'mdUserAccount'); + $this->load->model('app/User_accountlog_model', 'mdUserAccountLog'); + $this->load->model('app/Deal_log_model', 'mdDealLog'); + $res = $this->ci->mdDealLog->select($where, 'id DESC', 0, 0, 'id,app_uid,money'); + if ($res) { + foreach ($res as $key => $value) { + $reUa = $this->ci->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $value['app_uid'])); + if ($reUa['id']) { + $aid = $reUa['id']; + $money_total = $reUa['money_total'] + $value['money']; + $money_left = $reUa['money_left'] + $value['money']; + } else { + $money_total = $value['money']; + $money_left = $value['money']; + $addData = array('app_id' => $this->app_id, 'app_uid' => $value['app_uid'], 'status' => 1, 'c_time' => time()); + $aid = $this->ci->mdUserAccount->add($addData); + } + if ($aid) { + $this->ci->mdUserAccountLog->db->trans_begin(); + $this->ci->mdUserAccount->db->trans_begin(); + $this->ci->mdDealLog->db->trans_begin(); + //增加资金流水表 + $this->ci->mdUserAccountLog->add(array('account_id' => $aid, 'trade_type' => 1, 'money_in' => $value['money'] + , 'money_left' => $money_left, 'status' => 1, 'c_time' => time())); + //更新账户表 + $this->ci->mdUserAccount->update(array('money_total' => $money_total, 'money_left' => $money_left), array('id' => $aid)); + //更新分销记录表 + $this->ci->mdDealLog->update(array('status' => 1), array('id' => $value['id'])); + if ($this->ci->mdUserAccountLog->db->trans_status() && $this->ci->mdUserAccount->db->trans_status() + && $this->ci->mdDealLog->db->trans_status()) { + $this->ci->mdUserAccountLog->db->trans_commit(); + $this->ci->mdUserAccount->db->trans_commit(); + $this->ci->mdDealLog->db->trans_commit(); + debug_log("[success] " . __FUNCTION__ . ":操作成功,account_id={$aid}", $this->log_file); + } else { + $this->ci->mdUserAccountLog->db->trans_rollback(); + $this->ci->mdUserAccount->db->trans_rollback(); + $this->ci->mdDealLog->db->trans_rollback(); + debug_log("[finish] " . __FUNCTION__ . ":执行失败回滚,account_id={$aid}", $this->log_file); + } + } + } + } + } + + /** + * Notes:更新分销记录状态 -1无效 + * Created on: 2020/7/13 15:37 + * Created by: dengbw + * @param $params + * @return array + */ + public function deal_log_status($params) + { + $this->load->model('appdistribution/Deal_log_model', 'mdDealLog'); + $this->load->model('appitem/items_model', 'mdItems'); + $this->load->model('order/order_purchase_model', 'mdOrderPurchase'); + if (!$params['id']) { + return array('code' => 0, 'msg' => '参数错误'); + } + $order = $this->ci->mdOrderPurchase->get(array('id' => $params['id'])); + if (!$order) { + return array('code' => 0, 'msg' => '订单不存在'); + } + $item = $this->ci->mdItems->get(array('id' => $order['item_id'], 'app_id' => $this->app_id)); + if (!$item) { + return array('code' => 0, 'msg' => '商品不存在'); + } + if (!$item['is_deal']) { + return array('code' => 0, 'msg' => '不是分销商品'); + } + if (($order['status'] == 3 && $order['status_detail'] == 33) //申请退款 已退款 + || ($order['status'] == 2 && $order['status_detail'] == 23) //支付后环节 核销码过期未退款 + || ($order['status'] == 2 && $order['status_detail'] == 24) //支付后环节 核销码过期已退款 + ) { + //更新分销状态失效 + $this->ci->mdDealLog->update(array('status' => -1), array('app_id' => $order['app_id'], 'cf_sid' => $order['sid'])); + debug_log("[success] " . __FUNCTION__ . ":操作成功,sid={$order['sid']}", $this->log_file); + } else { + debug_log("[error] " . __FUNCTION__ . ":{$order['sid']}_更新分销记录状态失败", $this->log_file); + } + } + + public function __get($name) + { + if ('_model' === substr($name, -6)) { + return $this->ci->$name; + } elseif ('load' == $name) { + return $this->ci->load; + } + return null; + } +} diff --git a/common/models/app/App_model.php b/common/models/app/App_model.php index f0c3bebd..90a64cac 100644 --- a/common/models/app/App_model.php +++ b/common/models/app/App_model.php @@ -16,4 +16,31 @@ class App_model extends HD_Model parent::__construct($this->table_name, 'default'); } + /** + * Notes:app配置 + * Created on: 2019/12/27 14:52 + * Created by: dengbw + * @param $app_id + * @return array + */ + public function appConfig($app_id = null) + { + $map_config = array( + '1' => array( + 'app_key' => 'liche', + 'table' => 'hd_app_liche_users', + 'model' => 'app/liche/app_liche_users_model', + 'wx' => array( + 'appid' => 'wx98e64c11aac45966', + 'secret' => 'f8eec7be1c87a1c8e40213e144821ec3', + ), + ), + ); + + if(is_null($app_id)){ + return $map_config; + } + + return $map_config[$app_id]; + } } diff --git a/common/models/app/Deal_log_model.php b/common/models/app/Deal_log_model.php new file mode 100755 index 00000000..b86c0ffe --- /dev/null +++ b/common/models/app/Deal_log_model.php @@ -0,0 +1,17 @@ +table_name, 'default'); + } +} diff --git a/common/models/app/User_account_model.php b/common/models/app/User_account_model.php index b29abd0a..bc635b70 100644 --- a/common/models/app/User_account_model.php +++ b/common/models/app/User_account_model.php @@ -10,4 +10,19 @@ class User_account_model extends HD_Model parent::__construct($this->table_name, 'default'); } + /** + * Notes:配置 + * Created on: 2019/12/27 14:52 + * Created by: dengbw + * @return array + */ + public function config() + { + return array( + 1 => array( + 'deal' => array('img_url' => 'https://qs.haodian.cn/wechat_app/liche', 'bg_color' => '#fb3939'), + 'rule' => '' + ) + ); + } } diff --git a/sql/app/app.sql b/sql/app/app.sql index e036ef91..f048ab5d 100644 --- a/sql/app/app.sql +++ b/sql/app/app.sql @@ -97,3 +97,25 @@ create table lc_app_user_accountlog ( u_time timestamp not null default current_timestamp on update current_timestamp, primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='账户资金流水表'; + +-- ---------------------------- +-- Title:分销-记录表 +-- Author:lcc +-- Table:lc_app_deal_log +-- --------------------------- +drop table if exists lc_app_deal_log; +create table lc_app_deal_log ( + id int(10) unsigned not null auto_increment comment '自增id', + app_id int(10) unsigned not null comment '小程序id', + app_uid int(10) unsigned not null comment '小程序用户id', + cf_sid varchar(32) not null comment '来源订单号', + type tinyint(1) not null default '0' comment '类型(0自己购买1团员购买2粉丝购买3团员粉丝购买)', + t_uid int(10) unsigned not null default '0' comment '根据type加id', + ex_id int(10) unsigned not null default '0' comment '核销码id', + money decimal(12,2) not null default '0.00' comment '佣金', + remark varchar(256) not null default '' comment '备注', + status tinyint(1) not null default '0' comment '状态(-1无效 0待确认 1已入账)', + c_time int(11) not null default '0' comment '创建时间', + u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间', + primary key (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='分销-记录表' diff --git a/sql/app/liche.sql b/sql/app/liche.sql index 3ef6b2d5..9373701a 100644 --- a/sql/app/liche.sql +++ b/sql/app/liche.sql @@ -18,7 +18,8 @@ create table lc_app_liche_users ( u_time timestamp not null default current_timestamp on update current_timestamp, primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='狸车小程序用户表'; -alter table lc_app_liche_users add ifdist tinyint(1) unsigned not null default 0 comment '是否分销人员' after jsondata; +alter table lc_app_liche_users add dealer tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否分销' after jsondata; +alter table lc_app_liche_users add up_uid int(10) NOT NULL DEFAULT '0' COMMENT '上级uid' after dealer; -- ----------------------------