Qc.php 12 KB

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