255], [['address', 'remark'], 'string', 'max' => 1000], [['adapay_payment_id'], 'safe'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'share_user_first_id' => 'share_user_first_id', 'share_user_second_id' => 'share_user_second_id', 'share_user_third_id' => 'share_user_third_id', 'is_share' => 'ID', 'store_id' => 'Store ID', 'user_id' => '用户id', 'order_no' => '订单号', 'total_price' => '订单总费用(包含运费)', 'pay_price' => '实际支付总费用(含运费)', 'express_price' => '运费', 'send_price' => '赠送用户金额', 'take_price' => '扣除用户联盟券抵扣金额', 'first_share_price' => '一级分销', 'second_share_price' => '二级分销', 'third_share_price' => '三级分销', 'name' => '收货人姓名', 'mobile' => '收货人手机', 'address' => '收货地址', 'remark' => '订单备注', 'is_pay' => '支付状态:0=未支付,1=已支付', 'pay_type' => '支付方式:1=微信支付', 'pay_time' => '支付时间', 'send_time' => '发货时间', 'express' => '物流公司', 'express_no' => 'Express No', 'confirm_time' => '确认收货时间', 'is_comment' => '是否已评价:0=未评价,1=已评价', 'apply_delete' => '是否申请取消订单:0=否,1=申请取消订单', 'created_at' => 'Addtime', 'is_delete' => 'Is Delete', 'is_price' => '是否发放佣金', 'parent_id' => '用户上级ID', 'first_price' => '一级佣金', 'second_price' => '二级佣金', 'third_price' => '三级佣金', 'coupon_sub_price' => '优惠券抵消金额', 'content' => 'Content', 'is_offline' => '是否到店自提 0--否 1--是', 'clerk_id' => '核销员user_id', 'address_data' => '收货地址信息,json格式', 'offline_qrcode' => '核销码', 'before_update_price' => '修改前的价格', 'shop_id' => '自提自提点ID', 'discount' => '会员折扣', 'user_coupon_id' => '使用的优惠券ID', 'integral' => '积分使用', 'give_integral' => '是否发放积分【1=> 已发放 , 0=> 未发放】', 'parent_id_1' => '用户上二级ID', 'parent_id_2' => '用户上三级ID', 'is_sale' => '是否超过售后时间', 'words' => '商家留言', 'version' => '版本', 'express_price_1' => '减免的运费', 'mch_id' => '入驻商户id', 'seller_comments' => '商家备注', 'order_union_id' => '合并订单的id', 'rebate' => '自购返利', 'before_update_express' => '价格修改前的运费', 'is_transfer' => '是否已转入商户账户:0=否,1=是', 'type' => '0普通订单1卡券兑换订单', 'share_price' => '发放佣金的金额', 'is_show' => '是否显示 0--不显示 1--显示(软删除用)', 'order_origin' => '订单来源 1:公众号或者网站 2:app 3:小程序', 'is_open_offline' => '是否是线下购物车下的订单', 'trade_status' => '订单状态,-1:默认,0:待发货,1:已取消,2:已发货,3:已确认', 'is_use_platform_mch' => '供应链系统下单时是否使用平台商户号,1使用,0未使用', 'transaction_id' => '微信商户号' ]; } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub if (intval($this->attributes['is_pay'])) { self::send_user_integral($this); } } public function getOrderDetail() { return $this->hasMany(OrderDetail::className(), ['order_id' => 'id'])->alias('od') ->leftJoin(['g' => Goods::tableName()], 'g.id=od.goods_id')->select(['od.*', 'g.name', 'g.attr goods_attr', 'g.cost_price']); } public function getDetail() { return $this->hasMany(OrderDetail::className(), ['order_id' => 'id']); } public function getGoods() { return $this->hasMany(Goods::className(), ['id' => 'goods_id'])->alias('g') ->viaTable(OrderDetail::tableName() . ' od', ['order_id' => 'id']); } public function getShop() { return $this->hasOne(Shop::className(), ['id' => 'shop_id']); } public function getClerk() { return $this->hasOne(User::className(), ['id' => 'clerk_id']); } public function getOrderForm() { return $this->hasMany(OrderForm::className(), ['order_id' => 'id'])->where(['is_delete' => 0]); } public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); } public function getRefund() { return $this->hasMany(OrderRefund::className(), ['order_id' => 'id']); } public function beforeSave($insert) { $this->content = \yii\helpers\Html::encode($this->content); return parent::beforeSave($insert); } public function getPondDetail() { return $this->hasOne(OrderDetail::className(), ['order_id' => 'id']); } public function getPondGoods() { return $this->hasOne(Goods::className(), ['id' => 'goods_id'])->alias('g') ->viaTable(OrderDetail::tableName() . ' od', ['order_id' => 'id']); } //发放积分 public static function send_user_integral($order) { debug_log(['发放积分'], 'send_user_integral.log'); try { $face_send_integral_profit = Option::get('face_send_integral_profit', $order->store_id, 'store', '0')['value']; debug_log(['face_send_integral_profit' => $face_send_integral_profit, 'store_id' => $order->store_id], 'send_user_integral.log'); if ($face_send_integral_profit <= 0) { throw new \Exception(''); } $user_id = $order->user_id; debug_log(['user_id' => $user_id], 'send_user_integral.log'); if ($user_id) { $total_price = $order->total_price; debug_log(['total_price' => $total_price], 'send_user_integral.log'); $integral = bcdiv(bcmul($total_price, $face_send_integral_profit, 2), 100, 2); AccountLog::saveLog($user_id, $integral, AccountLog::TYPE_INTEGRAL, AccountLog::LOG_TYPE_INCOME, AccountLog::ORDER_TYPE_FACE_PAY, $order->id, "商城当面付订单营销赠送积分, 订单号:{$order->order_no}"); return [ 'code' => 0, 'msg' => '发送成功' ]; } return [ 'code' => 1, 'msg' => '用户未找到' ]; } catch (\Exception $e) { debug_log([ 'msg' => $e->getMessage(), 'line' => $e->getLine(), 'file' => $e->getFile() ], 'send_user_integral.log'); return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 统计一个时间段 入住商或者当面付订单的数量以及订单的金额 * @param $mchId * @param $startTime * @param $endTime * @return array|\yii\db\ActiveRecord|null * @author: hankaige * @Time: 2025/7/15 10:12 */ public static function getMchOrder($mchId = 0, $startTime = 0, $endTime = 0){ $query = self::find()->where(['mch_id' => $mchId,'is_pay' => self::IS_PAY_TRUE,'is_delete' => self::IS_DELETE_FALSE]); if($startTime > 0){ $query->andWhere(['>=','created_at',$startTime]); } if($endTime){ $query->andWhere(['<=','created_at',$endTime]); } return $query->select('count(id) AS order_num,SUM(total_price) as order_price')->asArray()->one(); } }