'商城ID', 'goods_id' => '商品ID', 'reflux_amount' => '回流奖金池金额', 'integral_amount' => '增值积分金额', 'id' => 'ID', 'ids' => 'ID', ]; } /** * 保存 */ public function save() { try { $id = $this->id; $goods_id = $this->goods_id; $store_id = $this->store_id; $reflux_amount = $this->reflux_amount; $integral_amount = $this->integral_amount; $goods = Goods::findOne(['id' => $goods_id, 'is_delete' => 0, 'store_id' => $store_id]); if (!$goods) { throw new \Exception('商品不存在'); } if ($reflux_amount <= 0) { throw new \Exception('回流奖金池金额必须大于0'); } // if ($integral_amount <= 0) { // throw new \Exception('增值积分金额必须大于0'); // } if ($id) { $model = IntegralAppreciationGoods::findOne(['id' => $id, 'is_delete' => 0]); } else { $model = IntegralAppreciationGoods::findOne(['goods_id' => $goods_id, 'is_delete' => 0]); if ($model) { throw new \Exception('该商品已存在'); } $model = new IntegralAppreciationGoods(); $model->store_id = $store_id; } $model->goods_id = $goods_id; $model->reflux_amount = $reflux_amount; $model->integral_amount = $integral_amount; if (!$model->save()) { throw new \Exception(implode(',', $model->getFirstErrors())); } return [ 'code' => 0, 'msg' => '保存成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } /** * 列表 */ public function getList() { $goods_name = $this->goods_name; $start_time = $this->start_time; $end_time = $this->end_time; $store_id = $this->store_id; $query = IntegralAppreciationGoods::find()->alias('ig') ->leftJoin(['g' => Goods::tableName()], 'ig.goods_id = g.id') ->where(['ig.is_delete' => 0, 'g.is_delete' => 0, 'ig.store_id' => $store_id]); if ($goods_name) { $query->andWhere(['like', 'g.name', $goods_name]); } if ($start_time) { $start_time = strtotime($start_time); $query->andWhere(['>=', 'ig.created_at', $start_time]); } if ($end_time) { $end_time = strtotime($end_time); $query->andWhere(['<=', 'ig.created_at', $end_time]); } $query->orderBy('ig.id DESC') ->select('ig.id, ig.goods_id, ig.reflux_amount, ig.integral_amount, ig.created_at, g.name, g.cover_pic, g.price'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); } return [ 'code' => 0, 'msg' => '', 'data' => $list ]; } /** * 删除 / 批量 */ public function del() { try { $ids = $this->ids; $ids = explode(',', $ids); if (!$ids) { throw new \Exception('请选择要删除的项'); } foreach ($ids as $id) { $goods = IntegralAppreciationGoods::findOne($id); $goods->is_delete = 1; if (!$goods->save()) { throw new \Exception(implode(',', $goods->getFirstErrors())); } } return [ 'code' => 0, 'msg' => '删除成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }