Qc.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\LabelMessage;
  4. use app\common\model\LevelOrder as LOM;
  5. use app\common\model\UserSearch;
  6. use app\common\model\VideoUrl;
  7. use app\common\service\OrderCallback;
  8. use think\cache\driver\Redis;
  9. use think\Db;
  10. use Easemob\Auth;
  11. use Easemob\User;
  12. class Qc extends Base {
  13. public function index()
  14. {
  15. var_dump(getVideoTime('72fd58d8385f44369b071a81e24133c4'));
  16. die();
  17. header('content-type:text/html;charset=utf-8');
  18. $str1 = 'Abcd';
  19. $str2 = '你cU季炯炯a流量B';
  20. $arr1 = str_split($str1);
  21. $arr2 = str_split($str2);
  22. echo "两个字符数组:";
  23. var_dump($arr1);
  24. var_dump($arr2);
  25. $result = array_intersect(
  26. array_map('strtolower', $arr1),
  27. array_map('strtolower', $arr2)
  28. );
  29. var_dump($result);
  30. $result = array_values($result);
  31. $this->success('返回成功', $result);
  32. }
  33. public function index22()
  34. {
  35. $app_name = sysconf('app_name');
  36. $app_logo = sysconf('app_logo');
  37. $search_log = UserSearch::getSearchTitle($this->user_id,1);
  38. $search_arr = [];
  39. $where_str = 'b.id > 0';
  40. foreach ($search_log as $t){
  41. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  42. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  43. }
  44. $table = 'dd_video_url';
  45. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  46. $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 ';
  47. $list = VideoUrl::field($field)->alias('a')
  48. ->leftJoin("(SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ($where_str)) c","c.id = a.id ")
  49. ->leftJoin('VideoIntro k','a.video_id = k.id')
  50. ->where('a.is_deleted = 0 AND a.status =1 AND k.is_deleted = 0 AND k.status = 1')
  51. ->order('is_recommend DESC')
  52. ->orderRaw("rand()")
  53. ->limit($this->off_set,$this->page_num)
  54. ->select()->toArray();
  55. foreach ($list as $v)
  56. {
  57. var_dump($v['id'].'--'.$v['is_recommend']);
  58. }
  59. die();
  60. $app_name = sysconf('app_name');
  61. $app_logo = sysconf('app_logo');
  62. $search_log = UserSearch::getSearchTitle($this->user_id,1);
  63. $search_arr = [];
  64. $where_str = 'b.id > 0';
  65. foreach ($search_log as $t){
  66. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  67. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  68. }
  69. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  70. $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 ';
  71. $table = 'dd_video_url';
  72. $order_by_two = 'a.read_num';
  73. $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}";
  74. $list = Db::query($sql);
  75. array_walk($list,function (&$v,$k)use ($app_name,$app_logo){
  76. if(!$v['user_id']){
  77. $v['app_name'] = $app_name;
  78. $v['app_logo'] = $app_logo;
  79. }else{
  80. $user_info = \app\common\model\User::where('id',$v['user_id'])->field('name,headimg')->find();
  81. $v['app_name'] = $user_info ? $user_info->name : '';
  82. $v['app_logo'] = $user_info ? $user_info->headimg : '';
  83. }
  84. });
  85. $this->success('ok',['list'=>$list,'sql'=>$sql]);
  86. }
  87. public function payOrder()
  88. {
  89. $this->user_id = 22;
  90. $order_id = input('post.order_id');
  91. $pay_type = input('post.pay_type',1);
  92. $order_info = LOM::where('id',$order_id)->find()->toArray();
  93. if($order_info['status'] != 0) $this->error('订单状态错误');
  94. if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
  95. if($order_info['price_total'] <= 0) $this->error('订单金额错误');
  96. $pay_no = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
  97. if(!$order_info['pay_no']) LOM::where('id',$order_id)->update(['pay_no'=>$pay_no]);
  98. $user_info = User::where('id',$this->user_id)->find()->toArray();
  99. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
  100. Db::startTrans();
  101. try {
  102. switch ($pay_type){
  103. case 1://微信小程序
  104. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  105. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
  106. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  107. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  108. $pay_config['config']['pay_no'] = $pay_no;
  109. $pay_config['config']['notify_url'] = $notify_url;
  110. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  111. $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
  112. $ret_data['config'] = $pay_config['config'];
  113. break;
  114. case 2 :
  115. if(!$user_info['openid']) $this->exception('请绑定公众号');
  116. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  117. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
  118. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  119. $ret_data['config'] = $pay_config['config'];
  120. break;
  121. }
  122. Db::commit();
  123. }catch (\Exception $e){
  124. $this->is_commit = false;
  125. $this->ret_msg = $e->getMessage();
  126. Db::rollback();
  127. }
  128. $this->transReturn($ret_data);
  129. }
  130. /**
  131. * @title 获取分享的签名
  132. * @desc 获取分享的签名
  133. * @url /api/qc/getWeChatSign
  134. * @method POST
  135. * @tag 基础
  136. *
  137. **/
  138. public function getWeChatSign(){
  139. $urls = input('url');
  140. $appid = config('app.official_account')['appid'];
  141. $secret = config('app.official_account')['secret'];
  142. $redis = new Redis();
  143. $access_token = $redis->get('access_token');
  144. if (!$access_token){
  145. $access_token = '';
  146. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
  147. $res= http_curl($url);
  148. if (isset($res['access_token'])){
  149. $redis->set('access_token',$res['access_token'],'7000');
  150. $access_token = $res['access_token'];
  151. }
  152. }
  153. $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
  154. $res2=http_curl($url2);
  155. if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
  156. $timestamp = time();
  157. $noncestr = get32Str(15);
  158. $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr&timestamp=$timestamp&url=".$urls;
  159. $sign = sha1($string);
  160. $return = [
  161. 'appid'=>$appid,
  162. 'noncestr'=>$noncestr,
  163. 'timestamp'=>$timestamp,
  164. 'url'=>$urls,
  165. 'sign'=>$sign,
  166. 'ticket'=>$res2['ticket']
  167. ];
  168. $this->success('成功',$return);
  169. }
  170. /**
  171. * 导入子项目数据
  172. * @auth true
  173. * @throws \think\Exception
  174. * @throws \think\exception\PDOException
  175. */
  176. public function import()
  177. {
  178. $get = $this->request->get();
  179. $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
  180. $project_id = $get['project_id'];
  181. $num = 5;
  182. try {
  183. $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
  184. $objExcel = $objReader->load($import_path);
  185. $list = $objExcel->getActiveSheet()->toArray();
  186. if (!isset($list[2][15]) || !$list[2][15]){
  187. $this->error('失败');
  188. }
  189. if (isset($list[2][16])){
  190. $this->error('失败');
  191. }
  192. Db::name($this->table3)->where('project_id',$project_id)->delete();
  193. Db::name($this->table)->where('id',$project_id)->update(['url'=>$get['url']]);
  194. $result = 0;
  195. foreach ($list as $k=>$v){
  196. if($k>=$num-1){
  197. if(array_filter($v)){
  198. $data=[];
  199. foreach ($v as $kk=>$vv){
  200. $data[IntToChr($kk)]=trim($vv);
  201. }
  202. $date['project_id'] = $project_id;
  203. $date['number'] = $data['A'];
  204. $date['cost_project'] = $data['B'];
  205. $date['area_calculating_aperture'] = $data['C'];
  206. $date['single_party_cost'] = $data['D'];
  207. $date['single_party_cost1'] = str_replace(',','',$data['D']);
  208. $date['total_price_included'] = $data['E'];
  209. $date['total_price_included1'] = str_replace(',','',$data['E']);
  210. $date['single_party_cost_excluding'] = $data['F'];
  211. $date['single_party_cost_excluding1'] = str_replace(',','',$data['F']);
  212. $date['total_price_included_excluding'] = $data['G'];
  213. $date['total_price_included_excluding1'] = str_replace(',','',$data['G']);
  214. $date['single_party_cost_tax'] = $data['H'];
  215. $date['single_party_cost_tax1'] = str_replace(',','',$data['H']);
  216. $date['single_party_cost_no_tax'] = $data['I'];
  217. $date['single_party_cost_no_tax1'] = str_replace(',','',$data['I']);
  218. $date['quantities'] = $data['J'];
  219. $date['quantities1'] = str_replace(',','',$data['J']);
  220. $date['calculating_unit'] = $data['K'];
  221. $date['unilateral_content'] = $data['L'];
  222. $date['unilateral_content1'] = str_replace(',','',$data['L']);
  223. $date['unilateral_content_excluding'] = $data['M'];
  224. $date['unilateral_content_excluding1'] = str_replace(',','',$data['M']);
  225. $date['saleable_single_party_tax'] = $data['N'];
  226. $date['saleable_single_party_tax1'] = str_replace(',','',$data['N']);
  227. $date['saleable_single_party_no_tax'] = $data['O'];
  228. $date['saleable_single_party_no_tax1'] = str_replace(',','',$data['O']);
  229. $date['note'] = $data['P'];
  230. $date['create_at'] = date('Y-m-d H:i:s');
  231. $numbers = explode('.',$data['A']);
  232. if (count($numbers)>1){
  233. array_pop($numbers); //去掉数组最后一组元素
  234. $number = implode('.',$numbers);
  235. $date['pid'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('id');
  236. $date['pname'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('cost_project');
  237. }else{
  238. $date['pid'] = 0;
  239. $date['pname'] = '';
  240. }
  241. if (Db::table($this->table3)->insertGetId($date)){
  242. $result = 1;
  243. }else{
  244. $result = 0;
  245. break;
  246. }
  247. }
  248. }
  249. }
  250. if ($result==1){
  251. $this->success('成功');
  252. }else{
  253. $this->error('失败');
  254. }
  255. } catch (\think\exception\ValidateException $e) {
  256. $this->error($e->getMessage());
  257. }
  258. }
  259. function excelToArray(){
  260. //加载excel文件
  261. $filename = dirname(__FILE__).'/result.xlsx';
  262. $objPHPExcelReader = \PHPExcel_IOFactory::load($filename);
  263. $sheet = $objPHPExcelReader->getSheet(0); // 读取第一个工作表(编号从 0 开始)
  264. $highestRow = $sheet->getHighestRow(); // 取得总行数
  265. $highestColumn = $sheet->getHighestColumn(); // 取得总列数
  266. $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');
  267. // 一次读取一列
  268. $res_arr = array();
  269. for ($row = 2; $row <= $highestRow; $row++) {
  270. $row_arr = array();
  271. for ($column = 0; $arr[$column] != 'F'; $column++) {
  272. $val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
  273. $row_arr[] = $val;
  274. }
  275. $res_arr[] = $row_arr;
  276. }
  277. return $res_arr;
  278. }
  279. public function index_match()
  280. {
  281. $password = "123456879_/";
  282. //密码必须包含大小写字母/数字/符号任意两者组合
  283. $regStr = "/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,16}$/";
  284. var_dump(preg_match($regStr, $password));
  285. }
  286. }