'wdc支付']; /** * 生成订单唯一id * @param $uid 用户uid * @return string */ public static function getNewOrderId() { list($msec, $sec) = explode(' ', microtime()); $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); $orderId = 'lv' . $msectime . mt_rand(10000, 99999); while (self::be(['order_id' => $orderId])) $orderId = 'lv' . $msectime . mt_rand(10000, 99999); return $orderId; } /** * 创建订单 * @param $uid * @param $level_id * @param $payType * @param $mark * @return Level|bool|\think\Model */ public static function createLevelOrder($uid, $payType='wdc') { self::beginTrans(); try { //Log::write('会员1:111'.$payType, 'error'); if (!array_key_exists($payType, self::$payType)) return self::setErrorInfo('选择支付方式有误!', true); $userInfo = User::getUserInfo($uid); if (!$userInfo) return self::setErrorInfo('用户不存在!', true); if ($userInfo['wdc'] < 1000) return self::setErrorInfo(['status' => 'pay_deficiency', 'msg' => 'wdc不足1000']); $orderInfo = [ 'uid' => $uid, 'order_id' => self::getNewOrderId(), 'pay_price' =>1000, 'add_time' => time() ]; //print_r($orderInfo);die; $order = Line::create($orderInfo); if (!$order) { Log::write('会员1:订单生成失败', 'error'); return self::setErrorInfo('排队失败!', true); } $res1 = false !== User::bcDec($uid, 'wdc', sys_config('del_wdc'), 'uid'); $res2 = UserBill::expend('排队', $uid, 'wdc', 'wdc_pay_product', sys_config('del_wdc'),$order['id'], $userInfo['wdc'], '酒币参加排队'); $res3=self::do_line($order); $res=$res1 && $res2 && $res3; self::commitTrans($res); return $order; } catch (\PDOException $e) { Log::write('会员2:' . $e->getMessage(), 'error'); self::rollbackTrans(); return self::setErrorInfo('生成订单时SQL执行错误错误原因:' . $e->getMessage()); } } public static function do_line($order){ $sum=new Line(); $sum=$sum->count(); if($sum%5 == 0){ $id=Line::where('status',0)->where('is_ok',0)->order('id asc')->find(); $res1=Line::where('id',$id['id'])->save(['is_ok'=>1,'status'=>1,'suc_time'=>time()]); $userInfo = User::getUserInfo($id['uid']); if (!$userInfo) return self::setErrorInfo('用户不存在!', true); $res2 = false !== User::bcInc($id['uid'], 'brokerage_price',sys_config('suc_bo_pd'), 'uid'); $res3 = UserBill::income('排队完成', $id['uid'], 'now_money', 'brokerage', sys_config('suc_bo_pd'),$order, $userInfo['brokerage_price'], '排队结束奖励佣金'); $res=$res1 && $res2 && $res3; return $res; //@file_put_contents('111.txt',json_encode($id)); } @file_put_contents('222.txt',$sum); return true; } //失败 分发奖励 public static function js_line($order_id){ self::beginTrans(); $arr=self::where('order_id',$order_id)->find(); //每个人获取到的奖金 $userInfo = User::getUserInfo($arr['uid']); if (!$userInfo) return self::setErrorInfo('用户不存在!', true); $res1 = false !== User::bcInc($arr['uid'], 'brokerage_price',sys_config('suc_bo_pd'), 'uid'); $res2 = UserBill::income('立即结束排队', $arr['uid'], 'now_money', 'brokerage',sys_config('suc_bo_pd'),$arr['id'], $userInfo['brokerage_price'], '结束排队返回佣金'); $res3=self::where('order_id',$order_id)->save(['is_ok'=>1,'status'=>1,'suc_time'=>time()]); $res4=User::bcDec($arr['uid'], 'over_num',1, 'uid'); $res=$res1 && $res2 && $res3 && $res4; if($res){ self::commitTrans($res); return $res; }else{ self::rollbackTrans(); } } //订单列表 public static function my_line($type,$page,$limit,$uid){ if($type==1){ $arr=self::where('status',0)->where('uid',$uid)->where('is_ok',0)->order('add_time desc')->page($page,$limit)->select(); foreach ($arr as &$item){ $count=self::where('id','<',$item['id'])->where('is_ok',0)->where('status',0)->count(); $item['aa']=$count; if(!$count){ $item['key']=1; }else{ $item['key']=$count+1; } } } if($type==2){ $arr=self::where('status',1)->where('uid',$uid)->where('is_ok',1)->order('add_time desc')->page($page,$limit)->select(); } if($type==3){ $arr=StoreOrder::where('line_id','<>',0)->where('uid',$uid)->where('paid',1)->order('add_time desc')->page($page,$limit)->select(); foreach ($arr as &$value){ $value=StoreOrder::tidyOrder($value,true); } } return $arr; } public static function systemPage($where = []) { $model = new self; if ($where['keyword'] !== '') $model = $model->where('id|uid', 'LIKE', "%$where[keyword]%"); if($where['data'] != ''){ list($startTime,$endTime) = explode(' - ',$where['data']); $model = $model->where('add_time','>',strtotime($startTime)); $model = $model->where('add_time','<',strtotime($endTime)); } if ($where['type'] !== '') $model = $model->where('status',$where['type']); if (isset($where['excel']) && $where['excel'] == 1) { $data=$model->select()->toArray(); self::SaveExcel($data); } $model = $model->order('add_time asc,id asc'); return self::pagee($model); } /* * 保存并下载excel * $list array * return */ public static function SaveExcel($list) { $export = []; foreach ($list as $index => $item) { $data="姓名:".$item['name'].PHP_EOL.'性别:'.$item['sex'].PHP_EOL.'出生年月:'.$item['birth'].PHP_EOL.'移动电话:'.$item['phone'].PHP_EOL.'固定电话:'.$item['mobile'].PHP_EOL.'电子邮件:'.$item['email'] .PHP_EOL.'联系地址:'.$item['address'].PHP_EOL.'邮编:'.$item['zip'].PHP_EOL.'工作单位:'.$item['work'].PHP_EOL.'职业/职务/专业:'.$item['specialty'].PHP_EOL.'教育程度:'.$item['education'].PHP_EOL.'是否受过志愿服务:'.$item['is_vol'].PHP_EOL.'有无服务经验:'.$item['is_experience']; $arr='时间段:'.$item['quantum'].PHP_EOL.'日期:'.$item['date']; $data1=$item['taste'].PHP_EOL.'注明:'.$item['make_taste']; $data2=$item['speciali'].PHP_EOL.'注明:'.$item['make_speciali']; $export[] = [ $item['id'], $data, $arr, $data1, $data2, $item['add_time'] > 0 ? date('Y/m-d H:i:s', $item['add_time']) : '暂无', ]; } PHPExcelService::setExcelHeader(['序号', '个人资料', '可提供服务时间','有兴趣参与的工作','专长','添加时间']) ->setExcelTile('志愿者申请' . date('YmdHis', time()), '信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time())) ->setExcelContent($export) ->ExcelSave(); } /** * 分页 * @param null $model 模型 * @param null $eachFn 处理结果函数 * @param array $params 分页参数 * @param int $limit 分页数 * @return array */ public static function pagee($model = null, $eachFn = null, $params = [], $limit = 20) { if (is_numeric($eachFn) && is_numeric($model)) { return parent::page($model, $eachFn); } if (is_numeric($eachFn)) { $limit = $eachFn; $eachFn = null; } else if (is_array($eachFn)) { $params = $eachFn; $eachFn = null; } if (is_callable($model)) { $eachFn = $model; $model = null; } elseif (is_numeric($model)) { $limit = $model; $model = null; } elseif (is_array($model)) { $params = $model; $model = null; } if (is_numeric($params)) { $limit = $params; $params = []; } $listRows = [ 'list_rows' => $limit, 'query' => $params ]; $paginate = $model === null ? self::paginate($listRows, false) : $model->paginate($listRows, false); $list = is_callable($eachFn) ? $paginate->each($eachFn) : $paginate; foreach ($list as &$value){ $value['nickname']=User::where('uid',$value['uid'])->value('nickname'); if($value['status']==0){ $value['status']='正在进行中'; }elseif($value['status']==1){ $value['status']='已完成'; }else{ $value['status']='已兑换'; } } $page = $list->render(); $total = $list->total(); return compact('list', 'page', 'total'); } }