|
@@ -26,6 +26,7 @@ use app\models\user\UserExtract;
|
|
|
use app\models\user\UserNotice;
|
|
|
use crmeb\services\GroupDataService;
|
|
|
use crmeb\services\UtilService;
|
|
|
+use think\facade\Db;
|
|
|
|
|
|
/**
|
|
|
* 用户类
|
|
@@ -614,119 +615,18 @@ class UserController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 申请
|
|
|
- * @param Request $request
|
|
|
- * @return mixed
|
|
|
- * @throws DataNotFoundException
|
|
|
- * @throws DbException
|
|
|
- * @throws ModelNotFoundException
|
|
|
- */
|
|
|
- public function apply(Request $request)
|
|
|
- {
|
|
|
- $data = UtilService::postMore([
|
|
|
- ['type'],
|
|
|
- ['address'],
|
|
|
- ]);
|
|
|
- if (!$data['type']) return app('json')->fail('传入type');
|
|
|
- if ($data['type'] == 2){
|
|
|
- $user = User::where('proxy_area', 'like', '%'.$data['address'].'%')->find();
|
|
|
- if ($user) return app('json')->fail('该地址已被申请');
|
|
|
- if (!$data['address']) return app('json')->fail('填写申请地址');
|
|
|
- }
|
|
|
- $user = User::where('uid', $request->uid())->find();
|
|
|
- if ($user['identity'] == 2) return app('json')->fail('已是区域代理');
|
|
|
- if ($user['identity'] == 1 and $data['type'] == 1) return app('json')->fail('已是vip代理');
|
|
|
- $res = UserApply::create([
|
|
|
- 'uid' => $request->uid(),
|
|
|
- 'type' => $data['type'],
|
|
|
- 'address' => $data['address'],
|
|
|
- ]);
|
|
|
- if ($res) return app('json')->success('提交申请成功');
|
|
|
- return app('json')->success('提交申请失败');
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public function apply_list(Request $request)
|
|
|
- {
|
|
|
- $data = UtilService::getMore([
|
|
|
- ['page', 1],
|
|
|
- ['limit', 10],
|
|
|
- ]);
|
|
|
-
|
|
|
- $list = UserApply::where('uid', $request->uid())->page($data['page'], $data['limit'])->select();
|
|
|
-
|
|
|
- $list = count($list) > 0 ? $list->toArray() : [];
|
|
|
-
|
|
|
- return app('json')->success($list);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 每月提成
|
|
|
+ * 定时分红
|
|
|
* @return void
|
|
|
- * @throws DataNotFoundException
|
|
|
- * @throws DbException
|
|
|
- * @throws ModelNotFoundException
|
|
|
*/
|
|
|
public function bonus()
|
|
|
{
|
|
|
- $user = User::where('identity', 2)->where('spread_count', '>=', 1)->select();
|
|
|
- if (count($user) > 0)
|
|
|
- {
|
|
|
- foreach ($user as $item){
|
|
|
- if ($item['spread_count'] >= 1 and $item['spread_count'] < 2){
|
|
|
- $uids = get_downline(User::select()->toArray(), $item['uid']);
|
|
|
- $monthFirstDay = strtotime(date('Y-m-01',time()));
|
|
|
- $monthLasttDay = strtotime(date('Y-m-t',time()));
|
|
|
- $order_price = StoreOrder::where('uid', 'in', $uids)->where('paid', 1)->whereBetweenTime('add_time', $monthFirstDay, $monthLasttDay)->where('status', '>=', 0)->sum('pay_price');
|
|
|
- if ($order_price > 0)
|
|
|
- {
|
|
|
- $price = $order_price * 0.03;
|
|
|
- User::where('uid', $item['uid'])->inc('brokerage_price', $price)->update();
|
|
|
- UserBill::income('佣金', $item['uid'], 'now_money', 'brokerage', $price, $item['uid'], $item['brokerage_price']+$price, '区域代理每月提成');
|
|
|
- }
|
|
|
- }elseif ($item['spread_count'] >= 2){
|
|
|
- $uids = get_downline(User::select()->toArray(), $item['uid']);
|
|
|
- $monthFirstDay = strtotime(date('Y-m-01',time()));
|
|
|
- $monthLasttDay = strtotime(date('Y-m-t',time()));
|
|
|
- $order_price = StoreOrder::where('uid', 'in', $uids)->where('paid', 1)->whereBetweenTime('add_time', $monthFirstDay, $monthLasttDay)->where('status', '>=', 0)->sum('pay_price');
|
|
|
- if ($order_price > 0)
|
|
|
- {
|
|
|
- $price = $order_price * 0.05;
|
|
|
- User::where('uid', $item['uid'])->inc('brokerage_price', $price)->update();
|
|
|
- UserBill::income('佣金', $item['uid'], 'now_money', 'brokerage', $price, $item['uid'], $item['brokerage_price']+$price, '区域代理每月提成');
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ try {
|
|
|
+ Db::startTrans();
|
|
|
+ User::bonus();
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 代理过期
|
|
|
- * @return void
|
|
|
- * @throws DataNotFoundException
|
|
|
- * @throws DbException
|
|
|
- * @throws ModelNotFoundException
|
|
|
- */
|
|
|
- public function overdue()
|
|
|
- {
|
|
|
- $user = User::where('identity', 2)->select();
|
|
|
- foreach ($user as $item)
|
|
|
- {
|
|
|
- $time = $item['proxy_time'] + (86400 * 30);
|
|
|
- if ($time < time()) {
|
|
|
- $uids = get_downline(User::select()->toArray(), $item['uid']);
|
|
|
- $order_count = StoreOrder::where('uid', 'in', $uids)->where('paid', 1)->whereBetweenTime('add_time', $item['proxy_time'], time())->where('status', '>=', 0)->count();
|
|
|
- if ($order_count >= 5)
|
|
|
- {
|
|
|
- User::where('uid', $item['uid'])->update(['proxy_time' => time()]);
|
|
|
- }else{
|
|
|
- User::where('uid', $item['uid'])->update(['identity' => 1]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|