Qc.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. }
  16. public function payOrder()
  17. {
  18. $this->user_id = 22;
  19. $order_id = input('post.order_id');
  20. $pay_type = input('post.pay_type',1);
  21. $order_info = LOM::where('id',$order_id)->find()->toArray();
  22. if($order_info['status'] != 0) $this->error('订单状态错误');
  23. if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
  24. if($order_info['price_total'] <= 0) $this->error('订单金额错误');
  25. $pay_no = $order_info['pay_no'] ? $order_info['pay_no'] : get_order_sn();// 支付单号
  26. if(!$order_info['pay_no']) LOM::where('id',$order_id)->update(['pay_no'=>$pay_no]);
  27. $user_info = User::where('id',$this->user_id)->find()->toArray();
  28. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid']];
  29. Db::startTrans();
  30. try {
  31. switch ($pay_type){
  32. case 1://微信小程序
  33. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  34. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'MWEB');
  35. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  36. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  37. $pay_config['config']['pay_no'] = $pay_no;
  38. $pay_config['config']['notify_url'] = $notify_url;
  39. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  40. $pay_config['config']['total_fee'] = $order_info['price_total'] * 100;
  41. $ret_data['config'] = $pay_config['config'];
  42. break;
  43. case 2 :
  44. if(!$user_info['openid']) $this->exception('请绑定公众号');
  45. $notify_url = $this->request->root(true) . '/api/we_chat_pay/LevelOrderNotify';
  46. $pay_config = WeChatPay::wxPay('订单支付',$pay_no,$order_info['price_total'],$notify_url,'JSAPI',$user_info['openid']);
  47. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  48. $ret_data['config'] = $pay_config['config'];
  49. break;
  50. }
  51. Db::commit();
  52. }catch (\Exception $e){
  53. $this->is_commit = false;
  54. $this->ret_msg = $e->getMessage();
  55. Db::rollback();
  56. }
  57. $this->transReturn($ret_data);
  58. }
  59. /**
  60. * @title 获取分享的签名
  61. * @desc 获取分享的签名
  62. * @url /api/qc/getWeChatSign
  63. * @method POST
  64. * @tag 基础
  65. *
  66. **/
  67. public function getWeChatSign(){
  68. $urls = input('url');
  69. $appid = config('app.official_account')['appid'];
  70. $secret = config('app.official_account')['secret'];
  71. $redis = new Redis();
  72. $access_token = $redis->get('access_token');
  73. if (!$access_token){
  74. $access_token = '';
  75. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
  76. $res= http_curl($url);
  77. if (isset($res['access_token'])){
  78. $redis->set('access_token',$res['access_token'],'7000');
  79. $access_token = $res['access_token'];
  80. }
  81. }
  82. $url2 ="https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi";
  83. $res2=http_curl($url2);
  84. if (!isset($res2) || $res2['errcode']!=0) $this->error('获取ticket失败');
  85. $timestamp = time();
  86. $noncestr = get32Str(15);
  87. $string = "jsapi_ticket=".$res2['ticket']."&noncestr=$noncestr&timestamp=$timestamp&url=".$urls;
  88. $sign = sha1($string);
  89. $return = [
  90. 'appid'=>$appid,
  91. 'noncestr'=>$noncestr,
  92. 'timestamp'=>$timestamp,
  93. 'url'=>$urls,
  94. 'sign'=>$sign,
  95. 'ticket'=>$res2['ticket']
  96. ];
  97. $this->success('成功',$return);
  98. }
  99. /**
  100. * 导入子项目数据
  101. * @auth true
  102. * @throws \think\Exception
  103. * @throws \think\exception\PDOException
  104. */
  105. public function import()
  106. {
  107. $get = $this->request->get();
  108. $import_path = $_SERVER['DOCUMENT_ROOT'].'/'.$get['path'];
  109. $project_id = $get['project_id'];
  110. $num = 5;
  111. try {
  112. $objReader =\PHPExcel_IOFactory::createReader('Excel2007');
  113. $objExcel = $objReader->load($import_path);
  114. $list = $objExcel->getActiveSheet()->toArray();
  115. if (!isset($list[2][15]) || !$list[2][15]){
  116. $this->error('失败');
  117. }
  118. if (isset($list[2][16])){
  119. $this->error('失败');
  120. }
  121. Db::name($this->table3)->where('project_id',$project_id)->delete();
  122. Db::name($this->table)->where('id',$project_id)->update(['url'=>$get['url']]);
  123. $result = 0;
  124. foreach ($list as $k=>$v){
  125. if($k>=$num-1){
  126. if(array_filter($v)){
  127. $data=[];
  128. foreach ($v as $kk=>$vv){
  129. $data[IntToChr($kk)]=trim($vv);
  130. }
  131. $date['project_id'] = $project_id;
  132. $date['number'] = $data['A'];
  133. $date['cost_project'] = $data['B'];
  134. $date['area_calculating_aperture'] = $data['C'];
  135. $date['single_party_cost'] = $data['D'];
  136. $date['single_party_cost1'] = str_replace(',','',$data['D']);
  137. $date['total_price_included'] = $data['E'];
  138. $date['total_price_included1'] = str_replace(',','',$data['E']);
  139. $date['single_party_cost_excluding'] = $data['F'];
  140. $date['single_party_cost_excluding1'] = str_replace(',','',$data['F']);
  141. $date['total_price_included_excluding'] = $data['G'];
  142. $date['total_price_included_excluding1'] = str_replace(',','',$data['G']);
  143. $date['single_party_cost_tax'] = $data['H'];
  144. $date['single_party_cost_tax1'] = str_replace(',','',$data['H']);
  145. $date['single_party_cost_no_tax'] = $data['I'];
  146. $date['single_party_cost_no_tax1'] = str_replace(',','',$data['I']);
  147. $date['quantities'] = $data['J'];
  148. $date['quantities1'] = str_replace(',','',$data['J']);
  149. $date['calculating_unit'] = $data['K'];
  150. $date['unilateral_content'] = $data['L'];
  151. $date['unilateral_content1'] = str_replace(',','',$data['L']);
  152. $date['unilateral_content_excluding'] = $data['M'];
  153. $date['unilateral_content_excluding1'] = str_replace(',','',$data['M']);
  154. $date['saleable_single_party_tax'] = $data['N'];
  155. $date['saleable_single_party_tax1'] = str_replace(',','',$data['N']);
  156. $date['saleable_single_party_no_tax'] = $data['O'];
  157. $date['saleable_single_party_no_tax1'] = str_replace(',','',$data['O']);
  158. $date['note'] = $data['P'];
  159. $date['create_at'] = date('Y-m-d H:i:s');
  160. $numbers = explode('.',$data['A']);
  161. if (count($numbers)>1){
  162. array_pop($numbers); //去掉数组最后一组元素
  163. $number = implode('.',$numbers);
  164. $date['pid'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('id');
  165. $date['pname'] = Db::name($this->table3)->where('project_id',$project_id)->where('number',$number)->value('cost_project');
  166. }else{
  167. $date['pid'] = 0;
  168. $date['pname'] = '';
  169. }
  170. if (Db::table($this->table3)->insertGetId($date)){
  171. $result = 1;
  172. }else{
  173. $result = 0;
  174. break;
  175. }
  176. }
  177. }
  178. }
  179. if ($result==1){
  180. $this->success('成功');
  181. }else{
  182. $this->error('失败');
  183. }
  184. } catch (\think\exception\ValidateException $e) {
  185. $this->error($e->getMessage());
  186. }
  187. }
  188. function excelToArray(){
  189. //加载excel文件
  190. $filename = dirname(__FILE__).'/result.xlsx';
  191. $objPHPExcelReader = \PHPExcel_IOFactory::load($filename);
  192. $sheet = $objPHPExcelReader->getSheet(0); // 读取第一个工作表(编号从 0 开始)
  193. $highestRow = $sheet->getHighestRow(); // 取得总行数
  194. $highestColumn = $sheet->getHighestColumn(); // 取得总列数
  195. $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');
  196. // 一次读取一列
  197. $res_arr = array();
  198. for ($row = 2; $row <= $highestRow; $row++) {
  199. $row_arr = array();
  200. for ($column = 0; $arr[$column] != 'F'; $column++) {
  201. $val = $sheet->getCellByColumnAndRow($column, $row)->getValue();
  202. $row_arr[] = $val;
  203. }
  204. $res_arr[] = $row_arr;
  205. }
  206. return $res_arr;
  207. }
  208. public function index_match()
  209. {
  210. $password = "123456879_/";
  211. //密码必须包含大小写字母/数字/符号任意两者组合
  212. $regStr = "/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,16}$/";
  213. var_dump(preg_match($regStr, $password));
  214. }
  215. }