| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- namespace addons\YunfastPay\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_yunfast_pay_agent_order}}".
- *
- * @property int $id
- * @property int $mall_id mall_id
- * @property int $user_id 会员ID
- * @property int $type 1 提现订单 2 门店打款订单
- * @property int $withdraw_id 提现ID
- * @property string $order_no 订单号
- * @property float $trans_amount 交易金额
- * @property string $acct_number 收款卡号
- * @property string $acct_name 收款户名
- * @property int $acct_type 账户类型 1:对私 2:对公
- * @property string|null $req_data 请求参数
- * @property string|null $res_data 返回参数
- * @property string $status 100-支付成功(支付订单)或退款成功(退款订单) 101-待支付 102-支付失败(支付订单)或退款失败(退款订单) 103-订单处理中 104-已撤销
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class AgentOrder extends ActiveRecord
- {
- protected static $json_fields = [
- 'req_data', 'res_data'
- ];
-
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_yunfast_pay_agent_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'type', 'withdraw_id', 'acct_type', 'created_at', 'updated_at'], 'integer'],
- [['order_no', 'trans_amount'], 'required'],
- [['trans_amount'], 'number'],
- [['req_data', 'res_data'], 'string'],
- [['order_no'], 'string', 'max' => 32],
- [['acct_number', 'acct_name'], 'string', 'max' => 64],
- [['status'], 'string', 'max' => 5],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'type' => 'Type',
- 'withdraw_id' => 'Withdraw ID',
- 'order_no' => 'Order No',
- 'trans_amount' => 'Trans Amount',
- 'acct_number' => 'Acct Number',
- 'acct_name' => 'Acct Name',
- 'acct_type' => 'Acct Type',
- 'req_data' => 'Req Data',
- 'res_data' => 'Res Data',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id', 'mall_id' => 'mall_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getWithdrawLog()
- {
- return $this->hasOne(WithdrawLog::class, ['id' => 'withdraw_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getSplitbillLog()
- {
- return $this->hasOne(SplitbillItem::class, ['id' => 'withdraw_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getStore()
- {
- return $this->hasOne(Store::class, ['id' => 'user_id', 'mall_id' => 'mall_id']);
- }
- /**
- * @param integer $mall_id
- * @param string $order_no
- * @return static
- */
- public static function getOrderByNo(int $mall_id, string $order_no)
- {
- return static::find()
- ->where(['mall_id' => $mall_id, 'order_no' => $order_no])
- ->one();
- }
-
- /**
- * 修改状态为已审核
- *
- * @return void
- */
- public function agree(WithdrawLog $log, string $msg = '', $status = '102', array $notify_data = [])
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- $this->status = $status;
- $this->notify_data = json_encode($notify_data);
- $this->save();
-
- WithdrawLog::remit_fail($log, $msg);
- $t->commit();
- return true;
- } catch (\Exception $e) {
- $t->rollBack();
- return false;
- }
- }
- /**
- * 门店
- *
- * @param string $status
- * @return void
- */
- public function failByStore($status = '102', array $notify_data = [])
- {
- $this->status = $status;
- $this->notify_data = json_encode($notify_data);
- return $this->save();
- }
- /**
- * @param string $status
- * @return void
- */
- public function success(WithdrawLog $log, $status = '100', array $notify_data = [])
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- $this->status = $status;
- $this->notify_data = json_encode($notify_data);
- $this->save();
- WithdrawLog::remit_success($log);
- $t->commit();
- return true;
- } catch (\Exception $e) {
- $t->rollBack();
- return false;
- }
- }
- /**
- * 门店
- *
- * @param string $status
- * @return void
- */
- public function successByStore($status = '100', array $notify_data = [])
- {
- $this->status = $status;
- $this->notify_data = json_encode($notify_data);
- return $this->save();
- }
- }
|