Common.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/5/27
  7. *
  8. *
  9. */
  10. namespace app\controller\api;
  11. use app\common\model\user\UserCertification;
  12. use app\common\repositories\merchant\order\OrderGzcRepository;
  13. use app\common\repositories\merchant\order\OrderMerchantRepository;
  14. use app\common\repositories\store\order\StoreRefundStatusRepository;
  15. use app\common\repositories\user\UserVisitDayRepository;
  16. use app\controller\api\merchant\sxy\Access;
  17. use app\controller\api\store\product\Jd;
  18. use app\controller\api\store\product\TaoKe;
  19. use app\controller\api\store\product\Vip;
  20. use app\traits\ShouxinyiApiRequest;
  21. use crmeb\basic\BaseController;
  22. use app\common\repositories\store\shipping\ExpressRepository;
  23. use app\common\repositories\store\StoreCategoryRepository;
  24. use app\common\repositories\system\groupData\GroupDataRepository;
  25. use app\common\repositories\user\UserVisitRepository;
  26. use app\common\repositories\wechat\TemplateMessageRepository;
  27. use app\common\repositories\system\merchant\MerchantCategoryRepository;
  28. use crmeb\services\MiniProgramService;
  29. use crmeb\services\UploadService;
  30. use crmeb\services\WechatService;
  31. use Exception;
  32. use think\App;
  33. use think\facade\Cache;
  34. use think\facade\Config;
  35. use think\facade\Log;
  36. use think\Response;
  37. use think\response\Html;
  38. use Alipay\AopClient;
  39. use think\facade\Db;
  40. use function Symfony\Component\String\s;
  41. /**
  42. * Class Common
  43. * @package app\controller\api
  44. * @author xaboy
  45. * @day 2020/5/28
  46. */
  47. class Common extends BaseController
  48. {
  49. protected $merId;
  50. protected $source;
  51. public function __construct(App $app)
  52. {
  53. parent::__construct($app);
  54. $this->source = $this->request->header('source');
  55. $this->merId = $this->request->header('merId');
  56. }
  57. /**
  58. * @return mixed
  59. * @author xaboy
  60. * @day 2020/5/28
  61. */
  62. public function hotKeyword()
  63. {
  64. $keyword = systemGroupData('hot_keyword');
  65. return app('json')->success($keyword);
  66. }
  67. public function express(ExpressRepository $repository)
  68. {
  69. return app('json')->success($repository->options());
  70. }
  71. public function home_quick_link(){
  72. $home_quick_link = systemGroupData('home_quick_link');
  73. return app('json')->success($home_quick_link);
  74. }
  75. public function menus()
  76. {
  77. return app('json')->success(['banner' => systemGroupData('my_banner'), 'menu' => systemGroupData('my_menus')]);
  78. }
  79. public function refundMessage()
  80. {
  81. return app('json')->success(explode("\n", systemConfig('refund_message')));
  82. }
  83. public function config()
  84. {
  85. $config = systemConfig(['appraise_set', 'mews_all', 'help', 'all_people', 'proclamation', 'my_release', 'ali_login', 'wechat_login', 'real_name', 'hide_mer_status', 'mer_intention_open', 'share_info', 'sys_intention_agree', 'share_title', 'share_pic', 'store_user_min_recharge', 'recharge_switch', 'balance_func_status', 'yue_pay_status', 'site_logo', 'site_name', 'wechat_id']);
  86. $make = app()->make(TemplateMessageRepository::class);
  87. $config['tempid'] = $make->getSubscribe();
  88. return app('json')->success($config);
  89. }
  90. /*商户入驻资料配置*/
  91. public function mer_config()
  92. {
  93. $config = systemConfig(['mer_type', 'mer_cate', 'card_person', 'email', 'mer_name', 'name',
  94. 'phone', 'addr', 'door_head', 'business_license', 'bank_account',
  95. 'bank_location', 'bank_deposit', 'bank_branch', 'open_account', 'logo', 'desc', 'business_addr',
  96. 'district_addr', 'spread_account', 'credit_code']);
  97. return app('json')->success($config);
  98. }
  99. /*商户入驻资料配置*/
  100. public function agent_config()
  101. {
  102. $config = systemConfig(['apply_set', 'apply_name', 'apply_type', 'apply_business']);
  103. return app('json')->success($config);
  104. }
  105. /*提现*/
  106. public function withdrawal_config()
  107. {
  108. $config = systemConfig(['withdrawal_status', 'withdrawal_money', 'withdrawal_alipay', 'withdrawal_wchat', 'withdrawal_card']);
  109. return app('json')->success($config);
  110. }
  111. /*关于我们*/
  112. public function about_config()
  113. {
  114. $config = systemConfig(['about_edition_ios', 'about_edition_old_ios',
  115. 'about_edition_android', 'about_edition_old_android',
  116. 'about_address', 'about_name', 'about_phone', 'about_email',
  117. 'about_yl', 'about_zx', 'about_pcpc', 'wechat_id']);
  118. $config['about_yl_name'] = '养老计划';
  119. $config['about_zx_name'] = '中信公证处';
  120. $config['about_pcpc_name'] = 'PCPC';
  121. if($this->source=='yhc'){
  122. $config = merchantConfig($this->merId,['yhc_about_name','yhc_about_address','yhc_about_phone','yhc_about_email']);
  123. }
  124. return app('json')->success($config);
  125. }
  126. /**
  127. * 公证处配置
  128. * author: php迷途小书童
  129. * created: 2021/3/31 16:12
  130. */
  131. public function gzcConfig()
  132. {
  133. $config = systemGroupData('gzc');
  134. return app('json')->success($config);
  135. }
  136. /**
  137. * @param GroupDataRepository $repository
  138. * @return mixed
  139. * @author xaboy
  140. * @day 2020/6/3
  141. */
  142. public function userRechargeQuota(GroupDataRepository $repository)
  143. {
  144. $recharge_quota = $repository->groupDataId('user_recharge_quota', 0);
  145. $recharge_attention = explode("\n", systemConfig('recharge_attention'));
  146. return app('json')->success(compact('recharge_quota', 'recharge_attention'));
  147. }
  148. /**
  149. * @param $field
  150. * @return mixed
  151. * @author xaboy
  152. * @day 2020/5/28
  153. */
  154. public function uploadImage($field)
  155. {
  156. $file = $this->request->file($field);
  157. if (!$file)
  158. return app('json')->fail('请上传图片');
  159. $file = is_array($file) ? $file[0] : $file;
  160. validate(["$field|图片" => [
  161. 'fileSize' => 10097152,
  162. 'fileExt' => 'jpg,JPG,jpeg,png,bmp,gif',
  163. 'fileMime' => 'image/jpeg,image/png,image/gif',
  164. ]])->check([$field => $file]);
  165. try {
  166. $upload = UploadService::create();
  167. $time = date('Y-m-d');
  168. $path = "chuxubao/images/" . $time . '/';
  169. $info = $upload->to('def')->move($field,$path);
  170. if ($info === false) {
  171. return app('json')->fail($upload->getError());
  172. }
  173. $res = $upload->getUploadInfo();
  174. $res['dir'] = path_to_url($res['dir']);
  175. if (strpos($res['dir'], 'http') === false) $res['dir'] = "http://" . $this->request->host(true) . $res['dir'];//2222
  176. } catch (\Throwable $e) {
  177. Log::info('upload:' . $e->getMessage());
  178. return app('json')->fail('上传失败');
  179. }
  180. return app('json')->success(['path' => $res['dir']]);
  181. }
  182. /**
  183. * @param $field
  184. * @return mixed
  185. * @author xaboy
  186. * @day 2020/5/28
  187. */
  188. public function uploadBase64Image()
  189. {
  190. $image = $this->request->param('image');
  191. $base64_img = trim($image);
  192. // 正则表达式:判断图片文件类型是否正确
  193. if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_img, $result)) {
  194. $type = $result[2];
  195. if (in_array($type, array('pjpeg', 'jpeg', 'jpg', 'JPG', 'gif', 'bmp', 'png'))) {
  196. // 如果文件夹不存在则创建
  197. $up_dir = '/uploads/def/' . date('Ymd') . '/';
  198. if (!is_dir('./public' . $up_dir)) {
  199. mkdir('./public' . $up_dir, 0777, true);
  200. }
  201. $new_file = (int)(microtime(true) * 1000);
  202. $imgName = $up_dir . "{$new_file}." . $type;
  203. if (file_put_contents('./public' . $imgName, base64_decode(str_replace($result[1], '', $base64_img)))) {
  204. // 完整的图片地址(包括域名)
  205. $imgurl = "http://" . $this->request->host(true) . $imgName;//2222
  206. return app('json')->success(['path' => $imgurl]);
  207. } else {
  208. return app('json')->fail('图片上传失败');
  209. }
  210. } else {
  211. return app('json')->fail('图片类型错误');
  212. }
  213. } else {
  214. return app('json')->fail('文件错误');
  215. }
  216. }
  217. /**
  218. * @return Response
  219. * @author xaboy
  220. * @day 2020/6/3
  221. */
  222. public function wechatNotify()
  223. {
  224. try {
  225. return response(WechatService::create()->handleNotify()->getContent());
  226. } catch (Exception $e) {
  227. Log::info('支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  228. }
  229. }
  230. /**
  231. * @return Response
  232. * @author xaboy
  233. * @day 2020/6/3
  234. */
  235. public function alipayNotify()
  236. {
  237. $post = $this->request->post();
  238. try {
  239. $aop = new AopClient;
  240. $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
  241. $flag = $aop->rsaCheckV1($post, NULL, "RSA2");
  242. if ($flag) {
  243. event('pay_success_order', ['order_sn' => $post['out_trade_no'], 'data' => $post]);
  244. }
  245. } catch (Exception $e) {
  246. Log::info('支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  247. }
  248. }
  249. public function routineNotify()
  250. {
  251. try {
  252. return response(MiniProgramService::create()->handleNotify()->getContent());
  253. } catch (Exception $e) {
  254. Log::info('支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  255. }
  256. Log::info('小程序支付成功回调');
  257. }
  258. /*代理支付支付宝回调*/
  259. public function aliPayAgentNotify()
  260. {
  261. $post = $this->request->post();
  262. try {
  263. $aop = new AopClient;
  264. $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB';
  265. $flag = $aop->rsaCheckV1($post, NULL, "RSA2");
  266. if ($flag) {
  267. event('pay_success_order_agent', ['order_sn' => $post['out_trade_no'], 'data' => $post]);
  268. }
  269. } catch (Exception $e) {
  270. Log::info('代理支付支付回调失败:' . var_export([$e->getMessage(), $e->getFile() . ':' . $e->getLine()], true));
  271. }
  272. }
  273. /**
  274. * 获取图片base64
  275. * @return mixed
  276. */
  277. public function get_image_base64()
  278. {
  279. list($imageUrl, $codeUrl) = $this->request->params([
  280. ['image', ''],
  281. ['code', ''],
  282. ], true);
  283. try {
  284. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : '';
  285. if (!$codeTmp) {
  286. $putCodeUrl = put_image($codeUrl);
  287. $code = $putCodeUrl ? image_to_base64('./runtime/temp' . $putCodeUrl) : '';
  288. $code && unlink('./runtime/temp' . $putCodeUrl);
  289. }
  290. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : '';
  291. if (!$imageTmp) {
  292. $putImageUrl = put_image($imageUrl);
  293. $image = $putImageUrl ? image_to_base64('./runtime/temp' . $putImageUrl) : '';
  294. $image && unlink('./runtime/temp' . $putImageUrl);
  295. }
  296. return app('json')->success(compact('code', 'image'));
  297. } catch (\Exception $e) {
  298. return app('json')->fail($e->getMessage());
  299. }
  300. }
  301. public function home()
  302. {
  303. $banner = systemGroupData('home_banner');
  304. $menu = systemGroupData('home_menu');
  305. foreach ($menu as $k => $v) {
  306. if (in_array($v['name'], ['京东', '饿了么', '唯品会', '拼多多', '苏宁易购'])) {
  307. $menu[$k]['is_change'] = 1;
  308. }
  309. }
  310. $hot = systemGroupData('home_hot');
  311. $ad = systemConfig(['home_ad_pic', 'home_ad_url']);
  312. $category = app()->make(StoreCategoryRepository::class)->getTwoLevel();
  313. $shop_category = app()->make(MerchantCategoryRepository::class)->allOptions();
  314. return app('json')->success(compact('banner', 'menu', 'hot', 'ad', 'category', 'shop_category'));
  315. }
  316. public function home_banner_new()
  317. {
  318. $banner = systemGroupData('home_banner_new');
  319. return app('json')->success($banner);
  320. }
  321. public function user_banner()
  322. {
  323. $banner = systemGroupData('user_banner');
  324. return app('json')->success($banner);
  325. }
  326. public function visit()
  327. {
  328. [$page, $type] = $this->request->params(['page', 'type'], true);
  329. $uid = $this->request->uid();
  330. if (!$page || !$uid) return app('json')->fail();
  331. $userVisitRepository = app()->make(UserVisitRepository::class);
  332. $type == 'routine' ? $userVisitRepository->visitSmallProgram($uid, $page) : $userVisitRepository->visitPage($uid, $page);
  333. return app('json')->success();
  334. }
  335. /*
  336. *@ banner图
  337. *@$type nearby=附近页面banner
  338. *@author cabbage
  339. * */
  340. public function hotBanner($type)
  341. {
  342. if (!in_array($type, ['new', 'hot', 'best', 'good', 'nearby']))
  343. $data = [];
  344. else
  345. $data = systemGroupData($type . '_home_banner');
  346. return app('json')->success($data);
  347. }
  348. /*版本更新*/
  349. public function about_change()
  350. {
  351. $data = $this->request->params(['about', 'type']);
  352. //安卓
  353. if ($data['type'] == 1) {
  354. $config = systemConfig(['about_edition_android', 'about_link_android', 'update_content','Android_forced_update']);
  355. $version = str_replace('.', '', $data['about']);
  356. $sysVersion = str_replace('.', '', $config['about_edition_android']);
  357. if ($version < $sysVersion) {
  358. return app('json')->success($config);
  359. }else{
  360. return app('json')->fail('已是最新版本');
  361. }
  362. }
  363. if ($data['type'] == 2) {
  364. $config = systemConfig(['about_edition_ios', 'about_link_ios', 'update_content','IOS_forced_update']);
  365. if ($data['about'] != $config['about_edition_ios']) {
  366. return app('json')->success($config);
  367. } else {
  368. return app('json')->fail('已是最新版本');
  369. }
  370. }
  371. }
  372. /*版本更新运营商*/
  373. public function about_change_yys()
  374. {
  375. $data = $this->request->params(['about', 'type']);
  376. //安卓
  377. if ($data['type'] == 1) {
  378. $config = systemConfig(['yys_code_android', 'yys_link_android']);
  379. if ($data['about'] != $config['yys_code_android']) {
  380. return app('json')->success($config);
  381. } else {
  382. return app('json')->fail('已是最新版本');
  383. }
  384. }
  385. if ($data['type'] == 2) {
  386. }
  387. }
  388. //通过curl方式获取请求内容公共方法
  389. public static function sendCurl($url, $data = array(), $method = 'get',$header = array() )
  390. {
  391. if ($method == 'post') {
  392. //使用crul模拟
  393. $ch = curl_init();
  394. //禁用https
  395. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  396. //允许请求以文件流的形式返回
  397. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  398. curl_setopt($ch, CURLOPT_POST, 1);
  399. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
  400. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  401. curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 30);
  402. curl_setopt($ch, CURLOPT_URL, $url);
  403. if ($header) {
  404. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  405. }
  406. $result = curl_exec($ch); //执行发送
  407. curl_close($ch);
  408. } else {
  409. if (ini_get('allow_fopen_url') == '1') {
  410. $result = file_get_contents($url);
  411. } else {
  412. //使用crul模拟
  413. $ch = curl_init();
  414. //允许请求以文件流的形式返回
  415. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  416. //禁用https
  417. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  418. curl_setopt($ch, CURLOPT_URL, $url);
  419. if ($header) {
  420. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  421. }
  422. $result = curl_exec($ch); //执行发送
  423. curl_close($ch);
  424. }
  425. }
  426. return json_decode($result, true);
  427. }
  428. public function iOSExamineStatsu_api($version)
  429. {
  430. // $res=2;
  431. // if ($this->check() == 'ios') {
  432. $res = Db::name('iosexaminestatsu')->where('version', $version)->value('status');
  433. if (!$res) {
  434. return app('json')->fail('未获取到该该版本的信息');
  435. // }
  436. }
  437. Log::info($_SERVER);
  438. return app('json')->success($res);
  439. }
  440. public function check()
  441. {
  442. $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
  443. $is_pc = (strpos($agent, 'windows nt')) ? true : false;
  444. $is_mac = (strpos($agent, 'mac os')) ? true : false;
  445. $is_iphone = (strpos($agent, 'iphone')) ? true : false;
  446. $is_android = (strpos($agent, 'android')) ? true : false;
  447. $is_ipad = (strpos($agent, 'ipad')) ? true : false;
  448. if ($is_pc) {
  449. return 'and';
  450. }
  451. if ($is_mac) {
  452. return 'ios';
  453. }
  454. if ($is_iphone) {
  455. return 'ios';
  456. }
  457. if ($is_android) {
  458. return 'and';
  459. }
  460. if ($is_ipad) {
  461. return 'ios';
  462. }
  463. }
  464. public function roll_yanglaojin(){
  465. $list = Db::name('UserBill')
  466. -> alias('ub')
  467. -> join('User u',"ub.uid = u.uid")
  468. -> where(['ub.commission_type'=>5,'ub.status'=>1])
  469. -> orderRand()
  470. -> limit(20)
  471. -> field('ub.number,u.nickname')
  472. -> select()
  473. -> each(function ($item){
  474. // $item['msg'] = '养老金快报:【'.$item['nickname']."】获得".$item['number']."养老金";
  475. $item['msg'] = '【'.$item['nickname']."】获得".$item['number']."养老金";
  476. return $item;
  477. })
  478. -> toArray();
  479. return app('json')->success($list);
  480. }
  481. public function applet_audit()
  482. {
  483. $status=Db::name('system_config_value')->where('config_key','xiaochengxu_shenhe')->value('value');
  484. return app('json')->success($status);
  485. }
  486. public function pension_jiesuan()
  487. {
  488. $where=[
  489. 'commission_type'=>5,
  490. 'gzc'=>0,
  491. 'status'=>1
  492. ];
  493. $bill_data=Db::name('user_bill')->where($where)->select()->toArray();
  494. $i=0;
  495. try {
  496. foreach ($bill_data as $k=>$v){
  497. $certification =Db::name('user_certification')->where('uid',$v['uid'])->find();
  498. if($certification) {
  499. $online = ['uid' => $v['uid'], 'pay_type' => 1, 'order_sn' => $v['order_sn'], 'order_id' => $v['link_id']];
  500. $certification = ['user_name' => $certification['user_name'], 'mobile'=>$certification['mobile'], 'user_card' => $certification['user_card']];
  501. $res=$this->GZC($online, $certification, $v['number']);
  502. if($res) {
  503. Db::name('user_bill')->where('bill_id', $v['bill_id'])->update(['gzc' => 1]);
  504. echo $v['bill_id'].'入账成功';
  505. $i++;
  506. }
  507. }else{
  508. echo $v['uid'].'没有实名注册没有给到养老金';
  509. }
  510. }
  511. }catch (\Exception $exception){
  512. Db::name('log')->insert(['data'=>'公证处入账错误:'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  513. }
  514. return app('json')->success('成功处理'.$i.'条数据');
  515. }
  516. public function GZC($online,$certification,$pension)
  517. {
  518. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  519. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  520. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  521. $create = [
  522. 'uid' => $online['uid'],
  523. 'platform_no' => $orderId,
  524. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  525. 'user_name' => $certification['user_name'],
  526. 'mobile' => $certification['mobile'],
  527. 'user_card' => $certification['user_card'],
  528. 'pension' => $pension,
  529. 'order_type' => 2,
  530. 'out_trade_no' => $online['order_sn']
  531. ];
  532. $test_user = Db::name('user') -> where('uid',$online['uid']) -> value('test_user');
  533. if($test_user == 0){
  534. $res = $OrderGzcRepository->create($create);
  535. }
  536. // $res=$OrderGzcRepository->create($create);
  537. return isset($res)?$res:false;
  538. }
  539. public function add_activation_code(){
  540. $phone = $this->request->param('phone');
  541. $num = $this->request->param('num');
  542. $uid = Db::name('user') -> where('account',$phone) -> value('uid');
  543. if(!$uid){
  544. return app('json')->fail('找不到用户');
  545. }
  546. $access = app() -> make(Access::class);
  547. $access -> add_activation_code($uid,$num);
  548. }
  549. public function refund_sxy_order_id(){
  550. $order_id = $this->request->param('order_id');
  551. $group_order = Db::name("store_order")
  552. ->alias('so')
  553. ->join('store_group_order sgo', 'so.group_order_id = sgo.group_order_id')
  554. ->where("so.order_id",$order_id)
  555. -> field("serialNumber,group_order_sn,mer_money,hf_pay_id,so.pay_price")
  556. -> find();
  557. $datas['requestId'] = ShouxinyiApiRequest::getOrderNumber('refund'); //订单号
  558. $datas['orderId'] = $group_order['serialNumber'];//交易订单的流水号
  559. $datas['isCollect'] = '1';
  560. $datas['amount'] = $group_order['pay_price'] * 100;//退款金额
  561. $datas['remark'] = '退款';
  562. $order_status=Db::name('store_split_order')->where('group_order_id',$group_order['group_order_sn'])->field('mid,status,subSplitRequestId,hf_pay_id,splitAmount')->select();
  563. if($order_status){
  564. $order_status=$order_status->toArray();
  565. }
  566. if($order_status && $order_status[0]['status']==1 && $order_status[1]['status']==1){
  567. //已分账退款(确认收货)
  568. $refundCollectDetail = [
  569. [
  570. 'collectAccType' => 'SPLIT_ACC',//归集类型 被分账方账户
  571. 'collectAmount' => bcmul ($group_order['mer_money'] , '100'),//归集金额
  572. 'subSplitRequestId'=>$order_status[0]['subSplitRequestId']
  573. ],
  574. [
  575. 'collectAccType' => 'SPLIT_ACC',//归集类型 被分账方账户
  576. 'collectAmount' => bcmul (bcsub($group_order['pay_price'],$group_order['mer_money'],2) , '100'),//归集金额
  577. 'subSplitRequestId'=>$order_status[1]['subSplitRequestId']
  578. ]
  579. ];
  580. $datas['refundCollectDetail'] = $refundCollectDetail;//归集信息
  581. }else{
  582. //未分账退款(未确认收货)
  583. $refundCollectDetail = array(
  584. 'collectAccType' => 'WAIT_ACC',//归集类型
  585. 'collectAmount' => $group_order['pay_price'] * 100,//归集金额
  586. );
  587. $datas['refundCollectDetail'] = [$refundCollectDetail];//归集信息
  588. }
  589. dump($datas);
  590. $sxyres = ShouxinyiApiRequest::refund($datas);
  591. dump($sxyres);
  592. if($sxyres['status'] != 'SUCCESS'){
  593. echo '退款失败';
  594. }
  595. }
  596. public function get_mp_access_token($name="WECHAT_MP")
  597. {
  598. if ($name == 'WECHAT_MP'){
  599. $appid = env('WECHAT_MP.APPID');
  600. $secret = env('WECHAT_MP.SECRET');
  601. }elseif ($name == 'WECHAT_TDYL'){
  602. $appid = env('WECHAT_TDYL.APPID');
  603. $secret = env('WECHAT_TDYL.SECRET');
  604. }else{
  605. return false;
  606. }
  607. $access_token = Cache::get("{$appid}_mp_access_token");
  608. if ($access_token)
  609. return $access_token;
  610. $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}";
  611. $res = curlGet($url);
  612. Cache::set("{$appid}_mp_access_token", $res['access_token'], $res['expires_in']);
  613. return $res['access_token'];
  614. }
  615. public function getqrcode()
  616. {
  617. $data = $this->request->param('page');
  618. if($data['page'] == ''){
  619. return app('json')->success('参数为空');
  620. }
  621. $user = app()->make(\app\controller\merchant\user\User::class);
  622. $access_token = $this->get_mp_access_token();
  623. $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token;
  624. $res = $user->posturl($url, $data);
  625. //判断是否是 json格式
  626. if (is_null(json_decode($res))) {
  627. $new_file = (int)(microtime(true) * 1000);
  628. $dir = iconv("UTF-8", "GBK", "./public/mpqrcode");
  629. if (!file_exists($dir)) {
  630. mkdir($dir, 0777, true);
  631. }
  632. $path = $dir . '/' . $new_file . ".jpg";
  633. file_put_contents($path, $res);
  634. $imgurl = env('APP_URL') . "/mpqrcode/" . $new_file . ".jpg";
  635. return app('json')->success(['qrcode' => $imgurl, 'path' => $path]);
  636. } else {
  637. //没有接收到数据流
  638. return false;
  639. }
  640. }
  641. public function user_visit_day_count()
  642. {
  643. $redis = Cache::store('redis')->handler();
  644. $number = (int)$redis->get('user_visit_day');
  645. if($number){
  646. $userVisitDayRepository = app()->make(UserVisitDayRepository::class);
  647. $userVisitDayRepository->incrUserVisitDay(date('Y-m-d'),$number);
  648. }
  649. $ip_list = $redis->lrange('user_visit', 0, -1);
  650. if (!empty($ip_list)) {
  651. foreach ($ip_list as $ip) {
  652. $userVisitRepository = app()->make(UserVisitRepository::class);
  653. if (empty($userVisitRepository->getWhere(['ip' => $ip]))) {
  654. $userVisitRepository->addVisit(0, 'count', 0, '', $ip);
  655. }
  656. }
  657. }
  658. $redis->del('user_visit_day');
  659. $redis->del('user_visit');
  660. return $number;
  661. }
  662. }