'微信', 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; } }