SystemBank.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: scstf
  5. * Date: 2018/9/4
  6. * Time: 17:21
  7. */
  8. namespace App\Commons\Model;
  9. use Biz\Account\AccountManager;
  10. use \System\Model;
  11. use Illuminate\Support\Facades\DB;
  12. use DB as DataBase;
  13. class SystemBank extends Model
  14. {
  15. public $timestamps = false;
  16. protected $table = 'system_bank';
  17. public static function getNative($type = 2)
  18. {
  19. $groups = $_SESSION['uinfo']['group_code'];
  20. if(empty($groups)){
  21. $account = new AccountManager();
  22. $groups = $account->getCurrentUser()->group_code;
  23. }
  24. $arr = explode (',', $groups);
  25. if (!$arr) return -1999;
  26. $where = '';
  27. foreach ($arr as $k => $v) {
  28. if ($v) {
  29. $where .= "groups like '%," . $v . ",%' or ";
  30. }
  31. }
  32. $where = trim ($where, 'or ');
  33. if (!$where) {
  34. return $ret = null;
  35. //return $ret = self::where (['type' => $type, 'status' => 1,])->get (['id', 'bank_num', 'bank', 'remark', 'infoname', 'type']);
  36. } else {
  37. $where = "({$where})";
  38. return $ret = self::where (['type' => $type, 'status' => 1,])->whereRaw ($where)->get (['id', 'bank_num', 'bank', 'remark', 'infoname', 'type']);
  39. }
  40. }
  41. public static function getOnlineNatives()
  42. {
  43. $userInfo=(new AccountManager())->getCurrentUser();
  44. $groups = $userInfo?$userInfo['group_code']:'';
  45. $arr = explode (',', $groups);
  46. if (!$arr) return -1999;
  47. $where = '';
  48. foreach ($arr as $k => $v) {
  49. if ($v) {
  50. $where .= "groups like '%," . $v . ",%' or ";
  51. }
  52. }
  53. $where = trim ($where, 'or ');
  54. $where = "({$where})";
  55. $sql = 'select count(*) as num,type from system_bank where type<>1 and status=1 and ' . $where . ' group by type order by type asc';
  56. $data = M ('')->join ($sql);
  57. if (empty($data)) {
  58. return null;
  59. }
  60. $json = '[{"id": 2, "name": "微信", "imgSrc": "/Public/img/banks/wxpay.png"},
  61. {"id": 3, "name": "支付宝", "imgSrc": "/Public/img/banks/alipay.png"},
  62. {"id": 4, "name": "QQ", "imgSrc": "/Public/img/banks/qqpay.png"},
  63. {"id": 5, "name": "银联", "imgSrc": "/Public/img/banks/unionpay.png"},
  64. {"id": 6, "name": "京东", "imgSrc": "/Public/img/banks/jdpay.png"},
  65. {"id": 7, "name": "多合一", "imgSrc": "/Public/img/banks/aiopay.png"}]';
  66. $arr = json_decode ($json, 1);
  67. $tmp = [];
  68. foreach ($data as $k => $v) {
  69. $tmp[$v['type']] = $v['num'];//array[1=>7,]
  70. }
  71. foreach ($arr as $k => $v) {
  72. if (!isset($tmp[$v['id']])) {
  73. unset($arr[$k]);
  74. }
  75. }
  76. //dd(array_values($arr));
  77. return array_values ($arr);
  78. }
  79. }