64], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'store_id' => 'Store ID', 'name' => 'Name', 'values' => 'Values', 'updated_at' => 'Updated At', 'created_at' => 'Created At', ]; } /** * 添加规格 * * @param integer $mall_id * @param string $name * @param array $values * @param integer $store_id * @return boolean */ public static function addGoodsSpecs(int $mall_id, string $name, array $values, int $store_id = 0) { $model = new static(); $model->mall_id = $mall_id; $model->store_id = $store_id; return $model->editSpecs($name, $values); } /** * ID获取规格 * * @param integer $mall_id * @param integer $id * @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]], */ public static function getSpecsById(int $mall_id, int $id) { return static::find() ->where(['mall_id' => $mall_id, 'id' => $id]) ->one(); } /** * 修改规格 * * @param string $name * @param array $values * @return boolean */ public function editSpecs(string $name, array $values) { $this->name = $name; $this->values = Json::encode($values); return $this->save(); } /** * 获取分页数据 * * @param integer $page * @param integer $limit * @param callable $callback * @param string $order_by * @param callable|null $list_callback * @return array */ public static function getPageList( int $page, int $limit, callable $callback, string $order_by = 'id', $list_callback = null ) :array { $model = static::find(); if (!empty($callback)) call_user_func($callback, $model); $pagination = new Pagination(['totalCount' => $model->count(), 'pageSize' => $limit]); $model->limit($pagination->limit)->offset($pagination->offset); $list = $model->asArray()->orderBy($order_by)->all(); // list处理 if (!empty($list_callback)) $list = call_user_func($list_callback, $list); $data['list'] = $list; $data['page_count'] = $pagination->pageCount; $data['current_page'] = $page + 1; return $data; } }