SicpayConfig.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. namespace addons\Sicpay\common\models;
  3. use common\enums\PayTypeEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\user\User;
  6. use Yii;
  7. use yii\helpers\Json;
  8. /**
  9. * This is the model class for table "{{%addons_sicpay_config}}".
  10. *
  11. * @property int $id
  12. * @property int|null $mall_id
  13. * @property string|null $agencyId 商户号
  14. * @property string|null $merRsaPrivateKey 商户RSA私钥
  15. * @property string|null $rootRsaPublicKey 平台(我司)RSA公
  16. * @property string|null $merAesKey 商户aes密钥
  17. * @property string|null $rootAesKey 平台(我司)aes密钥
  18. * @property string|null $pay_way
  19. * @property string|null $alipay
  20. * @property string|null $wechat
  21. * @property string|null $bank
  22. * @property string|null $terminal_no
  23. * @property string|null $child_merchant_no
  24. * @property int $status
  25. * @property int $created_at
  26. * @property int $updated_at
  27. */
  28. class SicpayConfig extends BaseActiveRecord
  29. {
  30. const ALIPAY_APP = "ALIPAY_APP";
  31. const WECHAT_APP = "WECHAT_APP";
  32. const CLOUD_APP = "CLOUD_APP";
  33. const ALIPAY_WAP = "ALIPAY_WAP";
  34. const WECHAT_WAP = "WECHAT_WAP";
  35. const CLOUD_H5 = "CLOUD_H5";
  36. const ALIPAY_MP = "ALIPAY_MP";
  37. const WECHAT_MP = "WECHAT_MP";
  38. const WECHAT_GZH = "WECHAT_GZH";
  39. const WECHAT_FRONT_QR = "WECHAT_FRONT_QR"; // 微信正扫
  40. public static $type_text = [
  41. self::ALIPAY_APP => "支付宝APP",
  42. self::WECHAT_APP => "微信APP",
  43. self::CLOUD_APP => "云闪付APP",
  44. self::ALIPAY_WAP => "支付宝H5",
  45. self::WECHAT_WAP => "微信H5",
  46. self::CLOUD_H5 => "在线银联",
  47. self::WECHAT_GZH => "微信公众号",
  48. self::ALIPAY_MP => "支付宝小程序",
  49. self::WECHAT_MP => "公众号小程序",
  50. self::WECHAT_FRONT_QR => "微信正扫",
  51. ];
  52. const APP = 1; // app
  53. const H5 = 2; // h5
  54. const MP = 3; // 小程序
  55. const WECHAT = 4; // 公众号
  56. const CLOUD = 1; // 云闪付
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public static function tableName()
  61. {
  62. return '{{%addons_sicpay_config}}';
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function rules()
  68. {
  69. return [
  70. [['mall_id', 'created_at', 'updated_at','status'], 'integer'],
  71. [['merRsaPrivateKey', 'rootRsaPublicKey', 'merAesKey', 'rootAesKey'], 'string'],
  72. [['agencyId'], 'string', 'max' => 32],
  73. [['pay_way', 'alipay', 'wechat', 'bank','terminal_no','child_merchant_no'], 'string', 'max' => 255],
  74. ];
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function attributeLabels()
  80. {
  81. return [
  82. 'id' => 'ID',
  83. 'mall_id' => 'Mall ID',
  84. 'agencyId' => '商户号',
  85. 'merRsaPrivateKey' => '商户RSA私钥',
  86. 'rootRsaPublicKey' => '平台(我司)RSA公',
  87. 'merAesKey' => '商户aes密钥',
  88. 'rootAesKey' => '平台(我司)aes密钥',
  89. 'created_at' => 'Created At',
  90. 'updated_at' => 'Updated At',
  91. ];
  92. }
  93. public function beforeValidate ()
  94. {
  95. if (!parent::beforeValidate()) {
  96. return false;
  97. }
  98. return true;
  99. }
  100. public static function getConfig($mall_id) {
  101. $config = self::find()->where(['mall_id'=>$mall_id])->one();
  102. if(!empty($config)){
  103. $config->pay_way = Json::decode($config['pay_way']);
  104. $config->alipay = Json::decode($config['alipay']);
  105. $config->wechat = Json::decode($config['wechat']);
  106. $config->bank = Json::decode($config['bank']);
  107. }else{
  108. return [];
  109. }
  110. return $config;
  111. }
  112. // 获取app支付渠道
  113. public function _get_app_way(){
  114. $way = [];
  115. // 支付宝
  116. // if(in_array(self::APP,$this->alipay)){
  117. // $way[] = [
  118. // "name"=>"中金-支付宝",
  119. // "img"=>"resources/img/payment/alipay.png",
  120. // "pay_type"=>PayTypeEnum::SIC_PAY,
  121. // "action"=>"sic_pay",
  122. // "trade_type"=>self::ALIPAY_APP
  123. // ];
  124. // }
  125. // // 微信
  126. // if(in_array(self::APP,$this->wechat)){
  127. // $way[] = [
  128. // "name"=>"中金-微信",
  129. // "img"=>"resources/img/payment/wechat.png",
  130. // "pay_type"=>PayTypeEnum::SIC_PAY,
  131. // "action"=>"sic_pay",
  132. // "trade_type"=>self::WECHAT_APP
  133. // ];
  134. // }
  135. // // 银联
  136. // if(in_array(self::APP,$this->bank)){
  137. // $way[] = [
  138. // "name"=>"中金-云闪付",
  139. // "img"=>"resources/img/payment/cloud.jpg",
  140. // "pay_type"=>PayTypeEnum::SIC_PAY,
  141. // "action"=>"sic_pay",
  142. // "trade_type"=>self::CLOUD_APP
  143. // ];
  144. // }
  145. // 支付宝
  146. if(in_array(self::H5,$this->alipay)){
  147. $way[] = [
  148. "name"=>"中金-支付宝",
  149. "img"=>"resources/img/payment/alipay.png",
  150. "pay_type"=>PayTypeEnum::SIC_PAY,
  151. "action"=>"sic_pay",
  152. "trade_type"=>self::ALIPAY_WAP
  153. ];
  154. }
  155. // 微信
  156. if(in_array(self::APP,$this->wechat)){
  157. $way[] = [
  158. "name"=>"中金-微信",
  159. "img"=>"resources/img/payment/wechat.png",
  160. "pay_type"=>PayTypeEnum::SIC_PAY,
  161. "action"=>"sic_pay",
  162. "trade_type"=>self::WECHAT_APP
  163. ];
  164. }
  165. // 银联
  166. if(in_array(self::H5,$this->bank)){
  167. $way[] = [
  168. "name"=>"中金-在线银联",
  169. "img"=>"resources/img/payment/joinpay_fast.png",
  170. "pay_type"=>PayTypeEnum::SIC_PAY,
  171. "action"=>"sic_pay",
  172. "trade_type"=>self::CLOUD_H5,
  173. ];
  174. }
  175. return $way;
  176. }
  177. // 获取h5支付渠道
  178. public function _get_h5_way(){
  179. $way = [];
  180. // 支付宝
  181. if(in_array(self::H5,$this->alipay)){
  182. $way[] = [
  183. "name"=>"中金-支付宝",
  184. "img"=>"resources/img/payment/alipay.png",
  185. "pay_type"=>PayTypeEnum::SIC_PAY,
  186. "action"=>"sic_pay",
  187. "trade_type"=>self::ALIPAY_WAP
  188. ];
  189. }
  190. // 微信
  191. if(in_array(self::H5,$this->wechat)){
  192. $way[] = [
  193. "name"=>"中金-微信",
  194. "img"=>"resources/img/payment/wechat.png",
  195. "pay_type"=>PayTypeEnum::SIC_PAY,
  196. "action"=>"sic_pay",
  197. "trade_type"=>self::WECHAT_WAP
  198. ];
  199. }
  200. // 银联
  201. if(in_array(self::H5,$this->bank)){
  202. $way[] = [
  203. "name"=>"中金-在线银联",
  204. "img"=>"resources/img/payment/joinpay_fast.png",
  205. "pay_type"=>PayTypeEnum::SIC_PAY,
  206. "action"=>"sic_pay",
  207. "trade_type"=>self::CLOUD_H5,
  208. ];
  209. }
  210. return $way;
  211. }
  212. // 获取小程序支付渠道
  213. public function _get_mp_way(){
  214. $way = [];
  215. // 支付宝
  216. if(in_array(self::MP,$this->alipay)){
  217. $way[] = [
  218. "name"=>"中金-支付宝",
  219. "img"=>"resources/img/payment/alipay.png",
  220. "pay_type"=>PayTypeEnum::SIC_PAY,
  221. "action"=>"sic_pay",
  222. "trade_type"=>self::ALIPAY_MP,
  223. ];
  224. }
  225. // 微信
  226. if(in_array(self::MP,$this->wechat)){
  227. $way[] = [
  228. "name"=>"中金-微信",
  229. "img"=>"resources/img/payment/wechat.png",
  230. "pay_type"=>PayTypeEnum::SIC_PAY,
  231. "action"=>"sic_pay",
  232. "trade_type"=>self::WECHAT_MP,
  233. ];
  234. }
  235. return $way;
  236. }
  237. // 获取公众号支付
  238. public function _get_wechat_way(){
  239. $way = [];
  240. // 微信
  241. if(in_array(self::WECHAT,$this->wechat)){
  242. $way[] = [
  243. "name"=>"中金-微信",
  244. "img"=>"resources/img/payment/wechat.png",
  245. "pay_type"=>PayTypeEnum::SIC_PAY,
  246. "action"=>"sic_pay",
  247. "trade_type"=>self::WECHAT_GZH,
  248. ];
  249. }
  250. // 银联
  251. if(in_array(self::H5,$this->bank)){
  252. $way[] = [
  253. "name"=>"中金-在线银联",
  254. "img"=>"resources/img/payment/joinpay_fast.png",
  255. "pay_type"=>PayTypeEnum::SIC_PAY,
  256. "action"=>"sic_pay",
  257. "trade_type"=>self::CLOUD_H5,
  258. ];
  259. }
  260. return $way;
  261. }
  262. public static function getTypeText(){
  263. $list = [];
  264. foreach (self::$type_text as $key=>$val){
  265. $list[] = [
  266. 'label'=>$val,
  267. 'value'=>$key,
  268. ];
  269. }
  270. return $list;
  271. }
  272. }