123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <?php
- /**
- * @author: xaboy<365615158@qq.com>
- * @day: 2017/11/11
- */
- namespace app\models\many;
- use app\admin\model\system\SystemConfig;
- use app\models\user\User;
- use app\models\user\UserBill;
- use crmeb\services\PHPExcelService;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- /**
- * Class StoreCategory
- * @package app\admin\model\store
- */
- class ManyOrder extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'many_order';
- use ModelTrait;
- protected $autoWriteTimestamp = true;
- public static function list($where)
- {
- $model = self::alias('a')
- ->order('a.id DESC')
- ->field('a.*,b.name,u.nickname')
- ->leftJoin('many b', 'b.id = a.many_id')
- ->leftJoin('user u', 'u.uid = a.uid')
- ->where('a.uid', $where['uid']);
- // if ($where['status'] == 0 or $where['status']) $model->where('a.status', '=', $where['status']);
- $data['count'] = $model->count();
- if ($where['page'] && $where['limit']) {
- $model->page($where['page'], $where['limit']);
- } else {
- $model->page(20, 1);
- }
- $list = $model->select()->toArray();
- $data['data'] = $list;
- return $data;
- }
- /**
- * 众筹成功订单返还
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function suc_return()
- {
- $order = self::where('is_return', 1)->where('status', 0)->select(); // 查询需要返还的订单
- if ($order) {
- foreach ($order as $item) {
- $many = Many::where('id', $item['many_id'])->find();
- $user = User::where('uid', $item['uid'])->find();//用户
- $user1 = [];
- $user2 = [];
- if ($user['spread_uid'] > 0) {
- $user1 = User::where('uid', $user['spread_uid'])->find();//用户
- if ($user1['spread_uid'] > 0) $user2 = User::where('uid', $user1['spread_uid'])->find();//用户
- }
- $purple_integral = round($item['price'] * 0.07, 2);// 奖励紫积分积分
- $frozen = $item['frozen'];
- $business_integral = round($item['price'] * 0.03, 2);// 奖励商家积分
- $user['white_integral'] += ($purple_integral + $frozen);
- $user['integral'] += $business_integral;
- if ($user1) {
- // 直推收益的百分之十
- $sy1 = $item['price'] * 0.015;
- $user1['white_integral'] += round($sy1 * 0.7, 2);
- $user1['integral'] += round($sy1 * 0.3, 2);
- }
- if ($user2) {
- // 间推收益的百分之五
- $sy2 = $item['price'] * 0.01;
- $user2['white_integral'] += round($sy2 * 0.7, 2);
- $user2['integral'] += round($sy2 * 0.3, 2);
- }
- self::where('id', $item['id'])->update(['status' => 1, 'return_time' => time()]);
- $user->save();
- UserBill::income('种树成功补贴肥料', $user['uid'], 'white_integral', 'zccg_white_integral', $purple_integral, $user['spread_uid'], $user['white_integral'], '种树成功补贴' . $many['name'] . '-第' . $item['stage'] . '期肥料');
- UserBill::income('种树成功解冻', $user['uid'], 'white_integral', 'fr_white_integral', $frozen, $user['spread_uid'], $user['white_integral'], '种树成功解冻' . $many['name'] . '-第' . $item['stage'] . '期'.$frozen.'肥料');
- UserBill::income('种树成功补贴阳光', $user['uid'], 'integral', 'zccg_integral', $business_integral, $user['spread_uid'], $user['integral'], '种树成功补贴' . $many['name'] . '-第' . $item['stage'] . '期阳光');
- ManyOrder::push($item['uid'], $item);
- if ($user1) {
- UserBill::income('直推奖励肥料', $user1['uid'], 'white_integral', 'zt_white_integral', $sy1 * 0.7, $user1['spread_uid'], $user1['white_integral'], '直推奖励肥料');
- UserBill::income('直推奖励阳光', $user1['uid'], 'integral', 'zt_integral', $sy1 * 0.3, $user1['spread_uid'], $user1['integral'], '直推奖励阳光');
- $user1->save();
- }
- if ($user2) {
- UserBill::income('间推奖励肥料', $user2['uid'], 'white_integral', 'jt_white_integral', $sy2 * 0.7, $user2['spread_uid'], $user2['white_integral'], '间推奖励肥料');
- UserBill::income('间推奖励阳光', $user2['uid'], 'integral', 'jt_integral', $sy2 * 0.3, $user2['spread_uid'], $user2['integral'], '间推奖励阳光');
- $user2->save();
- }
- }
- }
- }
- /**
- * 团队奖励
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function push($uid, $order)
- {
- $user = User::select();
- $find = User::where('uid', $uid)->find();
- $many = Many::where('id', $order['many_id'])->find();
- $price = $order['price'];
- if ($find['spread_uid'] > 0 and $price > 0){
- $spread = getParent($find['spread_uid'], $user->toArray());// 找到所有上级
- $v1 = 0;
- $v2 = 0;
- $v3 = 0;
- $one = SystemConfig::getConfigValue('v1')/100; // v1比例
- $tow = SystemConfig::getConfigValue('v2')/100;// v2比例
- $three = SystemConfig::getConfigValue('v3')/100;// v3比例
- foreach ($spread as $value) {
- $details = User::where('uid', $value)->find();
- if ($details['level'] == 1){
- if ($v2 == 0 and $v3 == 0){
- // 没有发放v2和v3的奖励
- if ($v1 == 0) { // 没有发放v1的奖励
- $jl = $price * $one;
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v1++;
- }elseif ($v1 == 1){// 发放v1奖励1次
- $jl = ($price*$one)*0.05;//平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v1++;
- }
- }
- }elseif ($details['level'] == 2){
- if ($v3 == 0){
- // 没有发放v3的奖励
- if ($v1 == 0 and $v2 == 0) { // 没有发放v1和v2的奖励的奖励
- $jl = $price * $tow; // 拿到流水的百分之八
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v2++;
- }elseif($v1 == 0 and $v2 == 1) { // 没有发放v1和v2的奖励的奖励
- $jl = ($price * $tow)*0.05; // 拿到流水的百分之八
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v2++;
- }elseif ($v1 > 0 and $v2 == 0){// 发放v1奖励,没有发放v2的奖励
- $jl = $price * ($tow - $one); // 拿到流水减掉v1的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v2++;
- }elseif ($v1 > 0 and $v2 == 1){// 发放v1奖励,发放v2的奖励一次
- $jl = ($price * ($tow - $one))*0.05; // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v2++;
- }
- }
- }elseif ($details['level'] == 3){
- if ($v1 == 0 and $v2 == 0 and $v3 == 0) { // 没有发放v1和v2v3的奖励的奖励
- $jl = $price * $three; // 拿到流水的百分之11
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 == 0 and $v2 == 0 and $v3 == 1) {// 没有发放v1和v2的奖励的奖励
- $jl = ($price * $three) * 0.05; // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 > 0 and $v2 == 0 and $v3 == 0){// 发放v1奖励,没有发放v2v3的奖励
- $jl = $price * ($three - $one); // 拿到流水减掉v1的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 > 0 and $v2 == 0 and $v3 == 1){// 发放v1奖励,没有发放v2v3的奖励
- $jl = ($price * ($three - $one)) * 0.05; // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 == 0 and $v2 > 0 and $v3 == 0){// 发放v1奖励,发放v2的奖励,没有发放v3的奖励
- $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 == 0 and $v2 > 0 and $v3 == 1){// 发放v1奖励,发放v2的奖励,发放v3的奖励
- $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 > 0 and $v2 > 0 and $v3 == 0){// 发放v1奖励,发放v2的奖励,发放v3的奖励
- $jl = ($price * ($three - $tow)); // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }elseif ($v1 > 0 and $v2 > 0 and $v3 == 1){// 发放v1奖励,发放v2的奖励,发放v3的奖励
- $jl = ($price * ($three - $tow)) * 0.05; // 拿到平级的百分之五
- $details['white_integral'] += $jl * 0.7; // 百分之70的紫积分
- $details['integral'] += $jl * 0.3; // 百分之30的商家积分
- $v3++;
- }
- }else{
- $jl = 0;
- }
- if ($jl > 0){
- $details->save();
- UserBill::income('团队奖励肥料', $details['uid'], 'white_integral', 'td_white_integral', $jl * 0.7, 0,$details['white_integral'], '种树成功补贴'.$many['name'].'-第'.$order['stage'].'期团队v'.$details['level'].'奖励肥料');
- UserBill::income('团队奖励阳光', $details['uid'], 'integral', 'td_integral', $jl * 0.3, 0,$details['integral'], '种树成功补贴'.$many['name'].'-第'.$order['stage'].'期期团队v'.$details['level'].'奖励阳光');
- }
- $jl = 0;
- }
- }
- }
- /**
- * 流水分红
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function flowing_water()
- {
- if (!Push::where('add_time', strtotime('today'))->find()) {
- $user = User::where('flowing_water', '>', 0)->select();
- if ($user) {
- foreach ($user as $item) {
- $price = ManyOrder::whereBetweenTime('return_time', strtotime('yesterday'), strtotime('today'))->sum('price');// 昨天众筹成功返还的流水
- if ($price > 0) {
- $details = User::where('uid', $item['uid'])->find();
- $details['white_integral'] += ($price * ($details['flowing_water'] / 100)) * 0.7; // 百分之70的紫积分
- $details['integral'] += ($price * ($details['flowing_water'] / 100)) * 0.3; // 百分之30的商家积分
- $details->save();
- UserBill::income('分红流水奖励肥料', $details['uid'], 'white_integral', 'team_white_integral', ($price * ($details['flowing_water'] / 100)) * 0.7, 0, $details['purple_integral'], '分红流水奖励肥料');
- UserBill::income('分红流水奖励阳光', $details['uid'], 'integral', 'team_integral', ($price * ($details['flowing_water'] / 100)) * 0.3, 0, $details['integral'], '分红流水奖励阳光');
- }
- }
- }
- }
- }
- /**
- * 更新推送时间
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function time()
- {
- if (!Push::where('add_time', strtotime('today'))->find()) {
- Push::create(['add_time' => strtotime('today')]); //存入数据库信息
- }
- }
- /**
- * 种树成功返还70%肥料
- * @param $many
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function order_return($many)
- {
- $order = self::where([['many_id', '=', $many['id']], ['stage', '=', $many['stage']], ['frozen', '<=', 0]])->select();
- if ($order)
- {
- foreach ($order as &$item)
- {
- $price = round($item['price'] * 0.7, 2);// 返还金额
- $item['frozen'] = round($item['price'] * 0.3, 2);// 冻结金额
- $user = User::where('uid', $item['uid'])->find();
- $user['white_integral'] += $price;
- $user->save();
- UserBill::income('返还肥料', $user['uid'], 'white_integral', 'fh_white_integral', $price, 0, $user['white_integral'], '种树成功返回' . $many['name'] . '-第' . $item['stage'] .'期70%肥料');
- self::where('id', $item['id'])->update(['frozen' => $item['frozen']]);
- }
- }
- }
- }
|