where(['is_delete' => 0, 'parent_id' => 0])->select('id, parent_id, url_path, store_id, table_num, created_at, md_id, is_disabled'); if ($this->status !== null && in_array($this->status, [0, 1])) { if (intval($this->status) === 0) { $query->andWhere(['store_id' => 0]); } else { $query->andWhere(['>', 'store_id', 0]); } } $pagination = pagination_make($query); foreach ($pagination['list'] as &$item) { $item = $this->getField($item); } // $pagination['list'] = $this->getField($pagination['list']); return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]; } public function createQrcode() { try { $num = $this->num ?: 1; $arr = range(1, $num); // $parent_id = $this->parent_id ?: 0; foreach ($arr as $item) { $max_id = MdFoodsQrcode::find()->max('id');; $max_id = $max_id + 1; $form = new MdFoodsQrcode(); $form->id = $max_id; $form->url_path = \Yii::$app->request->hostInfo . '/web/food/store/' . $max_id . '/?id='. $max_id; // $form->parent_id = $parent_id; $form->mini_path = "/alipay-order/orderMeal/orderMeal"; $form->save(); } return [ 'code' => 0, 'msg' => '生成成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } //修改子码桌号 / 门店 public function editQrcode() { try { $id = $this->id; $table_num = $this->table_num; $md_id = $this->md_id; $qrcode = MdFoodsQrcode::findOne(['id' => $id, 'is_delete' => 0]); if ($qrcode) { if ($table_num) { $query = FoodTableNumber::find()->where([ 'is_delete' => 0, 'store_id' => $qrcode->store_id, 'id' => $table_num ]); if ($qrcode->md_id) { $query->andWhere(['md_id' => $qrcode->md_id]); } else { $query->andWhere(['md_id' => [-1, 0]]); } $table_info = $query->one(); if ($table_info) { $qrcode->table_num = $table_num; } else { throw new \Exception('未找到对应的桌号信息'); } } if ($md_id) { if ($qrcode->table_num) { throw new \Exception('当前已绑定桌号,不可设置门店'); } // if ($qrcode->is_disabled) { // throw new \Exception('当前状态已到最底层,不可设置门店'); // } $md_info = Md::find()->where([ 'is_delete' => 0, 'store_id' => $qrcode->store_id, 'id' => $md_id ])->one(); if ($md_info) { $qrcode->md_id = $md_id; } else { throw new \Exception('未找到对应的门店信息'); } } $store_id = $qrcode->store_id; if ($store_id) { $store = Store::findOne($store_id); if ($store) { if (intval($store->business_model) !== 1) { //非独立运营 $str = $qrcode->url_path; $scene = substr($str, 0,(strpos($str, '?scene='))); $scene .= "?scene=store_id:" . $store_id; if ($qrcode->md_id) { $scene .= ",md_id:" . $qrcode->md_id; } if (isset($table_info)) { $scene .= ",food_table_num:" . $table_info->num . ",f_num:" . $table_info->num; } $qrcode->url_path = $scene; } } } if (!$qrcode->save()) { throw new \Exception(json_encode($qrcode->errors, JSON_UNESCAPED_UNICODE)); } return [ 'code' => 0, 'msg' => '操作成功' ]; } throw new \Exception('查找数据失败'); } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function delQrcode() { try { $id = $this->id; $qrcode = MdFoodsQrcode::findOne($id); $qrcode->is_delete = 1; if (!$qrcode->save()) { throw new \Exception(json_encode($qrcode->errors, JSON_UNESCAPED_UNICODE)); } return [ 'code' => 0, 'msg' => '操作成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } // public function getField($data){ $item = $data; $item['is_disabled'] = (int)$item['is_disabled']; $store = Store::findOne($item['store_id']); $item['store'] = [ 'name' => $store->name ?: '', 'logo' => $store->logo ?: (Option::get('logo', $item['store_id'], 'store')['value'] ?: Option::get('web_log', $item['store_id'], 'web')['value']) ]; $item['table_num_list'] = []; $item['md'] = [ 'name' => '', 'logo' => '' ]; if ($store) { $query = FoodTableNumber::find()->where([ 'is_delete' => 0, 'store_id' => $item['store_id'], ]); $qrcode_query = MdFoodsQrcode::find()->where(['is_delete' => 0, 'store_id' => $item['store_id']]); $item['table_num_text'] = FoodTableNumber::findOne($item['table_num'])->num ?: ''; $md_query = clone $qrcode_query; $filter_md_id = $md_query->select('md_id')->column(); $md_list = Md::find()->where(['store_id' => $item['store_id'], 'is_delete' => 0]) ->andWhere(['NOT IN', 'id', $filter_md_id])->select('id, name')->asArray()->all(); $item['md_list'] = $md_list; if ($item['md_id']) { $query->andWhere(['md_id' => $item['md_id']]); $qrcode_query->andWhere(['md_id' => $item['md_id']]); $md = Md::findOne($item['md_id']); $item['md'] = [ 'name' => $md->name ?: '', 'logo' => $md->cover_url ?: '' ]; } else { $query->andWhere(['md_id' => [-1, 0]]); $qrcode_query->andWhere(['md_id' => [-1, 0]]); } $filter_id = $qrcode_query->select('table_num')->column(); $query->andWhere(['NOT IN', 'id', $filter_id]); $table_num_list = $query->andWhere(['<>', 'id', $item['id']])->select('id, num, remark')->asArray()->all(); $item['table_num_list'] = $table_num_list; } $item['status'] = 0; if ($item['store_id'] > 0) { $item['status'] = 1; } $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']); // if ($item['children']) { // foreach ($item['children'] as &$i) { // $i = $this->getField($i); // } // // } return $item; } }