| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- namespace addons\Store\common\models;
- use addons\Store\common\enums\StoreEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\order\Order;
- use common\models\user\User;
- use Yii;
- use Exception;
- /**
- * This is the model class for table "qimall_addons_store_order_detail".
- *
- * @property int $id 订单项ID
- * @property int $order_id 订单ID
- * @property int $main_order_detail_id 主商城订单详情ID
- * @property int $user_id 用户id
- * @property int $mall_id 商城ID
- * @property int $mch_id 多商户id
- * @property int $store_id 店铺ID
- * @property int $goods_id 商品ID
- * @property string $goods_name 商品名称
- * @property int $goods_attr_id 规格ID
- * @property string $goods_attr_name 规格名称
- * @property string $sign_id 规格ID标识
- * @property string|null $attr_groups_format 格式化规格组
- * @property float $price 商品价格
- * @property float $cost_price 商品成本价
- * @property float $original_goods_price 商品原本总价
- * @property float $goods_price 商品优惠后总价
- * @property int $num 购买数量
- * @property float $adjust_money 调整金额
- * @property string $pic_url 商品图片
- * @property int $marketing_id 促销ID
- * @property string $marketing_type 促销类型
- * @property int $order_type 订单类型
- * @property int $give_score 赠送积分数量
- * @property int $order_status 订单状态【0待付款 1待发货 2 已发货 3已收货 4已完成 -1申请售后 -2售后中 -3售后完成 -4 已关闭 -5撤销售后】
- * @property int $shipping_status 物流状态【1已发货 0待发货】
- * @property int $is_feedback 订单售后状态【0未售后 1售后中 2售后完成】
- * @property string $remark 备注
- * @property int $is_evaluate 是否评价 【0未评价 1已评价 2已追评】
- * @property float $refund_balance_money 订单退款余额
- * @property int $is_virtual 是否包含 虚拟商品 0 不包含 1 包含
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property string|null $extra_info 额外信息
- * @property int $created_at
- * @property int $updated_at
- */
- class StoreOrderDetail extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_order_detail}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['order_id', 'main_order_detail_id','user_id', 'mall_id', 'mch_id', 'store_id', 'goods_id', 'goods_attr_id', 'marketing_id', 'order_type', 'give_score', 'order_status', 'shipping_status', 'is_feedback', 'is_evaluate', 'is_virtual', 'status', 'created_at', 'updated_at'], 'integer'],
- [['attr_groups_format', 'extra_info'], 'string'],
- [['price', 'cost_price', 'original_goods_price', 'goods_price', 'adjust_money', 'refund_balance_money'], 'number'],
- [['goods_name', 'remark'], 'string', 'max' => 200],
- [['goods_attr_name', 'sign_id', 'pic_url'], 'string', 'max' => 255],
- [['marketing_type'], 'string', 'max' => 50],
- ['num', 'safe'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '订单项ID',
- 'order_id' => '订单ID',
- 'main_order_detail_id' => '主商城订单详情ID',
- 'user_id' => '用户id',
- 'mall_id' => '商城ID',
- 'mch_id' => '多商户id',
- 'store_id' => '店铺ID',
- 'goods_id' => '商品ID',
- 'goods_name' => '商品名称',
- 'goods_attr_id' => '规格ID',
- 'goods_attr_name' => '规格名称',
- 'sign_id' => '规格ID标识',
- 'attr_groups_format' => '格式化规格组',
- 'price' => '商品价格',
- 'cost_price' => '商品成本价',
- 'original_goods_price' => '商品原本总价',
- 'goods_price' => '商品优惠后总价',
- 'num' => '购买数量',
- 'adjust_money' => '调整金额',
- 'pic_url' => '商品图片',
- 'marketing_id' => '促销ID',
- 'marketing_type' => '促销类型',
- 'order_type' => '订单类型',
- 'give_score' => '赠送积分数量',
- 'order_status' => '订单状态【0待付款 1待发货 2 已发货 3已收货 4已完成 -1申请售后 -2售后中 -3售后完成 -4 已关闭 -5撤销售后】',
- 'shipping_status' => '物流状态【1已发货 0待发货】',
- 'is_feedback' => '订单售后状态【0未售后 1售后中 2售后完成】',
- 'remark' => '备注',
- 'is_evaluate' => '是否评价 【0未评价 1已评价 2已追评】',
- 'refund_balance_money' => '订单退款余额',
- 'is_virtual' => '是否包含 虚拟商品 0 不包含 1 包含',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'extra_info' => '额外信息',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public function getUser(){
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public function getOrder(){
- return $this->hasOne(StoreOrder::class, ['id' => 'order_id']);
- }
- public function getStore()
- {
- return $this->hasOne(Store::class, ['id' => 'store_id'])->select('id,shop_mobile,store_name,logo_img');
- }
- /**
- * 保存数据
- * @Author bing
- * @DateTime 2021-08-24 15:34:48
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param array $params
- * @return void
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED]]);
- if (empty($model)) throw new Exception('订单详情不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @name:
- * @msg: 获取订单详情列表
- * @param {array} $cond
- * @param {array} $with
- * @param {bool} $is_array
- * @param {string} $select
- * @param {*} $index
- * @return {*}
- */
- public static function getOrderDetails(array $cond = [], array $with = [], bool $is_array = true, string $select = '*', $index = '')
- {
- $default_cond = [['<>', 'status', StatusEnum::DELETE]];
- $cond = array_merge($default_cond, $cond);
- $query = self::find()->select($select);
- self::paramPack(['where' => $cond, 'with' => $with], $query);
- if (!empty($index)) $query->indexBy($index);
- $labels = $query->asArray($is_array)->all();
- return $labels;
- }
- /**
- * @name:
- * @msg: 获取订单售后数量
- * @param {*} $order_id
- * @return {*}
- */
- public static function getAfterSaleCountByOrderId($order_id)
- {
- return self::find()
- ->select(['count(id) as count'])
- ->where(['status' => StatusEnum::ENABLED])
- ->andWhere(['order_id' => $order_id])
- ->andWhere([ 'is_feedback'=> OrderStatusEnum::FEEDBACKING])
- ->scalar();
- }
- /**
- * 获取订单详情api接口内容
- * @Author: lun
- * @DateTime: 2022/5/11 0011 14:31
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $order
- */
- public static function getApiOrderDetail($order)
- {
- // 检测是否是o2o订单
- if ($order['order_source'] != StoreEnum::ADDONS_NAME) return [];
- // 获取订单内容
- $order_select = "id,take_code";
- $store_order = StoreOrder::find()->select($order_select)->where(['order_no' => $order['order_no']])->asArray()->one();
- // 获取店铺名称
- $store_select = "id,store_name,shop_mobile,longitude,latitude,province_id,city_id,district_id,address";
- $store = Store::find()->select($store_select)->where(['id' => $order['store_id']])->asArray()->one();
- $data = [
- 'store_name' => $store['store_name'],
- 'address' => $store['address'],
- 'longitude' => $store['longitude'],
- 'latitude' => $store['latitude'],
- 'shop_mobile' => $store['shop_mobile'],
- 'take_mobile' => $order['mobile'],
- 'take_code' => $store_order['take_code'],
- 'take_url' => 'oid='.$order['id'].'&take_code='.$store_order['take_code'],
- ];
- return ['Store' => $data];
- }
- //供公共调用
- public static function getCapitalLogList($params){
- if (!isset($params['list']) || !is_array($params['list'])) return [];
- $source_table_id_arr_by_store_order_detail = [];
- foreach ($params['list'] as $item) {
- if (strpos($item['source_table'],'store_order_detail')!==false) {
- $source_table_id_arr_by_store_order_detail[] = $item['source_table_id'];
- }
- }
- if(!empty($source_table_id_arr_by_store_order_detail)){
- $order_detail_arr = [];
- $cond = [];
- $cond['where'] = [['id' => $source_table_id_arr_by_store_order_detail]];
- $cond['with'] = ['user' => function ($query) {
- $query->select('id,nickname,avatar_url');
- }, 'order' => function ($query) {
- $query->select('id,order_no');
- }];
- $order_detail_list = StoreOrderDetail::lists($cond);
- if($order_detail_list){
- foreach ($order_detail_list as $value) {
- $order_detail_arr[$value['id']] = [
- 'goods_name' => $value['goods_name'],
- 'goods_price' => $value['goods_price'],
- 'created_at' => date('Y-m-d H:i:s', $value['created_at']),
- 'order_no' => $value['order']['order_no'],
- 'user_id' => $value['user']['id'],
- 'nickname' => $value['user']['nickname'],
- 'avatar_url' => $value['user']['avatar_url'],
- ];
- }
- }
- foreach ($params['list'] as &$item) {
- if (strpos($item['source_table'],'{{%addons_course_orders}}')!==false) {
- $item['user_id'] = '';
- $item['nickname'] = '';
- $item['avatar_url'] = '';
- $item['order_no'] = '';
- $item['created_at'] = '';
- $item['goods_price'] = '';
- $item['goods_name'] = '';
- if (!empty($order_detail_arr[$item['source_table_id']])) {
- $item['user_id'] = $order_detail_arr[$item['source_table_id']]['user_id'];
- $item['nickname'] = $order_detail_arr[$item['source_table_id']]['nickname'];
- $item['avatar_url'] = $order_detail_arr[$item['source_table_id']]['avatar_url'];
- $item['order_no'] = $order_detail_arr[$item['source_table_id']]['order_no'];
- $item['created_at'] = $order_detail_arr[$item['source_table_id']]['created_at'];
- $item['goods_price'] = $order_detail_arr[$item['source_table_id']]['goods_price'];
- $item['goods_name'] = $order_detail_arr[$item['source_table_id']]['goods_name'];
- }
- }
- }
- }
- return $params['list'];
- }
- public static function orderRefundSubmit($params)
- {
- if (empty($params['mall_id'])) return [];
- $mall_id = $params['mall_id'];
- if (empty($params['order_detail'])) return [];
- $order_detail = $params['order_detail'];
- // 订单ID
- $order_id = is_array($order_detail) ? $order_detail['order_id'] : $order_detail['order_id'];
- $main_order = Order::findOne(['id'=>$order_id]);
- if(empty($main_order)) return [];
- $store_order = StoreOrder::findOne(['order_no'=>$main_order['order_no']]);
- if(empty($store_order)) return [];
- $order_credit = StoreOrderCredit::find()
- ->where(['mall_id'=>$mall_id,'order_id'=>$store_order['id'],'type'=>1,'is_repayment'=>0])
- ->andWhere(['>','pay_time',0])
- ->one();
- if(empty($order_credit)) return [];
- $store_order_detail = StoreOrderDetail::findOne(['main_order_detail_id'=>$order_detail['id']]);
- if(empty($store_order_detail)) return [];
- $goods_id = $store_order_detail['goods_id'];
- $extra = json_decode($order_credit['extra'],true);
- if(!empty($extra[$goods_id]['credit_money'])){
- $order_detail['goods_price'] = bcsub($order_detail['goods_price'],$extra[$goods_id]['credit_money']);
- }
- return $order_detail;
- }
- }
|