* @day: 2017/11/11 */ namespace app\models\many; 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) { if (strtotime($item['create_time'])+(86400*7) < time()){ $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'] * 1.07, 2);// 奖励紫积分积分 $business_integral = round($item['price'] * 0.03, 2);// 奖励商家积分 $user['purple_integral'] += $purple_integral; $user['business_integral'] += $business_integral; if ($user1){ // 直推收益的百分之十 $sy1 = $item['price'] * 0.1; $user1['purple_integral'] += $sy1 * 0.7; $user1['business_integral'] += $sy1 * 0.3; } if ($user2){ // 间推收益的百分之五 $sy2 = $item['price'] * 0.05; $user2['purple_integral'] += $sy2 * 0.7; $user2['business_integral'] += $sy2 * 0.3; } self::where('id', $item['id'])->update(['status' => 1]); $user->save(); UserBill::income('众筹成功奖励紫积分', $user['uid'], 'purple_integral', 'zccg', $purple_integral, $user['spread_uid'], $user['purple_integral'], '众筹成功返还紫积分'); UserBill::income('众筹成功奖励商家积分', $user['uid'], 'business_integral', 'zccg', $business_integral, $user['spread_uid'], $user['business_integral'], '众筹成功返还商家积分'); if ($user1){ UserBill::income('直推奖励紫积分', $user1['uid'], 'purple_integral', 'zccg', $sy1*0.7, $user1['spread_uid'], $user1['purple_integral'], '直推奖励紫积分'); UserBill::income('直推奖励商家积分', $user1['uid'], 'business_integral', 'zccg', $sy1*0.3, $user1['spread_uid'], $user1['business_integral'], '直推奖励商家积分'); $user1->save(); } if ($user2){ UserBill::income('间推奖励紫积分', $user1['uid'], 'purple_integral', 'zccg', $sy2*0.7, $user2['spread_uid'], $user2['purple_integral'], '间推奖励紫积分'); UserBill::income('间推奖励商家积分', $user1['uid'], 'business_integral', 'zccg', $sy2*0.3, $user2['spread_uid'], $user2['business_integral'], '间推奖励商家积分'); $user2->save(); } } } } } }