| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%order_pay_offline}}".
- *
- * @property integer $id
- */
- class OrderPayOffline extends \yii\db\ActiveRecord
- {
-
- const PAY_TYPE_OFFLINE_WECHAT = 1;
- const PAY_TYPE_OFFLINE_ALIPAY = 2;
- const PAY_TYPE_OFFLINE_BANK = 3;
-
- public static $type = [
- self::PAY_TYPE_OFFLINE_WECHAT => '微信',
- self::PAY_TYPE_OFFLINE_ALIPAY => '支付宝',
- self::PAY_TYPE_OFFLINE_BANK => '银行卡',
- ];
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%order_pay_offline}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
-
- public static function addPay($store_id, $user_id, $order_id, $type, $desc, $pic_list = []) {
- try{
- if(!in_array($type, array_keys(self::$type))){
- throw new \Exception('操作失败,渠道类型不符');
- }
- $order = Order::findOne($order_id);
- if($order->is_pay == 1){
- throw new \Exception('操作失败,订单状态不符');
- }
- if($order->user_id != $user_id){
- throw new \Exception('操作失败,用户信息不符');
- }
- $model = self::find()->where(['store_id' => $store_id, 'order_id' => $order_id, 'is_delete' => 0])->orderBy('id DESC')->one();
- if($model && $model->status != 2){
- throw new \Exception('操作失败,支付状态不符');
- }
- if(!$model){
- $model = new self();
- $model->store_id = $store_id;
- $model->order_id = $order_id;
- }
- $model->add_at = time();
- $model->status = 0;
- $model->audit_at = 0;
- $model->admin_remark = '';
- $model->type = $type;
- $model->desc = $desc;
- $model->pic_list = json_encode($pic_list);
- if(!$model->save()){
- throw new \Exception('操作失败,' . array_shift($model->getFirstErrors()));
- }
- } catch (\Exception $ex) {
- \Yii::error($ex);
- return [
- 'code' => 1,
- 'msg' => $ex->getMessage(),
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功',
- 'data' => $model,
- ];
- }
-
- public static function auditPay($store_id, $id, $status, $admin_remark = '') {
- $t = \Yii::$app->db->beginTransaction();
- try{
- $model = self::findOne($id);
- if($model->store_id != $store_id){
- throw new \Exception('操作失败,店铺信息错误');
- }
- if($model->status == 1){
- throw new \Exception('操作失败,订单状态不符');
- }
- $model->status = $status;
- $model->audit_at = time();
- if($admin_remark){
- $model->admin_remark = $admin_remark;
- }
- if(!$model->save()){
- throw new \Exception('操作失败,' . array_shift($model->getFirstErrors()));
- }
- if($status == 1){
- $order = Order::findOne($model->order_id);
- $order->pay_time = time();
- $order->is_pay = 1;
- $order->pay_type = Order::PAY_TYPE_OFFLINE;
- $order->trade_status = Order::ORDER_FLOW_NO_SEND;
- if (!$order->save()) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '订单保存失败'
- ];
- }
- (new \app\modules\client\models\v1\order\OrderPayDataForm())->setReturnData($order);
- (new \app\modules\common\models\NotifyForm())->videoGoodsShare($order);
- // 支付完成后,相关操作
- $form = new \app\modules\client\models\OrderComplete();
- $form->order_id = $order->id;
- $form->order_type = 0;
- $form->store_id = $model->store_id;
- $form->notify();
- }
- $t->commit();
- } catch (\Exception $ex) {
- $t->rollBack();
- \Yii::error($ex);
- return [
- 'code' => 1,
- 'msg' => $ex->getMessage(),
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功',
- 'data' => $model,
- ];
- }
-
- public static function delPay($store_id, $id) {
- $ids = explode(',', $id);
- if($ids){
- self::updateAll(['is_delete' => 1], [
- 'store_id' => $store_id,
- 'id' => $ids,
- ]);
- }
- }
-
- public static function getPayByOrderId($store_id, $order_id) {
- $model = self::find()->where(['store_id' => $store_id, 'order_id' => $order_id, 'is_delete' => 0])->orderBy('id DESC')->one();
- return $model;
- }
- }
|