'商品下架', 'goods.on.sale' => '商品上架', 'goods.alter' => '商品修改', 'goods.price.alter' => '商品价格变更', 'goods.storage.add' => '商品库添加', 'goods.storage.delete' => '商品库删除', 'goods.storage.remove' => '移除商品库商品', 'order.success' => '订单交易成功', 'order.delivered' => '商品已收货', 'order.delivery' => '商家已发货', 'order.cancel' => '订单取消', 'aftersale.agree' => '售后同意', 'aftersale.refuse' => '拒绝', 'aftersale.success' => '退款到账', ]; public static $event_name = [ self::GOODS_UNDERCARRIAGE => '商品下架', self::GOODS_ON_SALE => '商品上架', self::GOODS_ALTER=> '商品修改', self::GOODS_PRICE_ALTER => '商品价格变更', self::GOODS_STORAGE_ADD => '商品库添加', self::GOODS_STORAGE_DELETE => '商品库删除', self::GOODS_STORAGE_REMOVE => '移除商品库商品', self::ORDER_SUCCESS => '订单交易成功', self::ORDER_DELIVERED => '商品已收货', self::ORDER_DELIVERY => '商家已发货', self::ORDER_CANCEL => '订单取消', self::AFTERSALE_AGREE => '售后', self::AFTERSALE_REFUSE => '拒绝', self::AFTERSALE_SUCCESS => '退款到账', ]; public static $handler_type = [ self::HANDLER_GOODS => [ self::GOODS_UNDERCARRIAGE, self::GOODS_ON_SALE, self::GOODS_ALTER, self::GOODS_PRICE_ALTER , self::GOODS_STORAGE_ADD , self::GOODS_STORAGE_DELETE , self::GOODS_STORAGE_REMOVE , ], self::HANDLER_ORDER => [ self::ORDER_SUCCESS, self::ORDER_DELIVERED, self::ORDER_DELIVERY, self::ORDER_CANCEL, ], self::HANDLER_AFTERSALE => [ self::AFTERSALE_AGREE, self::AFTERSALE_REFUSE, self::AFTERSALE_SUCCESS, ] ]; /** * @var array */ public static $handler_class = [ self::HANDLER_GOODS => [ 'key' => 'juhe_goods_id', 'field' => 'goodsIds', 'class' => GoodsSkuModel::class, ], self::HANDLER_ORDER => [ 'key' => 'order_no', 'field' => 'orderSn', 'class' => MallOrderModel::class, ], self::HANDLER_AFTERSALE => [ 'key' => 'order_no', 'field' => 'orderSn', 'class' => MallOrderModel::class, ], ]; /** * {@inheritdoc} */ public static function tableName() { return '{{%addons_qijuhe_notice}}'; } /** * {@inheritdoc} */ public function rules() { return [ [['mall_id', 'created_at', 'updated_at', 'response_time', 'supply_id'], 'integer'], [['data', 'response'], 'string'], [['type', 'push_time'], 'string', 'max' => 64], [['notice_id'], 'string', 'max' => 225], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'supply_id' => 'Supply id', 'notice_id' => 'Notice ID', 'type' => 'Type', 'push_time' => 'Push Time', 'data' => 'Data', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'response' => 'Response', 'response_time' => 'Response Time', ]; } /** * 获取Handler * * @param string $type * @return string */ public function getHandler($type) { foreach (self::$handler_type as $handler => $handler_type) { if (in_array($type, $handler_type)) { return $handler; } } return false; } /** * 获取推送相关的mall_ids * * @param string $handler * @param array $data * @return array */ public function getMallIds($handler, $data) { $handler = $this->getHandler($handler); $class = self::$handler_class[$handler]; switch ($handler) { // 订单 case self::HANDLER_GOODS: $ids = GoodsSkuModel::find() ->alias('sku') ->leftJoin(['goods' => GoodsModel::tableName()], 'goods.id = sku.juhe_goods_id') ->andWhere(['goods.juhe_goods_id' => $data[$class['field']]]) ->select('sku.mall_id') ->groupBy('sku.mall_id') ->all(); break; default: $ids = $class['class']::find() ->select('mall_id') ->where([$class['key'] => $data[$class['field']]]) ->groupBy('mall_id') ->select('mall_id') ->all(); break; } $mall_ids = []; foreach ($ids as $v) { $mall_ids[] = $v['mall_id']; } return $mall_ids; } /** * 添加日志 * * @param array $data * @return integer */ public static function addLog($type,$data) { $model = new self(); // $data['response'] = Json::encode($data['response']); $log = $data; unset($log['message_id'],$log['notice_id']); $data['data'] = Json::encode($log); $data['type'] = $type; $data['created_at'] = $data['updated_at'] = time(); $model->load($data, ''); $model->save(false); return $model->id; } }