| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace addons\Sicpay\common\models;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "{{%addons_sicpay_order}}".
- *
- * @property int $id
- * @property int|null $mall_id
- * @property string|null $order_no
- * @property int|null $agencyId 商户号
- * @property float|null $amount
- * @property string|null $product_name
- * @property string $pay_result 1⽀付成功,0未⽀付,2⽀付失败,6已关闭
- * @property string|null $pay_time
- * @property int $created_at
- * @property int $updated_at
- * @property string|null $token_id
- * @property string|null $response_json
- * @property string|null $request_json
- * @property string|null $pay_no
- * @property string|null $mall_order_no
- * @property string $type
- */
- class SicpayOrder extends BaseActiveRecord
- {
- const PAY_SUCCESS = 1;
- const PAY_FAIL = 2;
- const PAY_WAIT = 0;
- const PAY_CLOSE = 6;
- public static $pay_text = [
- self::PAY_SUCCESS => "支付成功",
- self::PAY_FAIL => "支付失败",
- self::PAY_WAIT => "待支付",
- self::PAY_CLOSE => "交易关闭",
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_sicpay_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'agencyId', 'created_at', 'updated_at'], 'integer'],
- [['amount'], 'number'],
- [['order_no','amount'], 'required'],
- [['pay_time','pay_result','type'], 'safe'],
- [['response_json', 'request_json'], 'string'],
- [['order_no','pay_no','agencyId','mall_order_no'], 'string', 'max' => 64],
- [['type'], 'string', 'max' => 32],
- [['product_name', 'token_id'], 'string', 'max' => 255],
- [['pay_result'], 'string', 'max' => 4],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'mall_order_no' => 'Mall ID',
- 'order_no' => 'Order No',
- 'pay_no' => 'Order No',
- 'agencyId' => '商户号',
- 'amount' => 'Amount',
- 'product_name' => 'Product Name',
- 'pay_result' => '1⽀付成功,0未⽀付,2⽀付失败,6已关闭',
- 'pay_time' => 'Pay Time',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'token_id' => 'Token ID',
- 'response_json' => 'Response Json',
- 'request_json' => 'Request Json',
- ];
- }
- /**
- * 支付成功
- * @param $pay_no 支付单号
- * @param $pay_time 支付时间
- */
- public static function pay_success($order_id,$pay_no,$pay_time,$resp = []){
- $update = [
- 'pay_result'=>self::PAY_SUCCESS,
- 'pay_no'=>$pay_no,
- 'pay_time'=>$pay_time,
- 'updated_at'=>time()
- ];
- if(!empty($resp)){
- $update['response_json'] = json_encode($resp);
- }
- return self::updateAll($update,['id'=>$order_id]);
- }
- public static function pay_fail($order_id,$err_msg,$resp = []){
- $update = [
- 'pay_result'=>self::PAY_FAIL,
- 'err_msg'=>$err_msg,
- 'updated_at'=>time()
- ];
- if(!empty($resp)){
- $update['response_json'] = json_encode($resp);
- }
- return self::updateAll($update,['id'=>$order_id]);
- }
- public static function pay_close($order_id,$err_msg,$resp = []){
- $update = [
- 'pay_result'=>self::PAY_CLOSE,
- 'err_msg'=>$err_msg,
- 'updated_at'=>time()
- ];
- if(!empty($resp)){
- $update['response_json'] = json_encode($resp);
- }
- return self::updateAll($update,['id'=>$order_id]);
- }
- public static function getPayText(){
- $list = [];
- foreach (self::$pay_text as $key=>$val){
- $list[] = [
- 'label'=>$val,
- 'value'=>$key,
- ];
- }
- return $list;
- }
- }
|