123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- <?php
- namespace app\api\controller;
- use app\common\model\LabelMessage;
- use app\common\model\LevelOrder as LOM;
- use app\common\model\UserSearch;
- use app\common\model\VideoUrl;
- use app\common\service\OrderCallback;
- use think\cache\driver\Redis;
- use think\Db;
- use Easemob\Auth;
- use Easemob\User;
- class Qc extends Base {
- public function index()
- {
- var_dump(getVideoTime('72fd58d8385f44369b071a81e24133c4'));
- die();
- header('content-type:text/html;charset=utf-8');
- $str1 = 'Abcd';
- $str2 = '你cU季炯炯a流量B';
- $arr1 = str_split($str1);
- $arr2 = str_split($str2);
- echo "两个字符数组:";
- var_dump($arr1);
- var_dump($arr2);
- $result = array_intersect(
- array_map('strtolower', $arr1),
- array_map('strtolower', $arr2)
- );
- var_dump($result);
- $result = array_values($result);
- $this->success('返回成功', $result);
- }
- public function index22()
- {
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- $search_log = UserSearch::getSearchTitle($this->user_id,1);
- $search_arr = [];
- $where_str = 'b.id > 0';
- foreach ($search_log as $t){
- $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
- $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
- }
- $table = 'dd_video_url';
- if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
- $field = ' a.id,a.title,a.cover,a.user_id,a.is_vip,a.create_at,a.ali_vid,a.video_id,a.duration ,IFNULL(is_recommend,0) is_recommend ';
- $list = VideoUrl::field($field)->alias('a')
- ->leftJoin("(SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ($where_str)) c","c.id = a.id ")
- ->leftJoin('VideoIntro k','a.video_id = k.id')
- ->where('a.is_deleted = 0 AND a.status =1 AND k.is_deleted = 0 AND k.status = 1')
- ->order('is_recommend DESC')
- ->orderRaw("rand()")
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as $v)
- {
- var_dump($v['id'].'--'.$v['is_recommend']);
- }
- die();
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- $search_log = UserSearch::getSearchTitle($this->user_id,1);
- $search_arr = [];
- $where_str = 'b.id > 0';
- foreach ($search_log as $t){
- $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
- $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
- }
- if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
- $field = ' a.id,a.title,a.cover,a.user_id,a.is_vip,a.create_at,a.ali_vid,a.video_id,a.duration ,IFNULL(is_recommend,0) is_recommend ';
- $table = 'dd_video_url';
- $order_by_two = 'a.read_num';
- $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id Left JOIN dd_video_intro as k ON a.video_id = k.id WHERE a.is_deleted = 0 AND a.status =1 AND k.is_deleted = 0 AND k.status = 1 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
- $list = Db::query($sql);
- array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
- if(!$v['user_id']){
- $v['app_name'] = $app_name;
- $v['app_logo'] = $app_logo;
- }else{
- $user_info = \app\common\model\User::where('id',$v['user_id'])->field('name,headimg')->find();
- $v['app_name'] = $user_info ? $user_info->name : '';
- $v['app_logo'] = $user_info ? $user_info->headimg : '';
- }
- });
- $this->success('ok',['list'=>$list,'sql'=>$sql]);
- }
- public function payOrder()
- {
- $this->user_id = 22;
- $order_id = input('post.order_id');
- $pay_type = input('post.pay_type',1);
- $order_info = LOM::where('id',$order_id)->find()->toArray();
- if($order_info['status'] != 0) $this->error('订单状态错误');
- if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
- if($order_info['price_total'] <= 0) $this->error('订单金额错误');
- $pay_no = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
- if(!$order_info['pay_no']) LOM::where('id',$order_id)->update(['pay_no'=>$pay_no]);
- $user_info = User::where('id',$this->user_id)->find()->toArray();
- $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
- Db::startTrans();
- try {
- switch ($pay_type){
- case 1://微信小程序
- $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
- $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
- if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
- $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
- $pay_config['config']['pay_no'] = $pay_no;
- $pay_config['config']['notify_url'] = $notify_url;
- $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
- $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
- $ret_data['config'] = $pay_config['config'];
- break;
- case 2 :
- if(!$user_info['openid']) $this->exception('请绑定公众号');
- $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
- $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
- if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
- $ret_data['config'] = $pay_config['config'];
- break;
- }
- Db::commit();
- }catch (\Exception $e){
- $this->is_commit = false;
- $this->ret_msg = $e->getMessage();
- Db::rollback();
- }
- $this->transReturn($ret_data);
- }
- /**
- * @title 获取分享的签名
- * @desc 获取分享的签名
- * @url /api/qc/getWeChatSign
- * @method POST
- * @tag 基础
- *
- **/
- public function getWeChatSign(){
- $urls = input('url');
- $appid = config('app.official_account')['appid'];
- $secret = config('app.official_account')['secret'];
- $redis = new Redis();
- $access_token = $redis->get('access_token');
- if (!$access_token){
- $access_token = '';
- $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
- $res= http_curl($url);
- if (isset($res['access_token'])){
- $redis->set('access_token',$res['access_token'],'7000');
- $access_token = $res['access_token'];
- }
- }
- $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
- $res2=http_curl($url2);
- if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
- $timestamp = time();
- $noncestr = get32Str(15);
- $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr×tamp=$timestamp&url=".$urls;
- $sign = sha1($string);
- $return = [
- 'appid'=>$appid,
- 'noncestr'=>$noncestr,
- 'timestamp'=>$timestamp,
- 'url'=>$urls,
- 'sign'=>$sign,
- 'ticket'=>$res2['ticket']
- ];
- $this->success('成功',$return);
- }
- /**
- * 导入子项目数据
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function import()
- {
- $get = $this->request->get();
- $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
- $project_id = $get['project_id'];
- $num = 5;
- try {
- $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
- $objExcel = $objReader->load($import_path);
- $list = $objExcel->getActiveSheet()->toArray();
- if (!isset($list[2][15]) || !$list[2][15]){
- $this->error('失败');
- }
- if (isset($list[2][16])){
- $this->error('失败');
- }
- Db::name($this->table3)->where('project_id',$project_id)->delete();
- Db::name($this->table)->where('id',$project_id)->update(['url'=>$get['url']]);
- $result = 0;
- foreach ($list as $k=>$v){
- if($k>=$num-1){
- if(array_filter($v)){
- $data=[];
- foreach ($v as $kk=>$vv){
- $data[IntToChr($kk)]=trim($vv);
- }
- $date['project_id'] = $project_id;
- $date['number'] = $data['A'];
- $date['cost_project'] = $data['B'];
- $date['area_calculating_aperture'] = $data['C'];
- $date['single_party_cost'] = $data['D'];
- $date['single_party_cost1'] = str_replace(',','',$data['D']);
- $date['total_price_included'] = $data['E'];
- $date['total_price_included1'] = str_replace(',','',$data['E']);
- $date['single_party_cost_excluding'] = $data['F'];
- $date['single_party_cost_excluding1'] = str_replace(',','',$data['F']);
- $date['total_price_included_excluding'] = $data['G'];
- $date['total_price_included_excluding1'] = str_replace(',','',$data['G']);
- $date['single_party_cost_tax'] = $data['H'];
- $date['single_party_cost_tax1'] = str_replace(',','',$data['H']);
- $date['single_party_cost_no_tax'] = $data['I'];
- $date['single_party_cost_no_tax1'] = str_replace(',','',$data['I']);
- $date['quantities'] = $data['J'];
- $date['quantities1'] = str_replace(',','',$data['J']);
- $date['calculating_unit'] = $data['K'];
- $date['unilateral_content'] = $data['L'];
- $date['unilateral_content1'] = str_replace(',','',$data['L']);
- $date['unilateral_content_excluding'] = $data['M'];
- $date['unilateral_content_excluding1'] = str_replace(',','',$data['M']);
- $date['saleable_single_party_tax'] = $data['N'];
- $date['saleable_single_party_tax1'] = str_replace(',','',$data['N']);
- $date['saleable_single_party_no_tax'] = $data['O'];
- $date['saleable_single_party_no_tax1'] = str_replace(',','',$data['O']);
- $date['note'] = $data['P'];
- $date['create_at'] = date('Y-m-d H:i:s');
- $numbers = explode('.',$data['A']);
- if (count($numbers)>1){
- array_pop($numbers); //去掉数组最后一组元素
- $number = implode('.',$numbers);
- $date['pid'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('id');
- $date['pname'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('cost_project');
- }else{
- $date['pid'] = 0;
- $date['pname'] = '';
- }
- if (Db::table($this->table3)->insertGetId($date)){
- $result = 1;
- }else{
- $result = 0;
- break;
- }
- }
- }
- }
- if ($result==1){
- $this->success('成功');
- }else{
- $this->error('失败');
- }
- } catch (\think\exception\ValidateException $e) {
- $this->error($e->getMessage());
- }
- }
- function excelToArray(){
- //加载excel文件
- $filename = dirname(__FILE__).'/result.xlsx';
- $objPHPExcelReader = \PHPExcel_IOFactory::load($filename);
- $sheet = $objPHPExcelReader->getSheet(0); // 读取第一个工作表(编号从 0 开始)
- $highestRow = $sheet->getHighestRow(); // 取得总行数
- $highestColumn = $sheet->getHighestColumn(); // 取得总列数
- $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
- // 一次读取一列
- $res_arr = array();
- for ($row = 2; $row <= $highestRow; $row++) {
- $row_arr = array();
- for ($column = 0; $arr[$column] != 'F'; $column++) {
- $val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
- $row_arr[] = $val;
- }
- $res_arr[] = $row_arr;
- }
- return $res_arr;
- }
- public function index_match()
- {
- $password = "123456879_/";
- //密码必须包含大小写字母/数字/符号任意两者组合
- $regStr = "/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,16}$/";
- var_dump(preg_match($regStr, $password));
- }
- }
|