SicpayOrder.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace addons\Sicpay\common\models;
  3. use common\models\base\BaseActiveRecord;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_sicpay_order}}".
  7. *
  8. * @property int $id
  9. * @property int|null $mall_id
  10. * @property string|null $order_no
  11. * @property int|null $agencyId 商户号
  12. * @property float|null $amount
  13. * @property string|null $product_name
  14. * @property string $pay_result 1⽀付成功,0未⽀付,2⽀付失败,6已关闭
  15. * @property string|null $pay_time
  16. * @property int $created_at
  17. * @property int $updated_at
  18. * @property string|null $token_id
  19. * @property string|null $response_json
  20. * @property string|null $request_json
  21. * @property string|null $pay_no
  22. * @property string|null $mall_order_no
  23. * @property string $type
  24. */
  25. class SicpayOrder extends BaseActiveRecord
  26. {
  27. const PAY_SUCCESS = 1;
  28. const PAY_FAIL = 2;
  29. const PAY_WAIT = 0;
  30. const PAY_CLOSE = 6;
  31. public static $pay_text = [
  32. self::PAY_SUCCESS => "支付成功",
  33. self::PAY_FAIL => "支付失败",
  34. self::PAY_WAIT => "待支付",
  35. self::PAY_CLOSE => "交易关闭",
  36. ];
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public static function tableName()
  41. {
  42. return '{{%addons_sicpay_order}}';
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function rules()
  48. {
  49. return [
  50. [['mall_id', 'agencyId', 'created_at', 'updated_at'], 'integer'],
  51. [['amount'], 'number'],
  52. [['order_no','amount'], 'required'],
  53. [['pay_time','pay_result','type'], 'safe'],
  54. [['response_json', 'request_json'], 'string'],
  55. [['order_no','pay_no','agencyId','mall_order_no'], 'string', 'max' => 64],
  56. [['type'], 'string', 'max' => 32],
  57. [['product_name', 'token_id'], 'string', 'max' => 255],
  58. [['pay_result'], 'string', 'max' => 4],
  59. ];
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function attributeLabels()
  65. {
  66. return [
  67. 'id' => 'ID',
  68. 'mall_id' => 'Mall ID',
  69. 'mall_order_no' => 'Mall ID',
  70. 'order_no' => 'Order No',
  71. 'pay_no' => 'Order No',
  72. 'agencyId' => '商户号',
  73. 'amount' => 'Amount',
  74. 'product_name' => 'Product Name',
  75. 'pay_result' => '1⽀付成功,0未⽀付,2⽀付失败,6已关闭',
  76. 'pay_time' => 'Pay Time',
  77. 'created_at' => 'Created At',
  78. 'updated_at' => 'Updated At',
  79. 'token_id' => 'Token ID',
  80. 'response_json' => 'Response Json',
  81. 'request_json' => 'Request Json',
  82. ];
  83. }
  84. /**
  85. * 支付成功
  86. * @param $pay_no 支付单号
  87. * @param $pay_time 支付时间
  88. */
  89. public static function pay_success($order_id,$pay_no,$pay_time,$resp = []){
  90. $update = [
  91. 'pay_result'=>self::PAY_SUCCESS,
  92. 'pay_no'=>$pay_no,
  93. 'pay_time'=>$pay_time,
  94. 'updated_at'=>time()
  95. ];
  96. if(!empty($resp)){
  97. $update['response_json'] = json_encode($resp);
  98. }
  99. return self::updateAll($update,['id'=>$order_id]);
  100. }
  101. public static function pay_fail($order_id,$err_msg,$resp = []){
  102. $update = [
  103. 'pay_result'=>self::PAY_FAIL,
  104. 'err_msg'=>$err_msg,
  105. 'updated_at'=>time()
  106. ];
  107. if(!empty($resp)){
  108. $update['response_json'] = json_encode($resp);
  109. }
  110. return self::updateAll($update,['id'=>$order_id]);
  111. }
  112. public static function pay_close($order_id,$err_msg,$resp = []){
  113. $update = [
  114. 'pay_result'=>self::PAY_CLOSE,
  115. 'err_msg'=>$err_msg,
  116. 'updated_at'=>time()
  117. ];
  118. if(!empty($resp)){
  119. $update['response_json'] = json_encode($resp);
  120. }
  121. return self::updateAll($update,['id'=>$order_id]);
  122. }
  123. public static function getPayText(){
  124. $list = [];
  125. foreach (self::$pay_text as $key=>$val){
  126. $list[] = [
  127. 'label'=>$val,
  128. 'value'=>$key,
  129. ];
  130. }
  131. return $list;
  132. }
  133. }