| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace addons\Alitopay\common\models;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "{{%addons_atp_order}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string|null $batch_sn 批次号
- * @property string|null $order_sn 订单号
- * @property string|null $account 收款人
- * @property string|null $name 姓名
- * @property int $type 1提现打款2手动转账
- * @property float $money 打款金额
- * @property int $status 1待打款2打款中3打款成功4打款失败5打款超时
- * @property int $is_delete 是否删除
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- * @property int $source_id 来源ID
- * @property string $source_sn 来源单号
- * @property string $form_html
- * @property string $msg
- * @property string $order_id
- * @property string $file_id
- * @property string $download_url
- */
- class Order extends BaseActiveRecord
- {
- const TYPE_WITHDRAWAL = 1;
- const TYPE_MANUAL = 2;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_atp_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['type', 'status','mall_id', 'is_delete', 'created_at', 'updated_at', 'source_id'], 'integer'],
- [['money'], 'number'],
- [['batch_sn', 'order_sn'], 'string', 'max' => 64],
- [['source_sn','name','account'], 'string', 'max' => 32],
- [['order_id'], 'string', 'max' => 255],
- [['file_id'], 'string', 'max' => 200],
- [['download_url'], 'string', 'max' => 1000],
- [['form_html','msg'],"safe"]
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'ID',
- 'batch_sn' => '批次号',
- 'order_sn' => '订单号',
- 'type' => '1提现打款2手动转账',
- 'money' => '打款金额',
- 'status' => '1待打款2打款中3打款成功4打款失败5打款超时',
- 'is_delete' => '是否删除',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'source_id' => '来源ID',
- 'source_sn' => '来源单号',
- 'msg' => '来源单号',
- 'order_id' => '支付宝转账单据号',
- 'file_id' => '文件申请号file_id信息',
- 'download_url' => '电子回单下载url',
- ];
- }
- /**
- * 批量插入
- *
- * @param array $insert_data
- * @return int
- */
- public static function batchInsert(array $insert_data)
- {
- return \Yii::$app->db
- ->createCommand()
- ->batchInsert(static::tableName(), array_keys($insert_data[0]), $insert_data)
- ->execute();
- }
- /**
- * 打款成功
- *
- * @param integer $source_id
- * @param string $order_sn
- * @return void
- */
- public static function paySuccessBySourceIdAndOrderSn(
- int $source_id,
- string $order_sn,
- string $order_id,
- string $msg = '成功'
- )
- {
- static::updateAll(
- ['status' => 3, 'updated_at' => time(), 'msg' => $msg,'order_id'=>$order_id],
- ['source_id' => $source_id, 'order_sn' => $order_sn]
- );
- // 打款成功
- $cash = WithdrawLog::getLogById($source_id);
- WithdrawLog::remit_success($cash);
- }
- /**
- * 打款失败
- *
- * @param integer $source_id
- * @param string $order_sn
- * @param string $msg
- * @return void
- */
- public static function payFialBySourceIdAndOrderSn(
- int $source_id,
- string $order_sn,
- string $msg = ''
- )
- {
- static::updateAll(
- ['status' => 4, 'updated_at' => time(), 'msg' => $msg],
- ['source_id' => $source_id, 'order_sn' => $order_sn]
- );
- // 打款失败
- $cash = WithdrawLog::getLogById($source_id);
- WithdrawLog::remit_fail($cash, $msg);
- }
- /**
- * 给这批提现订单设置一个批次号
- *
- * @param string $batch_no
- * @param array $order_sns
- * @return int
- */
- public static function setOutBatchNoByOrderSn(string $batch_no, array $order_sns)
- {
- return static::updateAll(
- ['batch_sn' => $batch_no],
- ['order_sn' => $order_sns]
- );
- }
- }
|