where('id', $params['land_id'])->value('user_id'); Db::startTrans(); try { LandPlant::create([ 'user_id' => $userId, 'land_id' => $params['land_id'], 'kind' => $params['kind'], 'breed' => $params['breed'], 'area' => $params['area'], 'user' => $params['user'], 'remark' => $params['remark'], 'status' => $params['status'], 'pic' => json_encode($params['pic']), 'qr_code' => $params['qr_code'], 'plant_date' => strtotime($params['plant_date']), ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑 * @param array $params * @return bool * @author likeadmin * @date 2023/11/23 11:32 */ public static function edit(array $params): bool { $userId = Db::name('land')->where('id', $params['land_id'])->value('user_id'); Db::startTrans(); try { LandPlant::where('id', $params['id'])->update([ 'user_id' => $userId, 'land_id' => $params['land_id'], 'kind' => $params['kind'], 'breed' => $params['breed'], 'area' => $params['area'], 'user' => $params['user'], 'remark' => $params['remark'], 'status' => $params['status'], 'pic' => json_encode($params['pic']), 'qr_code' => $params['qr_code'], 'plant_date' => strtotime($params['plant_date']), ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除 * @param array $params * @return bool * @author likeadmin * @date 2023/11/23 11:32 */ public static function delete(array $params): bool { Db::name('land_plant_action')->where('plant_id', $params['id'])->delete(); return LandPlant::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2023/11/23 11:32 */ public static function detail($params): array { return LandPlant::findOrEmpty($params['id'])->toArray(); } }