asJson(AdoptGoodsForm::getList(get_params())); } /** * 修改商品库存 * @return \yii\web\Response */ public function actionSetAttrNum() { $form = new AdoptGoodsForm(); return $this->asJson($form->setAttrNum()); } /** * 编辑商品数据 */ public function actionSetAttribute() { $form = new AdoptGoodsForm(); return $this->asJson($form->setType()); } /** * 编辑商品数据 */ public function actionSetAttr() { $status = post_params('status', -1); $delivery_type = post_params('delivery_type', null); $md_id = get_md_id(); $goods_id = post_params('id'); $md_goods = MdGoods::findOne([ 'md_id' => $md_id, 'goods_id' => $goods_id ]); $is_new_record = false; if (!$md_goods) { $md_goods = new MdGoods(); $md_goods->md_id = $md_id; $md_goods->goods_id = $goods_id; $is_new_record = true; } $goods = Goods::findOne($goods_id); if ($status > -1) { if ($md_goods->goods_num <= 0 && $status == Goods::STATUS_NORMAL) { return $this->asJson(['code' => 1, 'msg' => '请先添加商品库存之后再进行上架操作']); } $md_goods->status = $status; if ($is_new_record) { $md_goods->attr = $goods->attr; $md_goods->virtual_sales = $goods->virtual_sales; $md_goods->price = $goods->price; $md_goods->delivery_type = Md::findOne(get_md_id())->self_delivery_type; $md_goods->goods_num = $goods->goods_num; } } if (isset($delivery_type)) { $md_goods->delivery_type = Json::encode($delivery_type); if ($is_new_record) { $md_goods->attr = $goods->attr; $md_goods->virtual_sales = $goods->virtual_sales; $md_goods->price = $goods->price; $md_goods->goods_num = $goods->goods_num; } } if ($md_goods->save()) { return $this->asJson(['code' => 0, 'msg' => '保存成功']); } else { return $this->asJson(['code' => 1, 'msg' => $md_goods->errors[0]]); } } /** * 修改商品状态 * @return \yii\web\Response */ public function actionStatus() { $goods = Goods::findOne(get_params('id')); if (empty($goods)) { return $this->asJson([ 'code' => 1, 'msg' => '查无此商品' ]); } $type = get_params('type','status'); if ($goods->product_type == Goods::GOODS_TYPE_NORMAL) { if ($type == 'status' && empty($goods->goods_num) && $goods->status == 0) { return $this->asJson([ 'code' => 1, 'msg' => '请添加库存' ]); } } $value = get_params('value',-1); $goods->$type = $value == -1 ? ($goods->$type ? 0 : 1) : $value; if ($goods->save()) { return $this->asJson([ 'code' => 0, 'msg' => '编辑成功' ]); }else { return $this->asJson([ 'code' => 1, 'msg' => '编辑失败' ]); } } /** * 批量修改认养 * @return \yii\web\Response */ public function actionUpdateAll() { $status = get_params('status'); $type = get_params('type'); // $updateData = [ // get_params('type') => get_params('status') // ]; $goods_id = get_params('goods_id'); if (!is_array($goods_id) || empty($goods_id)) { return $this->asJson([ 'code' => 1, 'msg' => 'goods_id为空' ]); } $count = 0; foreach ($goods_id as $id) { $goods = Goods::findOne($id); $adopt_goods = AdoptGoods::findOne([ 'goods_id' => $id, 'is_delete' => 0 ]); $goods->$type = $status; if($type == 'is_delete' && $adopt_goods){ $adopt_goods->is_delete = $status; $adopt_goods->save(); } if ($goods->save()) { $count++; } } if ($count) { return $this->asJson([ 'code' => 0, 'msg' => '共修改' . $count . '条数据' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '修改数据为0条' ]); } } /** * 土地地块 * @return \yii\web\Response */ public function actionLand() { $arr = get_params(); $query = Land::find()->alias('l') ->leftJoin(['lc' => LandCat::tableName()], 'lc.id=l.land_cat_id') ->where(['l.store_id' => get_store_id(), 'l.is_delete' => 0]); if (isset($arr['status']) && $arr['status'] > -1) { $query->andWhere([ 'g.status' => $arr['status'] ]); } if (isset($arr['land_name']) && !empty($arr['land_name'])) { $query->andWhere([ 'like', 'l.land_name', $arr['land_name'] ]); } if (!empty($arr['select'])) { $select = $arr['select']; } else { $select = ['l.id', 'l.land_name', 'l.status', 'l.land_desc', 'l.updated_at', 'l.land_pic', 'l.price', 'l.land_coordinate', 'l.sort' , 'l.land_coordinate', 'l.plant_seed', 'l.lease_cycle', 'l.lease_area', 'g.detail', 'l.monitoring_equipment_id', 'lc.name land_cat_name',]; } $query->select($select)->orderBy(['l.sort' => SORT_ASC, 'l.id' => SORT_DESC]); $pagination = pagination_make($query); $pagination['data'] = $pagination['list']; foreach($pagination['data'] as $k => $v) { $pagination['data'][$k]['plant_seed'] = Json::decode($v['plant_seed']); $pagination['data'][$k]['lease_cycle'] = Json::decode($v['lease_cycle']); $pagination['data'][$k]['lease_area'] = Json::decode($v['lease_area']); } unset($pagination['list']); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $pagination ]); } /** * 保存地块 */ public function actionAdoptSave() { $form = new AdoptGoodsForm(); $form->store_id = get_store_id(); $form->attributes = post_params(); return $this->asJson($form->saveAdopt()); } /** * 商品编辑 * @param $id * @return \yii\web\Response */ public function actionAdoptEdit() { $id = get_params('id') ?: 0; $goodsFrom = new AdoptGoodsForm(); return $this->asJson($goodsFrom->getAdoptEdit($id)); } /** * 编辑商品数据 */ public function actionUpdateAttribute() { $form = new GoodsForm(); return $this->asJson($form->updateAttribute()); } /** * 修改商品库存 * @return \yii\web\Response */ public function actionUpdateAttrNum() { $form = new GoodsForm(); return $this->asJson($form->updateAttrNum()); } public function actionDownQr() { $num = post_params('num', 0); $store_id = get_store_id(); $md_id = get_md_id(); $filename = md5($store_id . '-' . $md_id . '-' . $num); $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); if (file_exists($path)) { return $this->asJson([ 'code' => 0, 'data' => [ 'qr_url' => $pic_url, ] ]); } $id = FoodTableNumber::findOne(['num' => $num, 'md_id' => $md_id, 'is_delete' => 0])->id; $text = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/food/' . $store_id . '?md_id='. $md_id . '&food_table_num=' . $id); QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path); $goods_qrcode = new \claviska\SimpleImage($path); $bgPath = \Yii::$app->basePath . '/web/v1/statics/images/alipay-bg.png'; $bg = new \claviska\SimpleImage($bgPath); $bg->overlay($goods_qrcode, 'top left', 1, 200, 350); $bg->toFile($path, 'image/jpeg', 85); return $this->asJson([ 'code' => 0, 'data' => [ 'qr_url' => $pic_url, ] ]); } public function actionFoodQr() { $store_id = get_store_id(); $md_id = get_md_id(); $filename = md5($store_id . '-' . $md_id); $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg'; $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg'); if (file_exists($path)) { return $this->asJson([ 'code' => 0, 'data' => [ 'qr_url' => $pic_url, ] ]); } $text = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/food/' . $store_id . '?md_id='. $md_id); QrCode::image($text, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path); $goods_qrcode = new \claviska\SimpleImage($path); $bgPath = \Yii::$app->basePath . '/web/v1/statics/images/alipay-bg.png'; $bg = new \claviska\SimpleImage($bgPath); $bg->overlay($goods_qrcode, 'top left', 1, 200, 350); $bg->toFile($path, 'image/jpeg', 85); return $this->asJson([ 'code' => 0, 'data' => [ 'qr_url' => $pic_url, ] ]); } /** * 认养分类 */ public function actionAdoptCat() { $cat = AdoptCat::findAll(['store_id' => get_store_id(), 'is_delete' => 0, 'is_show' => 1]); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'list' => $cat ] ]); } public function actionAdoptCatList() { $name = get_params('name'); $query = AdoptCat::find()->where([ 'is_delete' => 0, 'store_id' => get_store_id() ]); if (!empty($name)) { $query->andWhere(['like', 'name', $name]); } $query->orderBy(['sort' => SORT_DESC]); $list = pagination_make($query); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'], ], ]); } public function actionAdoptCatStatus() { $id = post_params('id'); $cat = AdoptCat::findOne($id); $cat->is_show = $cat->is_show === 1 ? 0 : 1; if ($cat->save()) { return $this->asJson([ 'code' => 0, 'msg' => '修改成功' ]); } return $this->asJson([ 'code' => 1, 'msg' => '修改失败', ]); } public function actionAdoptCatDel() { $id = post_params('id'); $cat = AdoptCat::findOne($id); $cat->is_delete = 1; if ($cat->save()) { return $this->asJson([ 'code' => 0, 'msg' => '删除成功' ]); } return $this->asJson([ 'code' => 1, 'msg' => '删除失败', ]); } public function actionAdoptCatEdit() { $store_id = get_store_id(); $id = post_params('id', 0); $name = post_params('name'); $pic_url = post_params('pic_url', ''); $sort = post_params('sort'); $is_show = post_params('is_show', 1); if ($id > 0) { $cat = AdoptCat::findOne($id); } else { $cat = new AdoptCat(); } $cat->store_id = $store_id; $cat->name = $name; $cat->pic_url = $pic_url; $cat->sort = $sort; $cat->is_show = $is_show; if ($cat->save()) { return $this->asJson([ 'code' => 0, 'msg' => $id > 0 ? '编辑成功' : '添加成功', ]); } return $this->asJson([ 'code' => 1, 'msg' => $id > 0 ? '编辑失败' : '添加失败', ]); } public function actionGetAdoptSetting() { $store_id = get_store_id(); $adopt_setting = AdoptSetting::findOne(['store_id' => $store_id]); if (!$adopt_setting->adopt_payment) { $adopt_setting = new AdoptSetting(); $payment = [ [ 'key' => 'alipay', 'value' => 0, 'name' => '' ], [ 'key' => 'wechat', 'value' => 1, 'name' => '' ], // [ // 'key' => 'huodao', // 'value' => 0, // 'name' => '' // ], // [ // 'key' => 'friend', // 'value' => 0, // 'name' => '' // ], ]; $adopt_setting->store_id = $store_id; $adopt_setting->adopt_payment = Json::encode($payment); $adopt_setting->adopt_pay_type = 0; $adopt_setting->agreement_id = 0; $adopt_setting->created_at = time(); $adopt_setting->updated_at = time(); $adopt_setting->save(); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'adopt_payment' => Json::decode($adopt_setting->adopt_payment), 'adopt_pay_type' => $adopt_setting->adopt_pay_type, 'agreement_id' => $adopt_setting->agreement_id, 'ys_app_key' => $adopt_setting->ys_app_key, 'ys_secret' => $adopt_setting->ys_secret, 'mature_overtime' => $adopt_setting->mature_overtime, 'storage_overtime' => $adopt_setting->storage_overtime, 'free_preserve_time' => $adopt_setting->free_preserve_time, 'mature_overtime_tips' => $adopt_setting->mature_overtime_tips, 'storage_overtime_tips' => $adopt_setting->storage_overtime_tips, 'free_preserve_time_tips' => $adopt_setting->free_preserve_time_tips, ] ]); } public function actionSaveAdoptSetting() { $store_id = get_store_id(); $adopt_setting = AdoptSetting::findOne(['store_id' => $store_id]); $payment = post_params('adopt_payment'); $pay_type = post_params('adopt_pay_type', 0); $agreement_id = post_params('agreement_id', 0); $mature_overtime = post_params('mature_overtime', 0); $storage_overtime = post_params('storage_overtime', 0); $free_preserve_time = post_params('free_preserve_time', 0); $mature_overtime_tips = post_params('mature_overtime_tips', 0); $storage_overtime_tips = post_params('storage_overtime_tips', 0); $free_preserve_time_tips = post_params('free_preserve_time_tips', 0); $adopt_setting->adopt_pay_type = $pay_type; $adopt_setting->adopt_payment = $payment; $adopt_setting->agreement_id = $agreement_id; $adopt_setting->mature_overtime = $mature_overtime; $adopt_setting->mature_overtime_tips = $mature_overtime_tips; $adopt_setting->storage_overtime = $storage_overtime; $adopt_setting->storage_overtime_tips = $storage_overtime_tips; $adopt_setting->free_preserve_time = $free_preserve_time; $adopt_setting->free_preserve_time_tips = $free_preserve_time_tips; $adopt_setting->updated_at = time(); $adopt_setting->ys_app_key = post_params('ys_app_key',0); $adopt_setting->ys_secret = post_params('ys_secret',0); if (!$adopt_setting->save()) { return $this->asJson([ 'code' => 1, 'msg' => array_values($adopt_setting->errors)[0], ]); } return $this->asJson([ 'code' => 0, 'msg' => '保存成功' ]); } // 获取设备列表 public function actionDeviceList(){ return $this->asJson(DeviceForm::getList(get_params())); } // 添加设备 public function actionAddDevice(){ return $this->asJson(DeviceForm::addItem(post_params())); } // 添加设备 public function actionDelDevice(){ return $this->asJson(DeviceForm::delItem(get_params())); } // 刷新设备 public function actionRefresh(){ return $this->asJson(DeviceForm::refresh()); } // 获取设备选择列表 public function actionGetSelectList(){ return $this->asJson(DeviceForm::getSelectList()); } }