request->get(); if (!empty($get['start_time']) && !empty($get['end_time'])) { $start_time = strtotime($get['start_time'] . ' ' . '00:00:00'); $end_time = strtotime($get['end_time'] . ' ' . '23:59:59'); } $query = Drug::find()->with(['supplier'])->alias('d')->orderBy(['id' => SORT_DESC]); $user = \Yii::$app->user->identity; if ($user->role == UserRoleEnum::STORE_ADMIN) { //门店 $query->joinWith(['drugStoreRelationes' => function ($drug) use ($user) { $drug->alias('ds'); $drug->andWhere(['ds.store_id' => $user->store_id,'ds.is_forbid'=>0,'ds.status'=>2]); }]); } $query->andWhere(['d.type' => 5]); if (!empty($get['name'])) { $query->andWhere([ 'or', ['like', 'drug_name', $get['name']], ['like', 'drug_number', $get['name']], ['like', 'bar_code', $get['name']], ['like', 'source', $get['name'] ], ['like', 'pinyin_simple', $get['name'] ], ['like', 'drug_alias', $get['name'] ], ]); } if (!empty($start_time) && !empty($end_time)) { if ($start_time==$end_time){//筛选当天 $time=FuncHelper::getDayBE($get['start_time']); $end_time=$time; } $query->andWhere(['between', 'd.created_at', $start_time,$end_time]); } if (!empty($get['type'])) { $query->andWhere(['type' => $get['type']]); } $this->field = [ Drug::class => [ 'id', 'pinyin_simple', 'drug_name', 'source', 'type', 'is_otc', 'category_first', 'category_second', 'small_info', 'info', 'content', 'usage', 'image', 'status', 'drug_number', 'drug_alias', 'bar_code', 'guozi_no', 'place', 'function', 'instruction', 'decotion_id' => 'decotion', 'decotion' => 'drugUseWay.name', 'unit' => 'unit.name', 'store' => 'drugStoreRelationes.store_id', 'price' => 'drugStoreRelationes.price', 'buy_price' => 'drugStoreRelationes.buy_price', 'stock' => 'drugStoreRelationes.drugStoreDrug.stock', 'is_shalving' => 'drugStoreRelationes.status', 'type_id', 'frequency_id', 'unit_id', 'time_id', 'use_frequency' => 'drugUseFrequency.name', 'use_type' => 'drugUseType.name', 'use_time' => 'drugUseTime.name', 'is_forbid'=>'drugStoreRelationes.is_forbid', 'supplier', 'source_name' => 'supplier.name', 'specification', 'platform_ledger', 'store_ledger', 'supplier_ledger', ], ]; return $this->create($query, $get); } /** * @doc-name 新增产品服务包库 * @doc-param string drug_name 药名 * @doc-param string pinyin_simple 拼音首拼 * @doc-param string drug_number 编号 * @doc-param string drug_alias 别名 * @doc-param int unit_id 单位 * @doc-param int status 状态1草稿2下架3上架 * @doc-param string place 产地 / optional * @doc-param string instruction 说明书图片 / optional * @doc-param json drugstore[{"drugstore_id":1,"price":100,"type":1,"stock":100},{"drugstore_id":2,"price":100,"type":1,"stock":200}] 仓库 */ public function actionSave() { $post=\Yii::$app->request->post(); $post['type']=5; $GranularForm=new ServerForm(); $GranularForm->attributes=$post; return $GranularForm->save(); } /** * 获取服务商的下拉框 * @return array|\yii\db\ActiveRecord[] */ public function actionSupplierOption() { return SupplierModel::find()->select(['id', 'name'])->all(); } /** * @doc-name 删除产品服务包库 * @doc-param int id 药品ID */ public function actionDelete() { $post=\Yii::$app->request->post(); $this->requestValidate($post,[ ['id','required'] ]); $GranularForm = new ServerForm(); $GranularForm->attributes=$post; return $GranularForm->del(); } /** * @doc-name 修改产品服务包库 * @doc-param int id 药品ID * @doc-param string drug_name 药名 * @doc-param string pinyin_simple 拼音首拼 * @doc-param string drug_number 编号 * @doc-param string drug_alias 别名 * @doc-param int unit_id 单位 * @doc-param string place 产地 / optional * @doc-param string instruction 说明书图片 / optional */ public function actionUpdate() { $post=\Yii::$app->request->post(); $this->requestValidate($post,[ ['id','required'] ]); $GranularForm = new ServerForm(); $GranularForm->attributes=$post; return $GranularForm->update(); } /** * @doc-name 查看产品服务包库 * @doc-param int id 药品ID */ public function actionInfo() { $drug= Drug::find()->with(['supplier'])->where([ 'id'=>\Yii::$app->request->get('id'), 'type'=>5, ])->asArray()->one(); if (!$drug) throw new Exception('该药品不存在'); $drug['source_name']=$drug['supplier']['name']; return $drug; } # 后面可能回做一个结算重试 public function actionServiceLedger() { // $leaderNoMoney = Ledger::find()->where(['status' => 0])->sum('money'); $ledgerForm = new LedgerForm(); $ledgerForm->order_id = 272; $ledgerForm->status = 0; // 已结算 $ledgerForm->create(); } }